2 // X509ExtensionCollectionTest.cs - NUnit tests for X509ExtensionCollection
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using NUnit.Framework;
34 using System.Collections;
35 using System.Security.Cryptography;
36 using System.Security.Cryptography.X509Certificates;
39 namespace MonoTests.System.Security.Cryptography.X509Certificates {
42 public class X509ExtensionCollectionTest {
44 private X509ExtensionCollection empty;
45 private X509Extension extn_empty;
48 public void FixtureSetUp ()
50 empty = new X509ExtensionCollection ();
51 extn_empty = new X509Extension ("1.2", new byte[] { 0x05, 0x00 }, false);
55 public void Defaults ()
57 Assert.AreEqual (0, empty.Count, "Count");
58 Assert.IsFalse (empty.IsSynchronized, "IsSynchronized");
59 Assert.IsTrue (Object.ReferenceEquals (empty, empty.SyncRoot), "SyncRoot");
60 Assert.AreEqual (typeof (X509ExtensionEnumerator), empty.GetEnumerator ().GetType (), "GetEnumerator");
62 IEnumerable e = (empty as IEnumerable);
63 Assert.AreEqual (typeof (X509ExtensionEnumerator), e.GetEnumerator ().GetType (), "IEnumerable.GetEnumerator");
67 [ExpectedException (typeof (InvalidOperationException))]
68 public void Indexer_Int_Negative ()
70 Assert.IsNotNull (empty [-1]);
74 [ExpectedException (typeof (ArgumentOutOfRangeException))]
75 public void Indexer_Int_OutOfRange ()
77 Assert.IsNotNull (empty [0]);
81 public void Indexer_Int ()
83 X509ExtensionCollection c = new X509ExtensionCollection ();
85 Assert.AreEqual (extn_empty, c[0], "0");
89 [ExpectedException (typeof (ArgumentNullException))]
90 public void Indexer_String_Null ()
92 Assert.IsNotNull (empty [null]);
96 public void Indexer_String ()
98 X509ExtensionCollection c = new X509ExtensionCollection ();
100 Assert.IsNull (c[String.Empty]);
101 Assert.IsNull (c ["1.2.3"]);
102 Assert.AreEqual (extn_empty, c["1.2"], "0");
106 [ExpectedException (typeof (ArgumentNullException))]
107 public void Add_Null ()
115 X509ExtensionCollection c = new X509ExtensionCollection ();
116 Assert.AreEqual (0, c.Count, "Count-0");
118 Assert.AreEqual (1, c.Count, "Count-1");
122 [ExpectedException (typeof (ArgumentNullException))]
123 public void CopyTo_Null ()
125 empty.CopyTo (null, 0);
129 [ExpectedException (typeof (ArgumentOutOfRangeException))]
130 public void CopyTo_Negative ()
132 X509Extension[] array = new X509Extension[1];
133 empty.CopyTo (array, -1);
137 [ExpectedException (typeof (ArgumentOutOfRangeException))]
138 public void CopyTo_EmptyArray ()
140 X509Extension[] array = new X509Extension[0];
141 empty.CopyTo (array, 0);
145 public void CopyTo_EmptyCollection ()
147 X509Extension[] array = new X509Extension[1];
148 empty.CopyTo (array, 0);
152 public void CopyTo ()
154 X509ExtensionCollection c = new X509ExtensionCollection ();
156 X509Extension[] array = new X509Extension[1];
158 Assert.AreEqual (extn_empty, array[0], "0");
162 [ExpectedException (typeof (ArgumentNullException))]
163 public void ICollection_CopyTo_Null ()
165 (empty as ICollection).CopyTo (null, 0);
169 [ExpectedException (typeof (ArgumentOutOfRangeException))]
170 public void ICollection_CopyTo_Negative ()
172 X509Extension[] array = new X509Extension[1];
173 (empty as ICollection).CopyTo (array, -1);
177 [ExpectedException (typeof (ArgumentOutOfRangeException))]
178 public void ICollection_CopyTo_EmptyArray ()
180 X509Extension[] array = new X509Extension[0];
181 (empty as ICollection).CopyTo (array, 0);
185 public void ICollection_CopyTo_EmptyCollection ()
187 X509Extension[] array = new X509Extension[1];
188 (empty as ICollection).CopyTo (array, 0);
192 public void ICollection_CopyTo ()
194 X509ExtensionCollection c = new X509ExtensionCollection ();
196 X509Extension[] array = new X509Extension[1];
197 (c as ICollection).CopyTo (array, 0);
198 Assert.AreEqual (extn_empty, array[0], "0");