Merge pull request #2396 from akoeplinger/flaky-osx-socket-test
[mono.git] / mcs / class / System / Test / System.CodeDom / CodeNamespaceImportCollectionTest.cs
1 //
2 // CodeNamespaceImportCollectionTest.cs 
3 //      - Unit tests for System.CodeDom.CodeNamespaceImportCollection
4 //
5 // Author:
6 //      Gert Driesen  <drieseng@users.sourceforge.net>
7 //
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 //
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:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
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.
28 //
29
30 using NUnit.Framework;
31
32 using System;
33 using System.Collections;
34 using System.CodeDom;
35
36 namespace MonoTests.System.CodeDom {
37         [TestFixture]
38         public class CodeNamespaceImportCollectionTest {
39                 [Test]
40                 public void Constructor0 ()
41                 {
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");
48                 }
49
50                 [Test]
51                 public void Add ()
52                 {
53                         CodeNamespaceImport ni1 = new CodeNamespaceImport ("A");
54                         CodeNamespaceImport ni2 = new CodeNamespaceImport ("B");
55                         CodeNamespaceImport ni3 = new CodeNamespaceImport ("b");
56                         CodeNamespaceImport ni4 = new CodeNamespaceImport ("B");
57
58                         CodeNamespaceImportCollection coll = new CodeNamespaceImportCollection ();
59                         coll.Add (ni1);
60                         Assert.AreEqual (1, coll.Count, "#1");
61                         Assert.AreEqual (0, ((IList) coll).IndexOf (ni1), "#2");
62
63                         coll.Add (ni2);
64                         Assert.AreEqual (2, coll.Count, "#3");
65                         Assert.AreEqual (1, ((IList) coll).IndexOf (ni2), "#4");
66
67                         coll.Add (ni3);
68                         Assert.AreEqual (2, coll.Count, "#5");
69                         Assert.AreEqual (-1, ((IList) coll).IndexOf (ni3), "#6");
70
71                         coll.Add (ni4);
72                         Assert.AreEqual (2, coll.Count, "#7");
73                         Assert.AreEqual (-1, ((IList) coll).IndexOf (ni4), "#8");
74                 }
75
76                 [Test]
77                 [ExpectedException (typeof (NullReferenceException))]
78                 public void Add_Null () {
79                         CodeNamespaceImportCollection coll = new CodeNamespaceImportCollection ();
80                         coll.Add ((CodeNamespaceImport) null);
81                 }
82
83                 [Test]
84                 public void AddRange ()
85                 {
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");
91
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");
97
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");
105                 }
106
107                 [Test]
108                 [ExpectedException (typeof (ArgumentNullException))]
109                 public void AddRange_Null_Array ()
110                 {
111                         CodeNamespaceImportCollection coll = new CodeNamespaceImportCollection ();
112                         coll.AddRange ((CodeNamespaceImport[]) null);
113                 }
114
115                 [Test]
116                 [ExpectedException (typeof (NullReferenceException))]
117                 public void AddRange_Null_Item()
118                 {
119                         CodeNamespaceImportCollection coll = new CodeNamespaceImportCollection();
120                         coll.AddRange(new CodeNamespaceImport[] { null });
121                 }
122         }
123 }