Merge pull request #901 from Blewzman/FixAggregateExceptionGetBaseException
[mono.git] / mcs / class / corlib / Test / System.Collections.Concurrent / ConcurrentStackTests.cs
index f4808192d03cfbf59d0f35e9fb87b55e3447701f..5f5e3b22bb71faad8e5e5e39686ac521c7187cc7 100644 (file)
@@ -28,6 +28,7 @@ using System.Threading;
 using System.Linq;
 using System.Collections.Concurrent;
 using NUnit.Framework;
+using NUnit.Framework.Constraints;
 
 namespace MonoTests.System.Collections.Concurrent
 {
@@ -124,7 +125,6 @@ namespace MonoTests.System.Collections.Concurrent
                        Assert.IsTrue(stack.IsEmpty, "#4");
                }
                
-               //[Ignore]
                [Test()]
                public void EnumerateTestCase()
                {
@@ -190,12 +190,36 @@ namespace MonoTests.System.Collections.Concurrent
                        Assert.IsTrue(s == "9876543210", "#1 : " + s);
                }
 
+               [Test, ExpectedException (typeof (ArgumentNullException))]
+               public void ToExistingArray_Null ()
+               {
+                       stack.CopyTo (null, 0);
+               }
+
+               [Test, ExpectedException (typeof (ArgumentOutOfRangeException))]
+               public void ToExistingArray_OutOfRange ()
+               {
+                       stack.CopyTo (new int[3], -1);
+               }
+
+               [Test, ExpectedException (typeof (ArgumentException))]
+               public void ToExistingArray_IndexOverflow ()
+               {
+                       stack.CopyTo (new int[3], 4);
+               }
+
+               [Test, ExpectedException (typeof (ArgumentException))]
+               public void ToExistingArray_Overflow ()
+               {
+                       stack.CopyTo (new int[3], 0);
+               }
+
                [Test]
                public void TryPopRangeTest ()
                {
                        int[] values = new int[3];
                        Assert.AreEqual (3, stack.TryPopRange (values));
-                       CollectionAssert.AreEquivalent (new int[] { 9, 8, 7 }, values);
+                       Assert.That (values, new CollectionEquivalentConstraint (new int[] { 9, 8, 7 }));
                        Assert.AreEqual (10 - values.Length, stack.Count);
                        for (int i = 9 - values.Length; i >= 0; i--) {
                                int outValue;
@@ -204,12 +228,19 @@ namespace MonoTests.System.Collections.Concurrent
                        }
                }
 
+               [Test]
+               public void TryPopRangeEmpty ()
+               {
+                       stack = new ConcurrentStack<int>();
+                       Assert.AreEqual (0, stack.TryPopRange (new int [1]));
+               }
+
                [Test]
                public void TryPopRangeTestWithOneElement ()
                {
                        int[] values = new int[1];
                        Assert.AreEqual (1, stack.TryPopRange (values));
-                       CollectionAssert.AreEquivalent (new int[] { 9 }, values);
+                       Assert.That (values, new CollectionEquivalentConstraint (new int[] { 9 }));
                        Assert.AreEqual (10 - values.Length, stack.Count);
                        for (int i = 9 - values.Length; i >= 0; i--) {
                                int outValue;
@@ -223,7 +254,7 @@ namespace MonoTests.System.Collections.Concurrent
                {
                        int[] values = new int[10];
                        Assert.AreEqual (10, stack.TryPopRange (values));
-                       CollectionAssert.AreEquivalent (Enumerable.Range (0, 10).Reverse ().ToArray (), values);
+                       Assert.That (values, new CollectionEquivalentConstraint (Enumerable.Range (0, 10).Reverse ()));
                        Assert.AreEqual (0, stack.Count);
                }
 
@@ -232,7 +263,7 @@ namespace MonoTests.System.Collections.Concurrent
                {
                        int[] values = new int[5];
                        Assert.AreEqual (2, stack.TryPopRange (values, 3, 2));
-                       CollectionAssert.AreEquivalent (new int[] { 0, 0, 0, 9, 8 }, values);
+                       Assert.That (values, new CollectionEquivalentConstraint (new int[] { 0, 0, 0, 9, 8 }));
                        Assert.AreEqual (8, stack.Count);
                }