+ col.CopyTo ((Array) null, 1);
+ col.Add (3);
+
+ try {
+ col.CopyTo ((Array) null, 1);
+ Assert.Fail ("#1");
+ } catch (NullReferenceException) {
+ }
+ }
+
+ [Test]
+ public void CopyTo_Index_Negative ()
+ {
+ int [] copy = new int [5] { 9, 4, 6, 2, 8 };
+
+ col.CopyTo (copy, -5);
+ col.Add (3);
+
+ try {
+ col.CopyTo (copy, -5);
+ Assert.Fail ("#1");
+ } catch (IndexOutOfRangeException ex) {
+ // Index was outside the bounds of the array
+ Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ }
+ }
+
+ [Test]
+ public void Count ()
+ {
+ Assert.AreEqual (0, col.Count, "#1");
+ col.Add (5);
+ Assert.AreEqual (1, col.Count, "#2");
+ col.Add (7);
+ Assert.AreEqual (2, col.Count, "#3");
+ col.Remove (7);
+ Assert.AreEqual (1, col.Count, "#4");
+ }
+
+ [Test]
+ public void Indexer ()
+ {
+ col.Add (5);
+ col.Add (7);
+ Assert.AreEqual (7, col [1], "#1");
+ Assert.AreEqual (5, col [0], "#2");
+ col [0] = 3;
+ Assert.AreEqual (7, col [1], "#3");
+ Assert.AreEqual (3, col [0], "#4");
+ }
+
+ [Test]
+ public void IndexOf ()
+ {
+ col.Add (5);
+ col.Add (7);
+ Assert.AreEqual (0, col.IndexOf (5), "#1");
+ Assert.AreEqual (-1, col.IndexOf (3), "#2");
+ Assert.AreEqual (1, col.IndexOf (7), "#3");
+ Assert.AreEqual (-1, col.IndexOf (-5), "#4");
+ }
+
+ [Test]
+ public void Remove ()
+ {
+ col.Add (5);
+ col.Add (3);
+ col.Remove (5);
+ col.Remove (7);
+
+ Assert.AreEqual (1, col.Count, "#1");
+ Assert.AreEqual (3, col [0], "#2");
+ col.Remove (3);
+ Assert.AreEqual (0, col.Count, "#3");
+ col.Remove (3);
+ // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=363280
+ //Assert.AreEqual (0, col.Count, "#4");
+ }
+
+ [Test]
+ public void RemoveAt ()
+ {
+ col.Add (5);
+ col.Add (3);
+ col.Add (7);
+ col.RemoveAt (1);
+ Assert.AreEqual (2, col.Count, "#A1");
+ Assert.AreEqual (3, col [0], "#A2");
+ Assert.AreEqual (7, col [1], "#A3");
+ col.RemoveAt (0);
+ Assert.AreEqual (1, col.Count, "#B1");
+ Assert.AreEqual (7, col [0], "#B2");
+ col.RemoveAt (0);
+ Assert.AreEqual (0, col.Count, "#C1");
+ Assert.AreEqual (-1, col.IndexOf (5), "#C2");
+ Assert.AreEqual (-1, col.IndexOf (3), "#C3");
+ // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=363280
+ //Assert.AreEqual (-1, col.IndexOf (7), "#C4");
+ }
+
+ [Test]
+ [NUnit.Framework.Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=363276
+ public void RemoveAt_Index_Negative ()
+ {
+ col.Add (5);
+
+ try {
+ col.RemoveAt (-1);
+ Assert.Fail ("#1");
+ } catch (IndexOutOfRangeException ex) {
+ // Index was outside the bounds of the array
+ Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ }
+
+ Assert.AreEqual (1, col.Count, "#5");
+ }
+
+ [Test]
+ [NUnit.Framework.Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=363276
+ public void RemoveAt_Index_Overflow ()
+ {
+ col.Add (5);
+
+ try {
+ col.RemoveAt (1);
+ Assert.Fail ("#1");
+ } catch (ArgumentOutOfRangeException ex) {
+ // Index was outside the bounds of the array
+ Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.AreEqual ("index", ex.ParamName, "#5");
+ }
+
+ Assert.AreEqual (1, col.Count, "#6");
+ }
+
+ [Test]
+ public void ICollection_IsSynchronized ()
+ {
+ ICollection collection = (ICollection) col;
+ Assert.IsTrue (collection.IsSynchronized);
+ }
+
+ [Test]
+ public void ICollection_SyncRoot ()
+ {
+ ICollection collection = (ICollection) col;
+ Assert.AreSame (collection, collection.SyncRoot);
+ }
+
+ [Test]
+ public void IList_Add ()
+ {
+ IList list = (IList) col;
+ list.Add (5);
+ Assert.AreEqual (1, list.Count, "#1");
+ list.Add (7);
+ Assert.AreEqual (2, list.Count, "#2");
+ list.Add (5);
+ Assert.AreEqual (2, list.Count, "#3");
+ list.Add (3);
+ Assert.AreEqual (3, list.Count, "#4");
+ }
+
+ [Test]
+ public void IList_Add_Item_Invalid ()
+ {
+ IList list = (IList) col;
+
+ try {
+ list.Add (null);
+ Assert.Fail ("#A1");
+ } catch (ArgumentException ex) {
+ Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
+ Assert.IsNull (ex.InnerException, "#A3");
+ Assert.AreEqual ("item", ex.Message, "#A4");
+ Assert.IsNull (ex.ParamName, "#A5");
+ }
+
+ try {
+ list.Add ("x");
+ Assert.Fail ("#B1");
+ } catch (ArgumentException ex) {
+ Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+ Assert.IsNull (ex.InnerException, "#B3");
+ Assert.AreEqual ("item", ex.Message, "#B4");
+ Assert.IsNull (ex.ParamName, "#B5");
+ }
+ }
+
+ [Test]
+ public void IList_Clear ()
+ {
+ IList list = (IList) col;
+ list.Add (5);
+ list.Add (7);
+ list.Clear ();
+ Assert.AreEqual (0, list.Count);
+ }
+
+ [Test]
+ public void IList_Contains ()
+ {
+ IList list = (IList) col;
+ list.Add (5);
+ list.Add (7);
+ Assert.IsTrue (list.Contains (5), "#1");
+ Assert.IsFalse (list.Contains (3), "#2");
+ Assert.IsTrue (list.Contains (7), "#3");
+ Assert.IsFalse (list.Contains (null), "#4");
+ Assert.IsFalse (list.Contains ("x"), "#5");
+ }
+
+ [Test]
+ public void IList_Indexer ()
+ {
+ IList list = (IList) col;
+ list.Add (5);
+ list.Add (7);
+ Assert.AreEqual (7, list [1], "#1");
+ Assert.AreEqual (5, list [0], "#2");
+ list [0] = 3;
+ Assert.AreEqual (7, list [1], "#3");
+ Assert.AreEqual (3, list [0], "#4");
+ }
+
+ [Test]
+ public void IList_IndexOf ()
+ {
+ IList list = (IList) col;
+ list.Add (5);
+ list.Add (7);
+ Assert.AreEqual (0, list.IndexOf (5), "#1");
+ Assert.AreEqual (-1, list.IndexOf (3), "#2");
+ Assert.AreEqual (1, list.IndexOf (7), "#3");
+ Assert.AreEqual (-1, list.IndexOf (null), "#4");
+ Assert.AreEqual (-1, list.IndexOf ("x"), "#5");
+ }
+
+ [Test]
+ public void IList_Insert ()
+ {
+ IList list = (IList) col;
+ list.Add (5);
+
+ try {
+ list.Insert (0, 7);
+ Assert.Fail ("#A1");
+ } catch (NotSupportedException ex) {
+ // ListBox.IntegerCollection is sorted, and
+ // items cannot be inserted into it
+ Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#A2");
+ Assert.IsNull (ex.InnerException, "#A3");
+ Assert.IsNotNull (ex.Message, "#A4");
+ }
+
+ try {
+ list.Insert (-5, null);
+ Assert.Fail ("#B1");
+ } catch (NotSupportedException ex) {
+ // ListBox.IntegerCollection is sorted, and
+ // items cannot be inserted into it
+ Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#B2");
+ Assert.IsNull (ex.InnerException, "#B3");
+ Assert.IsNotNull (ex.Message, "#B4");
+ }
+ }
+
+ [Test]
+ public void IList_IsFixedSize ()
+ {
+ IList list = (IList) col;
+ Assert.IsFalse (list.IsFixedSize);
+ }
+
+ [Test]
+ public void IList_IsReadOnly ()
+ {
+ IList list = (IList) col;
+ Assert.IsFalse (list.IsReadOnly);
+ }
+
+ [Test]
+ public void IList_Remove ()
+ {
+ IList list = (IList) col;
+ list.Add (5);
+ list.Add (3);
+ list.Remove (5);
+ list.Remove (7);
+ list.Remove (int.MinValue);
+ list.Remove (int.MaxValue);
+
+ Assert.AreEqual (1, list.Count, "#1");
+ Assert.AreEqual (3, list [0], "#2");
+ list.Remove (3);
+ Assert.AreEqual (0, list.Count, "#3");
+ }
+
+ [Test]
+ public void IList_Remove_Value_Invalid ()
+ {
+ IList list = (IList) col;
+ list.Add (5);
+
+ try {
+ list.Remove ("x");
+ Assert.Fail ("#A1");
+ } catch (ArgumentException ex) {
+ Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
+ Assert.IsNull (ex.InnerException, "#A3");
+ Assert.AreEqual ("value", ex.Message, "#A4");
+ Assert.IsNull (ex.ParamName, "#A5");
+ }
+
+ try {
+ list.Remove (null);
+ Assert.Fail ("#B1");
+ } catch (ArgumentException ex) {
+ Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+ Assert.IsNull (ex.InnerException, "#B3");
+ Assert.AreEqual ("value", ex.Message, "#B4");
+ Assert.IsNull (ex.ParamName, "#B5");
+ }
+ }
+
+ [Test]
+ public void IList_RemoveAt ()
+ {
+ IList list = (IList) col;
+ list.Add (5);
+ list.Add (3);
+ list.Add (7);
+ list.RemoveAt (1);
+ Assert.AreEqual (2, list.Count, "#A1");
+ Assert.AreEqual (3, list [0], "#A2");
+ Assert.AreEqual (7, list [1], "#A3");
+ list.RemoveAt (0);
+ Assert.AreEqual (1, list.Count, "#B1");
+ Assert.AreEqual (7, list [0], "#B2");
+ list.RemoveAt (0);
+ Assert.AreEqual (0, list.Count, "#C");
+ }
+
+ [Test]
+ public void IList_RemoveAt_Index_Negative ()
+ {
+ IList list = (IList) col;
+ list.Add (5);
+
+ try {
+ list.RemoveAt (-1);
+ Assert.Fail ("#1");
+ } catch (IndexOutOfRangeException ex) {
+ // Index was outside the bounds of the array
+ Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ }
+
+ // // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=363276
+ //Assert.AreEqual (1, list.Count, "#5");