2 // CodeNamespaceImportCollectionTest.cs
3 // - Unit tests for System.CodeDom.CodeNamespaceImportCollection
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 CodeNamespaceImportCollectionTest {
40 public void Constructor0 ()
42 CodeNamespaceImportCollection coll = new CodeNamespaceImportCollection ();
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.IsNull (((ICollection) coll).SyncRoot, "#5");
53 CodeNamespaceImport ni1 = new CodeNamespaceImport ("A");
54 CodeNamespaceImport ni2 = new CodeNamespaceImport ("B");
55 CodeNamespaceImport ni3 = new CodeNamespaceImport ("b");
56 CodeNamespaceImport ni4 = new CodeNamespaceImport ("B");
58 CodeNamespaceImportCollection coll = new CodeNamespaceImportCollection ();
60 Assert.AreEqual (1, coll.Count, "#1");
61 Assert.AreEqual (0, ((IList) coll).IndexOf (ni1), "#2");
64 Assert.AreEqual (2, coll.Count, "#3");
65 Assert.AreEqual (1, ((IList) coll).IndexOf (ni2), "#4");
68 Assert.AreEqual (2, coll.Count, "#5");
69 Assert.AreEqual (-1, ((IList) coll).IndexOf (ni3), "#6");
72 Assert.AreEqual (2, coll.Count, "#7");
73 Assert.AreEqual (-1, ((IList) coll).IndexOf (ni4), "#8");
77 [ExpectedException (typeof (NullReferenceException))]
78 public void Add_Null () {
79 CodeNamespaceImportCollection coll = new CodeNamespaceImportCollection ();
80 coll.Add ((CodeNamespaceImport) null);
84 public void AddRange ()
86 CodeNamespaceImport ni1 = new CodeNamespaceImport ("A");
87 CodeNamespaceImport ni2 = new CodeNamespaceImport ("B");
88 CodeNamespaceImport ni3 = new CodeNamespaceImport ("b");
89 CodeNamespaceImport ni4 = new CodeNamespaceImport ("B");
90 CodeNamespaceImport ni5 = new CodeNamespaceImport ("C");
92 CodeNamespaceImportCollection coll = new CodeNamespaceImportCollection ();
93 coll.AddRange (new CodeNamespaceImport[] {ni1, ni2});
94 Assert.AreEqual (2, coll.Count, "#1");
95 Assert.AreEqual (0, ((IList) coll).IndexOf (ni1), "#2");
96 Assert.AreEqual (1, ((IList) coll).IndexOf (ni2), "#3");
98 coll.AddRange (new CodeNamespaceImport[] { ni3, ni4, ni5 });
99 Assert.AreEqual (3, coll.Count, "#4");
100 Assert.AreEqual (0, ((IList) coll).IndexOf (ni1), "#5");
101 Assert.AreEqual (1, ((IList) coll).IndexOf (ni2), "#6");
102 Assert.AreEqual (-1, ((IList) coll).IndexOf (ni3), "#7");
103 Assert.AreEqual (-1, ((IList) coll).IndexOf (ni4), "#8");
104 Assert.AreEqual (2, ((IList) coll).IndexOf (ni5), "#9");
108 [ExpectedException (typeof (ArgumentNullException))]
109 public void AddRange_Null_Array ()
111 CodeNamespaceImportCollection coll = new CodeNamespaceImportCollection ();
112 coll.AddRange ((CodeNamespaceImport[]) null);
116 [ExpectedException (typeof (NullReferenceException))]
117 public void AddRange_Null_Item()
119 CodeNamespaceImportCollection coll = new CodeNamespaceImportCollection();
120 coll.AddRange(new CodeNamespaceImport[] { null });