2 // CodeTypeParameterCollectionTest.cs
3 // - Unit tests for System.CodeDom.CodeTypeParameterCollection
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.
31 using NUnit.Framework;
34 using System.Collections;
37 namespace MonoTests.System.CodeDom {
39 public class CodeTypeParameterCollectionTest {
41 public void Constructor0 ()
43 CodeTypeParameterCollection coll = new CodeTypeParameterCollection ();
44 Assert.IsFalse (((IList) coll).IsFixedSize, "#1");
45 Assert.IsFalse (((IList) coll).IsReadOnly, "#2");
46 Assert.AreEqual (0, coll.Count, "#3");
47 Assert.IsFalse (((ICollection) coll).IsSynchronized, "#4");
51 public void Constructor1 ()
53 CodeTypeParameter tp1 = new CodeTypeParameter ();
54 CodeTypeParameter tp2 = new CodeTypeParameter ();
56 CodeTypeParameter[] typeParams = new CodeTypeParameter[] { tp1, tp2 };
57 CodeTypeParameterCollection coll = new CodeTypeParameterCollection (
60 Assert.AreEqual (2, coll.Count, "#1");
61 Assert.AreEqual (0, coll.IndexOf (tp1), "#2");
62 Assert.AreEqual (1, coll.IndexOf (tp2), "#3");
66 [ExpectedException (typeof (ArgumentNullException))]
67 public void Constructor1_NullItem ()
69 CodeTypeParameter[] typeParams = new CodeTypeParameter[] {
70 new CodeTypeParameter (), null };
72 CodeTypeParameterCollection coll = new CodeTypeParameterCollection (
77 [ExpectedException (typeof (ArgumentNullException))]
78 public void Constructor1_Null () {
79 CodeTypeParameterCollection coll = new CodeTypeParameterCollection (
80 (CodeTypeParameter[]) null);
84 public void Constructor2 ()
86 CodeTypeParameter tp1 = new CodeTypeParameter ();
87 CodeTypeParameter tp2 = new CodeTypeParameter ();
89 CodeTypeParameterCollection c = new CodeTypeParameterCollection ();
93 CodeTypeParameterCollection coll = new CodeTypeParameterCollection (c);
94 Assert.AreEqual (2, coll.Count, "#1");
95 Assert.AreEqual (0, coll.IndexOf (tp1), "#2");
96 Assert.AreEqual (1, coll.IndexOf (tp2), "#3");
100 [ExpectedException (typeof (ArgumentNullException))]
101 public void Constructor2_Null ()
103 CodeTypeParameterCollection coll = new CodeTypeParameterCollection (
104 (CodeTypeParameterCollection) null);
110 CodeTypeParameter tp1 = new CodeTypeParameter ();
111 CodeTypeParameter tp2 = new CodeTypeParameter ();
113 CodeTypeParameterCollection coll = new CodeTypeParameterCollection ();
114 Assert.AreEqual (0, coll.Add (tp1), "#1");
115 Assert.AreEqual (1, coll.Count, "#2");
116 Assert.AreEqual (0, coll.IndexOf (tp1), "#3");
118 Assert.AreEqual (1, coll.Add (tp2), "#4");
119 Assert.AreEqual (2, coll.Count, "#5");
120 Assert.AreEqual (1, coll.IndexOf (tp2), "#6");
124 [ExpectedException (typeof (ArgumentNullException))]
125 public void Add_Null () {
126 CodeTypeParameterCollection coll = new CodeTypeParameterCollection ();
127 coll.Add ((CodeTypeParameter) null);
131 public void Insert ()
133 CodeTypeParameter tp1 = new CodeTypeParameter ();
134 CodeTypeParameter tp2 = new CodeTypeParameter ();
136 CodeTypeParameterCollection coll = new CodeTypeParameterCollection ();
138 Assert.AreEqual (1, coll.Count, "#1");
139 Assert.AreEqual (0, coll.IndexOf (tp1), "#2");
140 coll.Insert (0, tp2);
141 Assert.AreEqual (2, coll.Count, "#3");
142 Assert.AreEqual (1, coll.IndexOf (tp1), "#4");
143 Assert.AreEqual (0, coll.IndexOf (tp2), "#5");
147 [ExpectedException (typeof (ArgumentNullException))]
148 public void Insert_Null ()
150 CodeTypeParameterCollection coll = new CodeTypeParameterCollection ();
151 coll.Insert (0, (CodeTypeParameter) null);
155 public void AddRange ()
157 CodeTypeParameter tp1 = new CodeTypeParameter ();
158 CodeTypeParameter tp2 = new CodeTypeParameter ();
159 CodeTypeParameter tp3 = new CodeTypeParameter ();
161 CodeTypeParameterCollection coll1 = new CodeTypeParameterCollection ();
165 CodeTypeParameterCollection coll2 = new CodeTypeParameterCollection ();
167 coll2.AddRange (coll1);
168 Assert.AreEqual (3, coll2.Count, "#1");
169 Assert.AreEqual (1, coll2.IndexOf (tp1), "#2");
170 Assert.AreEqual (2, coll2.IndexOf (tp2), "#3");
171 Assert.AreEqual (0, coll2.IndexOf (tp3), "#4");
173 CodeTypeParameterCollection coll3 = new CodeTypeParameterCollection ();
175 coll3.AddRange (new CodeTypeParameter[] { tp1, tp2 });
176 Assert.AreEqual (3, coll2.Count, "#5");
177 Assert.AreEqual (1, coll2.IndexOf (tp1), "#6");
178 Assert.AreEqual (2, coll2.IndexOf (tp2), "#7");
179 Assert.AreEqual (0, coll2.IndexOf (tp3), "#8");
183 [ExpectedException (typeof (ArgumentNullException))]
184 public void AddRange_Null_Array ()
186 CodeTypeParameterCollection coll = new CodeTypeParameterCollection ();
187 coll.AddRange ((CodeTypeParameter[]) null);
191 [ExpectedException (typeof (ArgumentNullException))]
192 public void AddRange_Null_Collection ()
194 CodeTypeParameterCollection coll = new CodeTypeParameterCollection ();
195 coll.AddRange ((CodeTypeParameterCollection) null);
199 public void AddRange_Self ()
201 CodeTypeParameterCollection coll = new CodeTypeParameterCollection ();
202 coll.Add (new CodeTypeParameter ());
203 Assert.AreEqual (1, coll.Count, "#1");
204 coll.AddRange (coll);
205 Assert.AreEqual (2, coll.Count, "#2");
209 public void Remove ()
211 CodeTypeParameter ctp1 = new CodeTypeParameter ();
212 CodeTypeParameter ctp2 = new CodeTypeParameter ();
214 CodeTypeParameterCollection coll = new CodeTypeParameterCollection ();
217 Assert.AreEqual (2, coll.Count, "#1");
218 Assert.AreEqual (0, coll.IndexOf (ctp1), "#2");
219 Assert.AreEqual (1, coll.IndexOf (ctp2), "#3");
221 Assert.AreEqual (1, coll.Count, "#4");
222 Assert.AreEqual (-1, coll.IndexOf (ctp1), "#5");
223 Assert.AreEqual (0, coll.IndexOf (ctp2), "#6");
227 [ExpectedException (typeof (ArgumentException))]
228 public void Remove_NotInCollection ()
230 CodeTypeParameterCollection coll = new CodeTypeParameterCollection ();
231 coll.Remove (new CodeTypeParameter ());
235 [ExpectedException (typeof (ArgumentNullException))]
236 public void Remove_Null ()
238 CodeTypeParameterCollection coll = new CodeTypeParameterCollection ();
239 coll.Remove ((CodeTypeParameter) null);