2005-11-30 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / class / System / Test / System.Collections.Specialized / ListDictionaryTest.cs
1 //
2 // ListDictionaryTest.cs
3 //      - NUnit Test Cases for System.Collections.Specialized.ListDictionary.cs
4 //
5 // Authors:
6 //   Duncan Mak (duncan@ximian.com)
7 //   Alon Gazit (along@mainsoft.com)
8 //   Sebastien Pouliot  <sebastien@ximian.com>
9 //
10 // Copyright (C) 2003 Ximian Inc.
11 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
12 //
13
14 using NUnit.Framework;
15 using System;
16 using System.Collections;
17 using System.Collections.Specialized;
18
19 namespace MonoTests.System.Collections.Specialized {
20
21         [TestFixture]
22         public class ListDictionaryTest {
23
24                 private void BasicTests (ListDictionary ld)
25                 {
26                         Assert.AreEqual (0, ld.Count, "Count");
27                         Assert.IsFalse (ld.IsFixedSize, "IsFixedSize");
28                         Assert.IsFalse (ld.IsReadOnly, "IsReadOnly");
29                         Assert.IsFalse (ld.IsSynchronized, "IsSynchronized");
30                         Assert.AreEqual (0, ld.Keys.Count, "Keys");
31                         Assert.AreEqual (0, ld.Values.Count, "Values");
32                         Assert.IsNotNull (ld.SyncRoot, "SyncRoot");
33                         Assert.IsNotNull (ld.GetEnumerator (), "GetEnumerator");
34                         Assert.IsNotNull ((ld as IEnumerable).GetEnumerator (), "IEnumerable.GetEnumerator");
35
36                         ld.Add ("a", "1");
37                         Assert.AreEqual (1, ld.Count, "Count-1");
38                         Assert.IsTrue (ld.Contains ("a"), "Contains(a)");
39                         Assert.IsFalse (ld.Contains ("1"), "Contains(1)");
40
41                         ld.Add ("b", null);
42                         Assert.AreEqual (2, ld.Count, "Count-2");
43                         Assert.IsNull (ld["b"], "this[b]");
44
45                         DictionaryEntry[] entries = new DictionaryEntry[2];
46                         ld.CopyTo (entries, 0);
47
48                         ld["b"] = "2";
49                         Assert.AreEqual ("2", ld["b"], "this[b]2");
50
51                         ld.Remove ("b");
52                         Assert.AreEqual (1, ld.Count, "Count-3");
53                         ld.Clear ();
54                         Assert.AreEqual (0, ld.Count, "Count-4");
55                 }
56
57                 [Test]
58                 public void Constructor_Default ()
59                 {
60                         ListDictionary ld = new ListDictionary ();
61                         BasicTests (ld);
62                 }
63
64                 [Test]
65                 public void Constructor_IComparer_Null ()
66                 {
67                         ListDictionary ld = new ListDictionary (null);
68                         BasicTests (ld);
69                 }
70
71                 [Test]
72                 public void Constructor_IComparer ()
73                 {
74                         ListDictionary ld = new ListDictionary (new CaseInsensitiveComparer ());
75                         BasicTests (ld);
76                 }
77
78                 [Test, ExpectedException (typeof (ArgumentNullException))]
79                 public void CopyTo1 ()
80                 {
81                         ListDictionary ld = new ListDictionary ();
82                         ld.CopyTo (null, 0);
83                 }
84
85                 [Test, ExpectedException (typeof (ArgumentOutOfRangeException))]
86                 public void CopyTo2 ()
87                 {
88                         ListDictionary ld = new ListDictionary ();
89                         ld.CopyTo (new int[1],-1);       
90                 }
91
92                 [Test, ExpectedException (typeof (ArgumentNullException))]
93                 public void Remove ()
94                 {
95                         ListDictionary ld = new ListDictionary ();
96                         ld.Remove (null);
97                 }
98         }
99 }