CodeNamespaceImportCollectionTest.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // CodeNamespaceImportCollectionTest.cs
  3. // - Unit tests for System.CodeDom.CodeNamespaceImportCollection
  4. //
  5. // Author:
  6. // Gert Driesen <[email protected]>
  7. //
  8. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using NUnit.Framework;
  30. using System;
  31. using System.Collections;
  32. using System.CodeDom;
  33. namespace MonoTests.System.CodeDom {
  34. [TestFixture]
  35. public class CodeNamespaceImportCollectionTest {
  36. [Test]
  37. public void Constructor0 ()
  38. {
  39. CodeNamespaceImportCollection coll = new CodeNamespaceImportCollection ();
  40. Assert.IsFalse (((IList) coll).IsFixedSize, "#1");
  41. Assert.IsFalse (((IList) coll).IsReadOnly, "#2");
  42. Assert.AreEqual (0, coll.Count, "#3");
  43. Assert.IsFalse (((ICollection) coll).IsSynchronized, "#4");
  44. Assert.IsNull (((ICollection) coll).SyncRoot, "#5");
  45. }
  46. [Test]
  47. public void Add ()
  48. {
  49. CodeNamespaceImport ni1 = new CodeNamespaceImport ("A");
  50. CodeNamespaceImport ni2 = new CodeNamespaceImport ("B");
  51. CodeNamespaceImport ni3 = new CodeNamespaceImport ("b");
  52. CodeNamespaceImport ni4 = new CodeNamespaceImport ("B");
  53. CodeNamespaceImportCollection coll = new CodeNamespaceImportCollection ();
  54. coll.Add (ni1);
  55. Assert.AreEqual (1, coll.Count, "#1");
  56. Assert.AreEqual (0, ((IList) coll).IndexOf (ni1), "#2");
  57. coll.Add (ni2);
  58. Assert.AreEqual (2, coll.Count, "#3");
  59. Assert.AreEqual (1, ((IList) coll).IndexOf (ni2), "#4");
  60. coll.Add (ni3);
  61. Assert.AreEqual (2, coll.Count, "#5");
  62. Assert.AreEqual (-1, ((IList) coll).IndexOf (ni3), "#6");
  63. coll.Add (ni4);
  64. Assert.AreEqual (2, coll.Count, "#7");
  65. Assert.AreEqual (-1, ((IList) coll).IndexOf (ni4), "#8");
  66. }
  67. [Test]
  68. [ExpectedException (typeof (NullReferenceException))]
  69. public void Add_Null () {
  70. CodeNamespaceImportCollection coll = new CodeNamespaceImportCollection ();
  71. coll.Add ((CodeNamespaceImport) null);
  72. }
  73. [Test]
  74. public void AddRange ()
  75. {
  76. CodeNamespaceImport ni1 = new CodeNamespaceImport ("A");
  77. CodeNamespaceImport ni2 = new CodeNamespaceImport ("B");
  78. CodeNamespaceImport ni3 = new CodeNamespaceImport ("b");
  79. CodeNamespaceImport ni4 = new CodeNamespaceImport ("B");
  80. CodeNamespaceImport ni5 = new CodeNamespaceImport ("C");
  81. CodeNamespaceImportCollection coll = new CodeNamespaceImportCollection ();
  82. coll.AddRange (new CodeNamespaceImport[] {ni1, ni2});
  83. Assert.AreEqual (2, coll.Count, "#1");
  84. Assert.AreEqual (0, ((IList) coll).IndexOf (ni1), "#2");
  85. Assert.AreEqual (1, ((IList) coll).IndexOf (ni2), "#3");
  86. coll.AddRange (new CodeNamespaceImport[] { ni3, ni4, ni5 });
  87. Assert.AreEqual (3, coll.Count, "#4");
  88. Assert.AreEqual (0, ((IList) coll).IndexOf (ni1), "#5");
  89. Assert.AreEqual (1, ((IList) coll).IndexOf (ni2), "#6");
  90. Assert.AreEqual (-1, ((IList) coll).IndexOf (ni3), "#7");
  91. Assert.AreEqual (-1, ((IList) coll).IndexOf (ni4), "#8");
  92. Assert.AreEqual (2, ((IList) coll).IndexOf (ni5), "#9");
  93. }
  94. [Test]
  95. [ExpectedException (typeof (ArgumentNullException))]
  96. public void AddRange_Null_Array ()
  97. {
  98. CodeNamespaceImportCollection coll = new CodeNamespaceImportCollection ();
  99. coll.AddRange ((CodeNamespaceImport[]) null);
  100. }
  101. [Test]
  102. [ExpectedException (typeof (NullReferenceException))]
  103. public void AddRange_Null_Item()
  104. {
  105. CodeNamespaceImportCollection coll = new CodeNamespaceImportCollection();
  106. coll.AddRange(new CodeNamespaceImport[] { null });
  107. }
  108. }
  109. }