SynchronizedReadOnlyCollectionTest.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ServiceModel;
  5. using NUnit.Framework;
  6. using ObjectList = System.Collections.Generic.SynchronizedReadOnlyCollection<object>;
  7. namespace MonoTests.System.ServiceModel
  8. {
  9. [TestFixture]
  10. public class SynchronizedReadOnlyCollectionTest
  11. {
  12. [Test, ExpectedException (typeof (ArgumentException))]
  13. public void TestIListIndexOf ()
  14. {
  15. SynchronizedReadOnlyCollection<int> c = new SynchronizedReadOnlyCollection<int> ();
  16. ((IList) c).IndexOf ("foo");
  17. }
  18. [Test, ExpectedException (typeof (ArgumentException))]
  19. public void TestIListContainsWrongType()
  20. {
  21. SynchronizedReadOnlyCollection<int> c = new SynchronizedReadOnlyCollection<int> ();
  22. ((IList) c).Contains ("foo");
  23. }
  24. [Test]
  25. public void TestIListContainsNull ()
  26. {
  27. ObjectList c = new ObjectList ();
  28. Assert.IsFalse (((IList) c).Contains (null));
  29. SynchronizedReadOnlyCollection<ValueType> d = new SynchronizedReadOnlyCollection<ValueType> ();
  30. Assert.IsFalse (((IList) d).Contains (null));
  31. }
  32. [Test, ExpectedException (typeof (ArgumentException))]
  33. public void TestICollectionCopyTo ()
  34. {
  35. SynchronizedReadOnlyCollection<int> c = new SynchronizedReadOnlyCollection<int> ();
  36. Array a = Array.CreateInstance (typeof (String), 10);
  37. ((ICollection) c).CopyTo (a, 0);
  38. }
  39. [Test]
  40. public void TestCtorListArg ()
  41. {
  42. object x = new object ();
  43. object y = new object ();
  44. ObjectList c = new ObjectList (new object (),
  45. new object [] {x, y});
  46. Assert.AreEqual (2, c.Count, "#1");
  47. // indexer
  48. Assert.AreEqual (x, c [0], "#2");
  49. Assert.AreEqual (y, c [1], "#3");
  50. // GetEnumerator
  51. IEnumerator<object> ge = c.GetEnumerator ();
  52. Assert.IsTrue (ge.MoveNext (), "#8");
  53. Assert.AreEqual (x, ge.Current, "#9");
  54. Assert.IsTrue (ge.MoveNext (), "#10");
  55. Assert.AreEqual (y, ge.Current, "#11");
  56. // IEnumerable.GetEnumerator
  57. IEnumerable enu = c;
  58. IEnumerator e = enu.GetEnumerator ();
  59. Assert.IsTrue (e.MoveNext (), "#4");
  60. Assert.AreEqual (x, e.Current, "#5");
  61. Assert.IsTrue (e.MoveNext (), "#6");
  62. Assert.AreEqual (y, e.Current, "#7");
  63. }
  64. }
  65. }