namespace MonoTests.System
{
-
-
//Auxiliary Things
enum enua {hola,adios,mas,menos};
class BClass : AClass
{
- }
+ }
class CClass : AClass
- {
- }
+ {
+ }
struct AStruct
{
public string s;
public string a;
}
+
+ class DataEqual
+ {
+ public override bool Equals (object obj)
+ {
+ return true;
+ }
+ }
+
//End Auxiliary Things
[TestFixture]
{
char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
- Assert("#B05",
- Array.BinarySearch(arr, 'c') >= 3);
- Assert("#B06",
- Array.BinarySearch(arr, 'c') < 6);
+ Assert("#B05", Array.BinarySearch(arr, 'c') >= 3);
+ Assert("#B06", Array.BinarySearch(arr, 'c') < 6);
}
{
char[] arr = {'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};
- AssertEquals("#B07",
- -4, Array.BinarySearch(arr, 'c'));
+ AssertEquals("#B07", -4, Array.BinarySearch(arr, 'c'));
}
{
char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
- AssertEquals("#B08",
- -9, Array.BinarySearch(arr, 'e'));
+ AssertEquals("#B08", -9, Array.BinarySearch(arr, 'e'));
}
}
{
char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
- Assert("#B26",
- Array.BinarySearch(arr, 2, 8, 'c') >= 5);
- Assert("#B27",
- Array.BinarySearch(arr, 2, 8, 'c') < 8);
+ Assert("#B26", Array.BinarySearch(arr, 2, 8, 'c') >= 5);
+ Assert("#B27", Array.BinarySearch(arr, 2, 8, 'c') < 8);
}
{
char[] arr = {'z', 'z', 'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};
- AssertEquals("#B28",
- -6, Array.BinarySearch(arr, 2, 8, 'c'));
+ AssertEquals("#B28", -6, Array.BinarySearch(arr, 2, 8, 'c'));
}
{
char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
- AssertEquals("#B29",
- -11, Array.BinarySearch(arr, 2, 8, 'e'));
+ AssertEquals("#B29", -11, Array.BinarySearch(arr, 2, 8, 'e'));
}
}
char[] copy = new Char[4];
Array.Copy(orig, copy, 4);
for (int i = 0; i < orig.Length; i++) {
- AssertEquals("#E09(" + i + ")",
- orig[i], copy[i]);
+ AssertEquals("#E09(" + i + ")", orig[i], copy[i]);
}
Array.Clear(copy, 0, copy.Length);
for (int i = 0; i < orig.Length; i++) {
- AssertEquals("#E10(" + i + ")",
- (char)0, copy[i]);
+ AssertEquals("#E10(" + i + ")", (char)0, copy[i]);
}
Array.Copy(orig, copy, 2);
AssertEquals("#E11", orig[0], copy[0]);
Array.Copy(orig, 1, copy, 1, 3);
Assert("#E33", copy[0] != orig[0]);
for (int i = 1; i < orig.Length; i++) {
- AssertEquals("#E34(" + i + ")",
- orig[i], copy[i]);
+ AssertEquals("#E34(" + i + ")", orig[i], copy[i]);
}
Array.Clear(copy, 0, copy.Length);
Array.Copy(orig, 1, copy, 0, 2);
Assert("#E38", copy[3] != orig[3]);
}
+ [Test]
+ [ExpectedException (typeof (InvalidCastException))]
+ public void Copy_InvalidCast () {
+ object[] arr1 = new object [10];
+ Type[] arr2 = new Type [10];
+
+ arr1 [0] = new object ();
+
+ Array.Copy (arr1, 0, arr2, 0, 10);
+ }
+
[Test]
public void TestCopyTo() {
{
} catch (ArgumentException) {
errorThrown = true;
}
+#if TARGET_JVM // This is really implementation dependent behaviour.
+ catch (RankException) {
+ errorThrown = true;
+ }
+#endif // TARGET_JVM
Assert("#E62", errorThrown);
}
{
Assert("#F03b", errorThrown);
}
#endif
+#if !TARGET_JVM // Arrays lower bounds are not supported for TARGET_JVM
{
bool errorThrown = false;
try {
}
Assert("#F04", errorThrown);
}
+#endif // TARGET_JVM
{
bool errorThrown = false;
try {
}
Assert("#F05", errorThrown);
}
+#if !TARGET_JVM // CreateInstance with lower bounds not supported for TARGET_JVM
{
bool errorThrown = false;
try {
Type szarrayType = new int [10].GetType ();
Assert (szarrayType == (Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0})).GetType ());
Assert (szarrayType != (Array.CreateInstance (typeof (int), new int[] {1}, new int[] {1})).GetType ());
+#endif // TARGET_JVM
}
[Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void TestCreateInstance2 ()
- {
- Array a = Array.CreateInstance (typeof (Int32), (int[])null);
- }
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void TestCreateInstance2 ()
+ {
+ Array.CreateInstance (typeof (Int32), (int[])null);
+ }
[Test]
#if NET_2_0
#else
[ExpectedException (typeof (NullReferenceException))]
#endif
- public void TestCreateInstance2b ()
- {
- Array a = Array.CreateInstance (typeof (Int32), (long[])null);
- }
+ public void TestCreateInstance2b ()
+ {
+ Array.CreateInstance (typeof (Int32), (long[])null);
+ }
[Test]
public void TestGetEnumerator() {
}
[Test]
+ [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
public void TestGetEnumeratorNonZeroLowerBounds() {
int[] myLengthsArray = new int[2] { 3, 5 };
int[] myBoundsArray = new int[2] { 2, 3 };
}
[Test]
+ [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
public void TestIList_Add () {
int[] myLengthsArray = new int[2] { 3, 5 };
int[] myBoundsArray = new int[2] { 2, 3 };
Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
try {
((IList)myArray).Add ("can not");
- Fail ("IList.Add should throw");
+ Fail ("IList.Add should throw");
}
catch (NotSupportedException) {
return;
}
catch (Exception) {
- Fail ("IList.Add threw wrong exception type");
+ Fail ("IList.Add threw wrong exception type");
}
Fail("IList.Add shouldn't get this far");
}
[Test]
+ [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
public void TestIList_Insert () {
int[] myLengthsArray = new int[2] { 3, 5 };
int[] myBoundsArray = new int[2] { 2, 3 };
Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
try {
((IList)myArray).Insert (0, "can not");
- Fail ("IList.Insert should throw");
+ Fail ("IList.Insert should throw");
}
catch (NotSupportedException) {
return;
}
catch (Exception) {
- Fail ("IList.Insert threw wrong exception type");
+ Fail ("IList.Insert threw wrong exception type");
}
Fail("IList.Insert shouldn't get this far");
}
[Test]
+ [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
public void TestIList_Remove () {
int[] myLengthsArray = new int[2] { 3, 5 };
int[] myBoundsArray = new int[2] { 2, 3 };
Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
try {
((IList)myArray).Remove ("can not");
- Fail ("IList.Remove should throw");
+ Fail ("IList.Remove should throw");
}
catch (NotSupportedException) {
return;
}
catch (Exception) {
- Fail ("IList.Remove threw wrong exception type");
+ Fail ("IList.Remove threw wrong exception type");
}
Fail("IList.Remove shouldn't get this far");
}
[Test]
+ [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
public void TestIList_RemoveAt () {
int[] myLengthsArray = new int[2] { 3, 5 };
int[] myBoundsArray = new int[2] { 2, 3 };
Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
try {
((IList)myArray).RemoveAt (0);
- Fail ("IList.RemoveAt should throw");
+ Fail ("IList.RemoveAt should throw");
}
catch (NotSupportedException) {
return;
}
catch (Exception) {
- Fail ("IList.RemoveAt threw wrong exception type");
+ Fail ("IList.RemoveAt threw wrong exception type");
}
Fail("IList.RemoveAt shouldn't get this far");
}
[Test]
+ [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
public void TestIList_Contains () {
int[] myLengthsArray = new int[2] { 3, 5 };
int[] myBoundsArray = new int[2] { 2, 3 };
}
[Test]
+ [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
public void TestIList_IndexOf () {
int[] myLengthsArray = new int[2] { 3, 5 };
int[] myBoundsArray = new int[2] { 2, 3 };
}
char[] c2 = new Char[5];
- AssertEquals("#H03",
- 5, c2.GetLength(0));
+ AssertEquals("#H03", 5, c2.GetLength(0));
char[,] c3 = new Char[6,7];
- AssertEquals("#H04",
- 6, c3.GetLength(0));
- AssertEquals("#H05",
- 7, c3.GetLength(1));
+ AssertEquals("#H04", 6, c3.GetLength(0));
+ AssertEquals("#H05", 7, c3.GetLength(1));
}
[Test]
}
char[] c1 = new Char[5];
- AssertEquals("#H33",
- 0, c1.GetLowerBound(0));
+ AssertEquals("#H33", 0, c1.GetLowerBound(0));
char[,] c2 = new Char[4,4];
- AssertEquals("#H34",
- 0, c2.GetLowerBound(0));
- AssertEquals("#H35",
- 0, c2.GetLowerBound(1));
+ AssertEquals("#H34", 0, c2.GetLowerBound(0));
+ AssertEquals("#H35", 0, c2.GetLowerBound(1));
}
[Test]
}
char[] c1 = new Char[5];
- AssertEquals("#H63",
- 4, c1.GetUpperBound(0));
+ AssertEquals("#H63", 4, c1.GetUpperBound(0));
char[,] c2 = new Char[4,6];
- AssertEquals("#H64",
- 3, c2.GetUpperBound(0));
- AssertEquals("#H65",
- 5, c2.GetUpperBound(1));
+ AssertEquals("#H64", 3, c2.GetUpperBound(0));
+ AssertEquals("#H65", 5, c2.GetUpperBound(1));
}
[Test]
for (int i = 0; i < c1.GetLength(0); i++) {
for (int j = 0; j < c1.GetLength(1); j++) {
AssertEquals("#I24(" + i + "," + j + ")",
- c1[i,j], c1.GetValue(i, j));
+ c1[i,j], c1.GetValue(i, j));
}
}
}
for (int j = 0; j < c1.GetLength(1); j++) {
for (int k = 0; k < c1.GetLength(2); k++) {
AssertEquals("#I44(" + i + "," + j + ")",
- c1[i,j,k], c1.GetValue(i,j,k));
+ c1[i,j,k], c1.GetValue(i,j,k));
}
}
}
for (int j = 0; j < c1.GetLength(1); j++) {
int[] coords = {i, j};
AssertEquals("#I65(" + i + "," + j + ")",
- c1[i,j], c1.GetValue(coords));
+ c1[i,j], c1.GetValue(coords));
}
}
}
AssertEquals("#J50", 3, Array.IndexOf(s1, "a", 1, 3));
}
+ [Test]
+ public void TestIndexOf_CustomEqual ()
+ {
+ DataEqual[] test = new DataEqual [] { new DataEqual () };
+ AssertEquals (0, Array.IndexOf (test, "asdfas", 0));
+
+ IList array = (IList)test;
+ AssertEquals (0, array.IndexOf ("asdfas"));
+ }
+
[Test]
public void TestLastIndexOf1() {
{
AssertEquals("#K05", 0, Array.LastIndexOf(s1, "this"));
AssertEquals("#K06", 4, Array.LastIndexOf(s1, "test"));
AssertEquals("#K07", 3, Array.LastIndexOf(s1, "a"));
+
+ AssertEquals (-1, Array.LastIndexOf (new String [0], "foo"));
}
[Test]
}
String[] s1 = {"this", "is", "really", "a", "test"};
- AssertEquals("#K45",
- -1, Array.LastIndexOf(s1, null, 3, 3));
- AssertEquals("#K46",
- -1, Array.LastIndexOf(s1, "nothing", 3, 3));
- AssertEquals("#K47",
- -1, Array.LastIndexOf(s1, "this", 3, 3));
- AssertEquals("#K48",
- 1, Array.LastIndexOf(s1, "is", 3, 3));
- AssertEquals("#K49",
- -1, Array.LastIndexOf(s1, "test", 3, 3));
- AssertEquals("#K50",
- 3, Array.LastIndexOf(s1, "a", 3, 3));
- }
-
- [Test]
- [ExpectedException (typeof (ArgumentOutOfRangeException))]
- public void TestLastIndexOf4 ()
- {
- short [] a = new short [] { 19, 238, 317, 6, 565, 0, -52, 60, -563, 753, 238, 238};
- Array.LastIndexOf (a, 16, -1);
- }
-
- [Test]
- public void TestLastIndexOf5 ()
- {
- char [] a = new char [] {'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a', 'j', 'i', 'h'};
- string s;
- int retval;
- bool error = false;
-
- for (int i = a.Length - 1; i >= 0 ; i--) {
- s = i.ToString ();
- retval = Array.LastIndexOf(a, a [i], i, i + 1);
- if (retval != i)
- error = true;
- }
- Assert (!error);
- }
+ AssertEquals("#K45", -1, Array.LastIndexOf(s1, null, 3, 3));
+ AssertEquals("#K46", -1, Array.LastIndexOf(s1, "nothing", 3, 3));
+ AssertEquals("#K47", -1, Array.LastIndexOf(s1, "this", 3, 3));
+ AssertEquals("#K48", 1, Array.LastIndexOf(s1, "is", 3, 3));
+ AssertEquals("#K49", -1, Array.LastIndexOf(s1, "test", 3, 3));
+ AssertEquals("#K50", 3, Array.LastIndexOf(s1, "a", 3, 3));
+ }
+
+ [Test]
+ public void TestLastIndexOf4 ()
+ {
+ short [] a = new short [] { 19, 238, 317, 6, 565, 0, -52, 60, -563, 753, 238, 238};
+ try {
+ Array.LastIndexOf (a, (object)16, -1);
+ NUnit.Framework.Assert.Fail ("#1");
+ } catch (ArgumentOutOfRangeException) { }
+
+#if NET_2_0
+ try {
+ Array.LastIndexOf<short> (a, 16, -1);
+ NUnit.Framework.Assert.Fail ("#2");
+ } catch (ArgumentOutOfRangeException) { }
+#endif
+ }
+
+ [Test]
+ public void TestLastIndexOf5 ()
+ {
+ char [] a = new char [] {'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a', 'j', 'i', 'h'};
+ string s;
+ int retval;
+ bool error = false;
+
+ for (int i = a.Length - 1; i >= 0 ; i--) {
+ s = i.ToString ();
+ retval = Array.LastIndexOf(a, a [i], i, i + 1);
+ if (retval != i)
+ error = true;
+ }
+ Assert (!error);
+ }
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
for (int i = 0; i < c1.GetLength(0); i++) {
for (int j = 0; j < c1.GetLength(1); j++) {
AssertEquals("#M24(" + i + "," + j + ")",
- c1[i,j], c2[i, j]);
+ c1[i,j], c2[i, j]);
}
}
}
for (int j = 0; j < c1.GetLength(1); j++) {
for (int k = 0; k < c1.GetLength(2); k++) {
AssertEquals("#M44(" + i + "," + j + " )",
- c1[i,j,k], c2[i,j,k]);
+ c1[i,j,k], c2[i,j,k]);
}
}
}
for (int i = 0; i < c1.GetLength(0); i++) {
for (int j = 0; j < c1.GetLength(1); j++) {
AssertEquals("#M65(" + i + "," + j + ")",
- c1[i,j], c2[i,j]);
+ c1[i,j], c2[i,j]);
}
}
}
int ex_index = (i * types.Length) + j;
AssertEquals ("#M90(" + types [i] + "," + types [j] + ")",
- errorThrown, arg_ex [ex_index] == 1);
+ errorThrown, arg_ex [ex_index] == 1);
}
}
int ex_index = (i * types.Length) + j;
AssertEquals ("#M94(" + types [i] + "," + types [j] + ")",
- errorThrown, arg_ex [ex_index] == 1);
+ errorThrown, arg_ex [ex_index] == 1);
}
}
Array.Sort (arrsort, null, 0, arrsort.Length, null);
}
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void MoreSort10 ()
- {
- object [] array = {true, 'k', SByte.MinValue, Byte.MinValue, (short) 2, 634, (long) 436, (float) 1.1, 1.23, "Hello World"};
- Array.Sort (array, (IComparer) null);
- }
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void MoreSort10 ()
+ {
+ object [] array = {true, 'k', SByte.MinValue, Byte.MinValue, (short) 2, 634, (long) 436, (float) 1.1, 1.23, "Hello World"};
+ Array.Sort (array, (IComparer) null);
+ }
+
+ [Test] // bug #81941
+ public void Sort ()
+ {
+ double [] a = new double [2] { 0.9, 0.3 };
+ uint [] b = new uint [2] { 4, 7 };
+ Array.Sort (a, b);
+ AssertEquals ("#1", 0.3, a [0]);
+ AssertEquals ("#2", 0.9, a [1]);
+ AssertEquals ("#3", 7, b [0]);
+ AssertEquals ("#4", 4, b [1]);
+ }
[Test]
public void ClearJaggedArray ()
AssertEquals (45, sum);
}
+ [Test]
+ public void Resize ()
+ {
+ int [] arr = new int [] { 1, 3, 5 };
+ Array.Resize <int> (ref arr, 3);
+ AssertEquals ("#A1", 3, arr.Length);
+ AssertEquals ("#A2", 1, arr [0]);
+ AssertEquals ("#A3", 3, arr [1]);
+ AssertEquals ("#A4", 5, arr [2]);
+
+ Array.Resize <int> (ref arr, 2);
+ AssertEquals ("#B1", 2, arr.Length);
+ AssertEquals ("#B2", 1, arr [0]);
+ AssertEquals ("#B3", 3, arr [1]);
+
+ Array.Resize <int> (ref arr, 4);
+ AssertEquals ("#C1", 4, arr.Length);
+ AssertEquals ("#C2", 1, arr [0]);
+ AssertEquals ("#C3", 3, arr [1]);
+ AssertEquals ("#C4", 0, arr [2]);
+ AssertEquals ("#C5", 0, arr [3]);
+ }
+
[Test]
public void Resize_null ()
{
Array.Resize (ref arr, 10);
AssertEquals (arr.Length, 10);
}
+
+ [Test]
+ public void Test_ContainsAndIndexOf_EquatableItem ()
+ {
+ EquatableClass[] list = new EquatableClass[] {new EquatableClass (0), new EquatableClass (1), new EquatableClass (0)};
+
+ AssertEquals ("#0", 0, Array.IndexOf<EquatableClass> (list, list[0]));
+ AssertEquals ("#1", 0, Array.IndexOf<EquatableClass> (list, new EquatableClass (0)));
+ AssertEquals ("#2", 2, Array.LastIndexOf<EquatableClass> (list, list[0]));
+ AssertEquals ("#3", 2, Array.LastIndexOf<EquatableClass> (list, new EquatableClass (0)));
+ }
+
+ public class EquatableClass : IEquatable<EquatableClass>
+ {
+ int _x;
+ public EquatableClass (int x)
+ {
+ _x = x;
+ }
+
+ public bool Equals (EquatableClass other)
+ {
+ return this._x == other._x;
+ }
+ }
+
+ [Test]
+ public void AsIList ()
+ {
+ IList<int> arr = new int [10];
+ arr [0] = 5;
+ AssertEquals (5, arr [0]);
+
+ IList<FooStruct> arr2 = new FooStruct [10];
+ FooStruct s = new FooStruct ();
+ s.i = 11;
+ s.j = 22;
+ arr2 [5] = s;
+ s = arr2 [5];
+ AssertEquals (11, s.i);
+ AssertEquals (22, s.j);
+
+ IList<string> arr3 = new string [10];
+ arr3 [5] = "ABC";
+ AssertEquals ("ABC", arr3 [5]);
+ }
+
+ struct FooStruct {
+ public int i, j;
+ }
+
+#if !TARGET_JVM // BugBUG: T[] is not yet ICollection<T> under TARGET_JVM
+ [Test]
+ // From bug #80563
+ public void ICollectionNull ()
+ {
+ ICollection<object> test;
+
+ test = new List<object>();
+ AssertEquals ("list<o>", test.Contains (null), false);
+
+ test = new object[] {};
+ AssertEquals ("empty array", test.Contains (null), false);
+
+ test = new object[] {null};
+ AssertEquals ("array with null", test.Contains (null), true);
+
+ test = new List<object>(test);
+ AssertEquals ("List<object> with test", test.Contains (null), true);
+
+ test = new object[] {new object()};
+ AssertEquals ("array with object", test.Contains (null), false);
+
+ test = new List<object>(test);
+ AssertEquals ("array with test", test.Contains (null), false);
+ }
+#endif // TARGET_JVM
#endif
-}
+ #region Bug 80299
+
+ enum ByteEnum : byte {}
+ enum IntEnum : int {}
+
+ [Test]
+ public void TestByteEnumArrayToByteArray ()
+ {
+ ByteEnum[] a = new ByteEnum[] {(ByteEnum) 1, (ByteEnum) 2};
+ byte[] b = new byte[a.Length];
+ a.CopyTo (b, 0);
+ }
+
+ [Test]
+ public void TestByteEnumArrayToIntArray ()
+ {
+ ByteEnum[] a = new ByteEnum[] {(ByteEnum) 1, (ByteEnum) 2};
+ int[] b = new int[a.Length];
+ a.CopyTo (b, 0);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArrayTypeMismatchException))]
+ public void TestIntEnumArrayToByteArray ()
+ {
+ IntEnum[] a = new IntEnum[] {(IntEnum) 1, (IntEnum) 2};
+ byte[] b = new byte[a.Length];
+ a.CopyTo (b, 0);
+ }
+
+ [Test]
+ public void TestIntEnumArrayToIntArray ()
+ {
+ IntEnum[] a = new IntEnum[] {(IntEnum) 1, (IntEnum) 2};
+ int[] b = new int[a.Length];
+ a.CopyTo (b, 0);
+ }
+
+ #endregion
+
+#if NET_2_0
+ [Test] // bug #322248
+ public void IEnumerator_Reset ()
+ {
+ int[] array = new int[] { 1, 2, 3};
+ IEnumerator<int> e = ((IEnumerable<int>)array).GetEnumerator ();
+ Assert ("#A1", e.MoveNext ());
+ AssertEquals ("#A2", 1, e.Current);
+ Assert ("#A3", e.MoveNext ());
+ AssertEquals ("#A4", 2, e.Current);
+
+ e.Reset ();
+
+ Assert ("#C1", e.MoveNext ());
+ AssertEquals ("#C2", 1, e.Current);
+ }
+
+ [Test]
+ public void IEnumerator_Current_Finished ()
+ {
+ int[] array = new int[] { 1, 2, 3 };
+ IEnumerator<int> e = ((IEnumerable<int>)array).GetEnumerator ();
+ Assert ("#A1", e.MoveNext ());
+ AssertEquals ("#A2", 1, e.Current);
+ Assert ("#A3", e.MoveNext ());
+ AssertEquals ("#A4", 2, e.Current);
+ Assert ("#A5", e.MoveNext ());
+ AssertEquals ("#A6", 3, e.Current);
+ Assert ("#A6", !e.MoveNext ());
+
+ try {
+ Fail ("#B1:" + e.Current);
+ } catch (InvalidOperationException ex) {
+ // Enumeration already finished
+ AssertEquals ("#B2", typeof (InvalidOperationException), ex.GetType ());
+ AssertNull ("#B3", ex.InnerException);
+ AssertNotNull ("#B4", ex.Message);
+ }
+ }
+
+ [Test]
+ public void IEnumerator_Current_NotStarted ()
+ {
+ int[] array = new int[] { 1, 2, 3 };
+ IEnumerator<int> e = ((IEnumerable<int>)array).GetEnumerator ();
+
+ try {
+ Fail ("#A1:" + e.Current);
+ } catch (InvalidOperationException ex) {
+ // Enumeration has not started. Call MoveNext
+ AssertEquals ("#A2", typeof (InvalidOperationException), ex.GetType ());
+ AssertNull ("#A3", ex.InnerException);
+ AssertNotNull ("#A4", ex.Message);
+ }
+ }
+
+ [Test]
+ public void IEnumerator_Current_Reset ()
+ {
+ int[] array = new int[] { 1, 2, 3 };
+ IEnumerator<int> e = ((IEnumerable<int>)array).GetEnumerator ();
+ e.MoveNext ();
+ e.Reset ();
+
+ try {
+ Fail ("#B1:" + e.Current);
+ } catch (InvalidOperationException ex) {
+ // Enumeration has not started. Call MoveNext
+ AssertEquals ("#B2", typeof (InvalidOperationException), ex.GetType ());
+ AssertNull ("#B3", ex.InnerException);
+ AssertNotNull ("#B4", ex.Message);
+ }
+ }
+#endif
+}
}