2 // CodeParameterDeclarationExpressionCollectionTest.cs
3 // - Unit tests for System.CodeDom.CodeParameterDeclarationExpressionCollection
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 CodeParameterDeclarationExpressionCollectionTest {
40 public void Constructor0 ()
42 CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
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");
50 public void Constructor1 ()
52 CodeParameterDeclarationExpression param1 = new CodeParameterDeclarationExpression ();
53 CodeParameterDeclarationExpression param2 = new CodeParameterDeclarationExpression ();
55 CodeParameterDeclarationExpression[] parameters = new CodeParameterDeclarationExpression[] { param1, param2 };
56 CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection (
59 Assert.AreEqual (2, coll.Count, "#1");
60 Assert.AreEqual (0, coll.IndexOf (param1), "#2");
61 Assert.AreEqual (1, coll.IndexOf (param2), "#3");
65 [ExpectedException (typeof (ArgumentNullException))]
66 public void Constructor1_NullItem ()
68 CodeParameterDeclarationExpression[] parameters = new CodeParameterDeclarationExpression[] {
69 new CodeParameterDeclarationExpression (), null };
71 CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection (
76 [ExpectedException (typeof (ArgumentNullException))]
77 public void Constructor1_Null () {
78 CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection (
79 (CodeParameterDeclarationExpression[]) null);
83 public void Constructor2 ()
85 CodeParameterDeclarationExpression param1 = new CodeParameterDeclarationExpression ();
86 CodeParameterDeclarationExpression param2 = new CodeParameterDeclarationExpression ();
88 CodeParameterDeclarationExpressionCollection c = new CodeParameterDeclarationExpressionCollection ();
92 CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection (c);
93 Assert.AreEqual (2, coll.Count, "#1");
94 Assert.AreEqual (0, coll.IndexOf (param1), "#2");
95 Assert.AreEqual (1, coll.IndexOf (param2), "#3");
99 [ExpectedException (typeof (ArgumentNullException))]
100 public void Constructor2_Null ()
102 CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection (
103 (CodeParameterDeclarationExpressionCollection) null);
109 CodeParameterDeclarationExpression param1 = new CodeParameterDeclarationExpression ();
110 CodeParameterDeclarationExpression param2 = new CodeParameterDeclarationExpression ();
112 CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
113 Assert.AreEqual (0, coll.Add (param1), "#1");
114 Assert.AreEqual (1, coll.Count, "#2");
115 Assert.AreEqual (0, coll.IndexOf (param1), "#3");
117 Assert.AreEqual (1, coll.Add (param2), "#4");
118 Assert.AreEqual (2, coll.Count, "#5");
119 Assert.AreEqual (1, coll.IndexOf (param2), "#6");
123 [ExpectedException (typeof (ArgumentNullException))]
124 public void Add_Null () {
125 CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
126 coll.Add ((CodeParameterDeclarationExpression) null);
130 public void Insert ()
132 CodeParameterDeclarationExpression param1 = new CodeParameterDeclarationExpression ();
133 CodeParameterDeclarationExpression param2 = new CodeParameterDeclarationExpression ();
135 CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
137 Assert.AreEqual (1, coll.Count, "#1");
138 Assert.AreEqual (0, coll.IndexOf (param1), "#2");
139 coll.Insert (0, param2);
140 Assert.AreEqual (2, coll.Count, "#3");
141 Assert.AreEqual (1, coll.IndexOf (param1), "#4");
142 Assert.AreEqual (0, coll.IndexOf (param2), "#5");
146 [ExpectedException (typeof (ArgumentNullException))]
147 public void Insert_Null ()
149 CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
150 coll.Insert (0, (CodeParameterDeclarationExpression) null);
154 public void AddRange ()
156 CodeParameterDeclarationExpression param1 = new CodeParameterDeclarationExpression ();
157 CodeParameterDeclarationExpression param2 = new CodeParameterDeclarationExpression ();
158 CodeParameterDeclarationExpression param3 = new CodeParameterDeclarationExpression ();
160 CodeParameterDeclarationExpressionCollection coll1 = new CodeParameterDeclarationExpressionCollection ();
164 CodeParameterDeclarationExpressionCollection coll2 = new CodeParameterDeclarationExpressionCollection ();
166 coll2.AddRange (coll1);
167 Assert.AreEqual (3, coll2.Count, "#1");
168 Assert.AreEqual (1, coll2.IndexOf (param1), "#2");
169 Assert.AreEqual (2, coll2.IndexOf (param2), "#3");
170 Assert.AreEqual (0, coll2.IndexOf (param3), "#4");
172 CodeParameterDeclarationExpressionCollection coll3 = new CodeParameterDeclarationExpressionCollection ();
174 coll3.AddRange (new CodeParameterDeclarationExpression[] { param1, param2 });
175 Assert.AreEqual (3, coll2.Count, "#5");
176 Assert.AreEqual (1, coll2.IndexOf (param1), "#6");
177 Assert.AreEqual (2, coll2.IndexOf (param2), "#7");
178 Assert.AreEqual (0, coll2.IndexOf (param3), "#8");
182 [ExpectedException (typeof (ArgumentNullException))]
183 public void AddRange_Null_Array ()
185 CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
186 coll.AddRange ((CodeParameterDeclarationExpression[]) null);
190 [ExpectedException (typeof (ArgumentNullException))]
191 public void AddRange_Null_Item ()
193 CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
194 coll.AddRange (new CodeParameterDeclarationExpression[] { null });
198 [ExpectedException (typeof (ArgumentNullException))]
199 public void AddRange_Null_Collection ()
201 CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
202 coll.AddRange ((CodeParameterDeclarationExpressionCollection) null);
206 public void AddRange_Self ()
208 CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
209 coll.Add (new CodeParameterDeclarationExpression ());
210 Assert.AreEqual (1, coll.Count, "#1");
211 coll.AddRange (coll);
212 Assert.AreEqual (2, coll.Count, "#2");
216 public void Remove ()
218 CodeParameterDeclarationExpression cpde1 = new CodeParameterDeclarationExpression ();
219 CodeParameterDeclarationExpression cpde2 = new CodeParameterDeclarationExpression ();
221 CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
224 Assert.AreEqual (2, coll.Count, "#1");
225 Assert.AreEqual (0, coll.IndexOf (cpde1), "#2");
226 Assert.AreEqual (1, coll.IndexOf (cpde2), "#3");
228 Assert.AreEqual (1, coll.Count, "#4");
229 Assert.AreEqual (-1, coll.IndexOf (cpde1), "#5");
230 Assert.AreEqual (0, coll.IndexOf (cpde2), "#6");
234 [ExpectedException (typeof (ArgumentException))]
235 public void Remove_NotInCollection ()
237 CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
238 coll.Remove (new CodeParameterDeclarationExpression ());
242 [ExpectedException (typeof (ArgumentNullException))]
243 public void Remove_Null ()
245 CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
246 coll.Remove ((CodeParameterDeclarationExpression) null);