CodeCommentStatementCollectionTest.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. //
  2. // CodeCommentStatementCollectionTest.cs
  3. // - Unit tests for System.CodeDom.CodeCommentStatementCollection
  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 CodeCommentStatementCollectionTest {
  36. [Test]
  37. public void Constructor0 ()
  38. {
  39. CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
  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.IsNotNull (((ICollection) coll).SyncRoot, "#5");
  45. }
  46. [Test]
  47. public void Constructor1 ()
  48. {
  49. CodeCommentStatement ccs1 = new CodeCommentStatement ();
  50. CodeCommentStatement ccs2 = new CodeCommentStatement ();
  51. CodeCommentStatement[] statements = new CodeCommentStatement[] { ccs1, ccs2 };
  52. CodeCommentStatementCollection coll = new CodeCommentStatementCollection (
  53. statements);
  54. Assert.AreEqual (2, coll.Count, "#1");
  55. Assert.AreEqual (0, coll.IndexOf (ccs1), "#2");
  56. Assert.AreEqual (1, coll.IndexOf (ccs2), "#3");
  57. }
  58. [Test]
  59. [ExpectedException (typeof (ArgumentNullException))]
  60. public void Constructor1_NullItem ()
  61. {
  62. CodeCommentStatement[] statements = new CodeCommentStatement[] {
  63. new CodeCommentStatement (), null };
  64. CodeCommentStatementCollection coll = new CodeCommentStatementCollection (
  65. statements);
  66. }
  67. [Test]
  68. [ExpectedException (typeof (ArgumentNullException))]
  69. public void Constructor1_Null () {
  70. CodeCommentStatementCollection coll = new CodeCommentStatementCollection (
  71. (CodeCommentStatement[]) null);
  72. }
  73. [Test]
  74. public void Constructor2 ()
  75. {
  76. CodeCommentStatement ccs1 = new CodeCommentStatement ();
  77. CodeCommentStatement ccs2 = new CodeCommentStatement ();
  78. CodeCommentStatementCollection c = new CodeCommentStatementCollection ();
  79. c.Add (ccs1);
  80. c.Add (ccs2);
  81. CodeCommentStatementCollection coll = new CodeCommentStatementCollection (c);
  82. Assert.AreEqual (2, coll.Count, "#1");
  83. Assert.AreEqual (0, coll.IndexOf (ccs1), "#2");
  84. Assert.AreEqual (1, coll.IndexOf (ccs2), "#3");
  85. }
  86. [Test]
  87. [ExpectedException (typeof (ArgumentNullException))]
  88. public void Constructor2_Null ()
  89. {
  90. CodeCommentStatementCollection coll = new CodeCommentStatementCollection (
  91. (CodeCommentStatementCollection) null);
  92. }
  93. [Test]
  94. public void Add ()
  95. {
  96. CodeCommentStatement ccs1 = new CodeCommentStatement ();
  97. CodeCommentStatement ccs2 = new CodeCommentStatement ();
  98. CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
  99. Assert.AreEqual (0, coll.Add (ccs1), "#1");
  100. Assert.AreEqual (1, coll.Count, "#2");
  101. Assert.AreEqual (0, coll.IndexOf (ccs1), "#3");
  102. Assert.AreEqual (1, coll.Add (ccs2), "#4");
  103. Assert.AreEqual (2, coll.Count, "#5");
  104. Assert.AreEqual (1, coll.IndexOf (ccs2), "#6");
  105. }
  106. [Test]
  107. [ExpectedException (typeof (ArgumentNullException))]
  108. public void Add_Null () {
  109. CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
  110. coll.Add ((CodeCommentStatement) null);
  111. }
  112. [Test]
  113. public void Insert ()
  114. {
  115. CodeCommentStatement ccs1 = new CodeCommentStatement ();
  116. CodeCommentStatement ccs2 = new CodeCommentStatement ();
  117. CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
  118. coll.Add (ccs1);
  119. Assert.AreEqual (1, coll.Count, "#1");
  120. Assert.AreEqual (0, coll.IndexOf (ccs1), "#2");
  121. coll.Insert (0, ccs2);
  122. Assert.AreEqual (2, coll.Count, "#3");
  123. Assert.AreEqual (1, coll.IndexOf (ccs1), "#4");
  124. Assert.AreEqual (0, coll.IndexOf (ccs2), "#5");
  125. }
  126. [Test]
  127. [ExpectedException (typeof (ArgumentNullException))]
  128. public void Insert_Null ()
  129. {
  130. CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
  131. coll.Insert (0, (CodeCommentStatement) null);
  132. }
  133. [Test]
  134. public void AddRange ()
  135. {
  136. CodeCommentStatement ccs1 = new CodeCommentStatement ();
  137. CodeCommentStatement ccs2 = new CodeCommentStatement ();
  138. CodeCommentStatement ccs3 = new CodeCommentStatement ();
  139. CodeCommentStatementCollection coll1 = new CodeCommentStatementCollection ();
  140. coll1.Add (ccs1);
  141. coll1.Add (ccs2);
  142. CodeCommentStatementCollection coll2 = new CodeCommentStatementCollection ();
  143. coll2.Add (ccs3);
  144. coll2.AddRange (coll1);
  145. Assert.AreEqual (3, coll2.Count, "#1");
  146. Assert.AreEqual (1, coll2.IndexOf (ccs1), "#2");
  147. Assert.AreEqual (2, coll2.IndexOf (ccs2), "#3");
  148. Assert.AreEqual (0, coll2.IndexOf (ccs3), "#4");
  149. CodeCommentStatementCollection coll3 = new CodeCommentStatementCollection ();
  150. coll3.Add (ccs3);
  151. coll3.AddRange (new CodeCommentStatement[] { ccs1, ccs2 });
  152. Assert.AreEqual (3, coll2.Count, "#5");
  153. Assert.AreEqual (1, coll2.IndexOf (ccs1), "#6");
  154. Assert.AreEqual (2, coll2.IndexOf (ccs2), "#7");
  155. Assert.AreEqual (0, coll2.IndexOf (ccs3), "#8");
  156. }
  157. [Test]
  158. [ExpectedException (typeof (ArgumentNullException))]
  159. public void AddRange_Null_Array ()
  160. {
  161. CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
  162. coll.AddRange ((CodeCommentStatement[]) null);
  163. }
  164. [Test]
  165. [ExpectedException (typeof (ArgumentNullException))]
  166. public void AddRange_Null_Item ()
  167. {
  168. CodeNamespaceCollection coll = new CodeNamespaceCollection ();
  169. coll.AddRange (new CodeNamespace[] { null });
  170. }
  171. [Test]
  172. [ExpectedException (typeof (ArgumentNullException))]
  173. public void AddRange_Null_Collection ()
  174. {
  175. CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
  176. coll.AddRange ((CodeCommentStatementCollection) null);
  177. }
  178. [Test]
  179. public void AddRange_Self ()
  180. {
  181. CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
  182. coll.Add (new CodeCommentStatement ());
  183. Assert.AreEqual (1, coll.Count, "#1");
  184. coll.AddRange (coll);
  185. Assert.AreEqual (2, coll.Count, "#2");
  186. }
  187. [Test]
  188. public void Remove ()
  189. {
  190. CodeCommentStatement ccs1 = new CodeCommentStatement ();
  191. CodeCommentStatement ccs2 = new CodeCommentStatement ();
  192. CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
  193. coll.Add (ccs1);
  194. coll.Add (ccs2);
  195. Assert.AreEqual (2, coll.Count, "#1");
  196. Assert.AreEqual (0, coll.IndexOf (ccs1), "#2");
  197. Assert.AreEqual (1, coll.IndexOf (ccs2), "#3");
  198. coll.Remove (ccs1);
  199. Assert.AreEqual (1, coll.Count, "#4");
  200. Assert.AreEqual (-1, coll.IndexOf (ccs1), "#5");
  201. Assert.AreEqual (0, coll.IndexOf (ccs2), "#6");
  202. }
  203. [Test]
  204. [ExpectedException (typeof (ArgumentException))]
  205. public void Remove_NotInCollection ()
  206. {
  207. CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
  208. coll.Remove (new CodeCommentStatement ());
  209. }
  210. [Test]
  211. [ExpectedException (typeof (ArgumentNullException))]
  212. public void Remove_Null ()
  213. {
  214. CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
  215. coll.Remove ((CodeCommentStatement) null);
  216. }
  217. }
  218. }