2 // CodeCommentStatementCollectionTest.cs
3 // - Unit tests for System.CodeDom.CodeCommentStatementCollection
6 // Gert Driesen <drieseng@users.sourceforge.net>
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
30 using NUnit.Framework;
33 using System.Collections;
36 namespace MonoTests.System.CodeDom {
38 public class CodeCommentStatementCollectionTest {
40 public void Constructor0 ()
42 CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
43 Assert.IsFalse (((IList) coll).IsFixedSize, "#1");
44 Assert.IsFalse (((IList) coll).IsReadOnly, "#2");
45 Assert.AreEqual (0, coll.Count, "#3");
46 Assert.IsFalse (((ICollection) coll).IsSynchronized, "#4");
47 Assert.IsNotNull (((ICollection) coll).SyncRoot, "#5");
51 public void Constructor1 ()
53 CodeCommentStatement ccs1 = new CodeCommentStatement ();
54 CodeCommentStatement ccs2 = new CodeCommentStatement ();
56 CodeCommentStatement[] statements = new CodeCommentStatement[] { ccs1, ccs2 };
57 CodeCommentStatementCollection coll = new CodeCommentStatementCollection (
60 Assert.AreEqual (2, coll.Count, "#1");
61 Assert.AreEqual (0, coll.IndexOf (ccs1), "#2");
62 Assert.AreEqual (1, coll.IndexOf (ccs2), "#3");
66 [ExpectedException (typeof (ArgumentNullException))]
67 public void Constructor1_NullItem ()
69 CodeCommentStatement[] statements = new CodeCommentStatement[] {
70 new CodeCommentStatement (), null };
72 CodeCommentStatementCollection coll = new CodeCommentStatementCollection (
77 [ExpectedException (typeof (ArgumentNullException))]
78 public void Constructor1_Null () {
79 CodeCommentStatementCollection coll = new CodeCommentStatementCollection (
80 (CodeCommentStatement[]) null);
84 public void Constructor2 ()
86 CodeCommentStatement ccs1 = new CodeCommentStatement ();
87 CodeCommentStatement ccs2 = new CodeCommentStatement ();
89 CodeCommentStatementCollection c = new CodeCommentStatementCollection ();
93 CodeCommentStatementCollection coll = new CodeCommentStatementCollection (c);
94 Assert.AreEqual (2, coll.Count, "#1");
95 Assert.AreEqual (0, coll.IndexOf (ccs1), "#2");
96 Assert.AreEqual (1, coll.IndexOf (ccs2), "#3");
100 [ExpectedException (typeof (ArgumentNullException))]
101 public void Constructor2_Null ()
103 CodeCommentStatementCollection coll = new CodeCommentStatementCollection (
104 (CodeCommentStatementCollection) null);
110 CodeCommentStatement ccs1 = new CodeCommentStatement ();
111 CodeCommentStatement ccs2 = new CodeCommentStatement ();
113 CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
114 Assert.AreEqual (0, coll.Add (ccs1), "#1");
115 Assert.AreEqual (1, coll.Count, "#2");
116 Assert.AreEqual (0, coll.IndexOf (ccs1), "#3");
118 Assert.AreEqual (1, coll.Add (ccs2), "#4");
119 Assert.AreEqual (2, coll.Count, "#5");
120 Assert.AreEqual (1, coll.IndexOf (ccs2), "#6");
124 [ExpectedException (typeof (ArgumentNullException))]
125 public void Add_Null () {
126 CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
127 coll.Add ((CodeCommentStatement) null);
131 public void Insert ()
133 CodeCommentStatement ccs1 = new CodeCommentStatement ();
134 CodeCommentStatement ccs2 = new CodeCommentStatement ();
136 CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
138 Assert.AreEqual (1, coll.Count, "#1");
139 Assert.AreEqual (0, coll.IndexOf (ccs1), "#2");
140 coll.Insert (0, ccs2);
141 Assert.AreEqual (2, coll.Count, "#3");
142 Assert.AreEqual (1, coll.IndexOf (ccs1), "#4");
143 Assert.AreEqual (0, coll.IndexOf (ccs2), "#5");
147 [ExpectedException (typeof (ArgumentNullException))]
148 public void Insert_Null ()
150 CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
151 coll.Insert (0, (CodeCommentStatement) null);
155 public void AddRange ()
157 CodeCommentStatement ccs1 = new CodeCommentStatement ();
158 CodeCommentStatement ccs2 = new CodeCommentStatement ();
159 CodeCommentStatement ccs3 = new CodeCommentStatement ();
161 CodeCommentStatementCollection coll1 = new CodeCommentStatementCollection ();
165 CodeCommentStatementCollection coll2 = new CodeCommentStatementCollection ();
167 coll2.AddRange (coll1);
168 Assert.AreEqual (3, coll2.Count, "#1");
169 Assert.AreEqual (1, coll2.IndexOf (ccs1), "#2");
170 Assert.AreEqual (2, coll2.IndexOf (ccs2), "#3");
171 Assert.AreEqual (0, coll2.IndexOf (ccs3), "#4");
173 CodeCommentStatementCollection coll3 = new CodeCommentStatementCollection ();
175 coll3.AddRange (new CodeCommentStatement[] { ccs1, ccs2 });
176 Assert.AreEqual (3, coll2.Count, "#5");
177 Assert.AreEqual (1, coll2.IndexOf (ccs1), "#6");
178 Assert.AreEqual (2, coll2.IndexOf (ccs2), "#7");
179 Assert.AreEqual (0, coll2.IndexOf (ccs3), "#8");
183 [ExpectedException (typeof (ArgumentNullException))]
184 public void AddRange_Null_Array ()
186 CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
187 coll.AddRange ((CodeCommentStatement[]) null);
191 [ExpectedException (typeof (ArgumentNullException))]
192 public void AddRange_Null_Item ()
194 CodeNamespaceCollection coll = new CodeNamespaceCollection ();
195 coll.AddRange (new CodeNamespace[] { null });
199 [ExpectedException (typeof (ArgumentNullException))]
200 public void AddRange_Null_Collection ()
202 CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
203 coll.AddRange ((CodeCommentStatementCollection) null);
207 public void AddRange_Self ()
209 CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
210 coll.Add (new CodeCommentStatement ());
211 Assert.AreEqual (1, coll.Count, "#1");
212 coll.AddRange (coll);
213 Assert.AreEqual (2, coll.Count, "#2");
217 public void Remove ()
219 CodeCommentStatement ccs1 = new CodeCommentStatement ();
220 CodeCommentStatement ccs2 = new CodeCommentStatement ();
222 CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
225 Assert.AreEqual (2, coll.Count, "#1");
226 Assert.AreEqual (0, coll.IndexOf (ccs1), "#2");
227 Assert.AreEqual (1, coll.IndexOf (ccs2), "#3");
229 Assert.AreEqual (1, coll.Count, "#4");
230 Assert.AreEqual (-1, coll.IndexOf (ccs1), "#5");
231 Assert.AreEqual (0, coll.IndexOf (ccs2), "#6");
235 [ExpectedException (typeof (ArgumentException))]
236 public void Remove_NotInCollection ()
238 CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
239 coll.Remove (new CodeCommentStatement ());
243 [ExpectedException (typeof (ArgumentNullException))]
244 public void Remove_Null ()
246 CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
247 coll.Remove ((CodeCommentStatement) null);