2 // CodeAttributeArgumentCollectionTest.cs
3 // - Unit tests for System.CodeDom.CodeAttributeArgumentCollection
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 CodeAttributeArgumentCollectionTest {
40 public void Constructor0 ()
42 CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection ();
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 CodeAttributeArgument caa1 = new CodeAttributeArgument ();
54 CodeAttributeArgument caa2 = new CodeAttributeArgument ();
56 CodeAttributeArgument[] arguments = new CodeAttributeArgument[] { caa1, caa2 };
57 CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection (
60 Assert.AreEqual (2, coll.Count, "#1");
61 Assert.AreEqual (0, coll.IndexOf (caa1), "#2");
62 Assert.AreEqual (1, coll.IndexOf (caa2), "#3");
66 [ExpectedException (typeof (ArgumentNullException))]
67 public void Constructor1_NullItem ()
69 CodeAttributeArgument[] arguments = new CodeAttributeArgument[] {
70 new CodeAttributeArgument (), null };
72 CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection (
77 [ExpectedException (typeof (ArgumentNullException))]
78 public void Constructor1_Null () {
79 CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection (
80 (CodeAttributeArgument[]) null);
84 public void Constructor2 ()
86 CodeAttributeArgument caa1 = new CodeAttributeArgument ();
87 CodeAttributeArgument caa2 = new CodeAttributeArgument ();
89 CodeAttributeArgumentCollection c = new CodeAttributeArgumentCollection ();
93 CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection (c);
94 Assert.AreEqual (2, coll.Count, "#1");
95 Assert.AreEqual (0, coll.IndexOf (caa1), "#2");
96 Assert.AreEqual (1, coll.IndexOf (caa2), "#3");
100 [ExpectedException (typeof (ArgumentNullException))]
101 public void Constructor2_Null ()
103 CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection (
104 (CodeAttributeArgumentCollection) null);
110 CodeAttributeArgument caa1 = new CodeAttributeArgument ();
111 CodeAttributeArgument caa2 = new CodeAttributeArgument ();
113 CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection ();
114 Assert.AreEqual (0, coll.Add (caa1), "#1");
115 Assert.AreEqual (1, coll.Count, "#2");
116 Assert.AreEqual (0, coll.IndexOf (caa1), "#3");
118 Assert.AreEqual (1, coll.Add (caa2), "#4");
119 Assert.AreEqual (2, coll.Count, "#5");
120 Assert.AreEqual (1, coll.IndexOf (caa2), "#6");
124 [ExpectedException (typeof (ArgumentNullException))]
125 public void Add_Null () {
126 CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection ();
127 coll.Add ((CodeAttributeArgument) null);
131 public void Insert ()
133 CodeAttributeArgument caa1 = new CodeAttributeArgument ();
134 CodeAttributeArgument caa2 = new CodeAttributeArgument ();
136 CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection ();
138 Assert.AreEqual (1, coll.Count, "#1");
139 Assert.AreEqual (0, coll.IndexOf (caa1), "#2");
140 coll.Insert (0, caa2);
141 Assert.AreEqual (2, coll.Count, "#3");
142 Assert.AreEqual (1, coll.IndexOf (caa1), "#4");
143 Assert.AreEqual (0, coll.IndexOf (caa2), "#5");
147 [ExpectedException (typeof (ArgumentNullException))]
148 public void Insert_Null ()
150 CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection ();
151 coll.Insert (0, (CodeAttributeArgument) null);
155 public void AddRange ()
157 CodeAttributeArgument caa1 = new CodeAttributeArgument ();
158 CodeAttributeArgument caa2 = new CodeAttributeArgument ();
159 CodeAttributeArgument caa3 = new CodeAttributeArgument ();
161 CodeAttributeArgumentCollection coll1 = new CodeAttributeArgumentCollection ();
165 CodeAttributeArgumentCollection coll2 = new CodeAttributeArgumentCollection();
167 coll2.AddRange (coll1);
168 Assert.AreEqual (3, coll2.Count, "#1");
169 Assert.AreEqual (1, coll2.IndexOf (caa1), "#2");
170 Assert.AreEqual (2, coll2.IndexOf (caa2), "#3");
171 Assert.AreEqual (0, coll2.IndexOf (caa3), "#4");
173 CodeAttributeArgumentCollection coll3 = new CodeAttributeArgumentCollection();
175 coll3.AddRange (new CodeAttributeArgument[] {caa1, caa2});
176 Assert.AreEqual (3, coll2.Count, "#5");
177 Assert.AreEqual (1, coll2.IndexOf (caa1), "#6");
178 Assert.AreEqual (2, coll2.IndexOf (caa2), "#7");
179 Assert.AreEqual (0, coll2.IndexOf (caa3), "#8");
183 [ExpectedException (typeof (ArgumentNullException))]
184 public void AddRange_Null_Array ()
186 CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection ();
187 coll.AddRange ((CodeAttributeArgument[]) null);
191 [ExpectedException (typeof (ArgumentNullException))]
192 public void AddRange_Null_Item ()
194 CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection ();
195 coll.AddRange (new CodeAttributeArgument[] { null });
199 [ExpectedException (typeof (ArgumentNullException))]
200 public void AddRange_Null_Collection ()
202 CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection ();
203 coll.AddRange ((CodeAttributeArgumentCollection) null);
207 public void AddRange_Self ()
209 CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection ();
210 coll.Add (new CodeAttributeArgument ());
211 Assert.AreEqual (1, coll.Count, "#1");
212 coll.AddRange (coll);
213 Assert.AreEqual (2, coll.Count, "#2");
217 public void Remove ()
219 CodeAttributeArgument caa1 = new CodeAttributeArgument ();
220 CodeAttributeArgument caa2 = new CodeAttributeArgument ();
222 CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection ();
225 Assert.AreEqual (2, coll.Count, "#1");
226 Assert.AreEqual (0, coll.IndexOf (caa1), "#2");
227 Assert.AreEqual (1, coll.IndexOf (caa2), "#3");
229 Assert.AreEqual (1, coll.Count, "#4");
230 Assert.AreEqual (-1, coll.IndexOf (caa1), "#5");
231 Assert.AreEqual (0, coll.IndexOf (caa2), "#6");
235 [ExpectedException (typeof (ArgumentException))]
236 public void Remove_NotInCollection ()
238 CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection ();
239 coll.Remove (new CodeAttributeArgument ());
243 [ExpectedException (typeof (ArgumentNullException))]
244 public void Remove_Null ()
246 CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection ();
247 coll.Remove ((CodeAttributeArgument) null);