In System.Collections.Generic:
[mono.git] / mcs / class / corlib / Test / System.Collections.Generic / DictionaryTest.cs
1 //
2 // MonoTests.System.Collections.Generic.DictionaryTest
3 //
4 // Authors:
5 //      Sureshkumar T (tsureshkumar@novell.com)
6 //      Ankit Jain (radical@corewars.org)
7 //      David Waite (mass@akuma.org)
8 //
9 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
10 // Copyright (C) 2005 David Waite (mass@akuma.org)
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32 #if NET_2_0
33
34 using System;
35 using System.Collections;
36 using System.Collections.Generic;
37 using System.IO;
38 using System.Runtime.Serialization.Formatters.Binary;
39 using System.Text;
40 using System.Threading;
41
42 using NUnit.Framework;
43
44 namespace MonoTests.System.Collections.Generic {
45         [TestFixture]
46         public class DictionaryTest {
47                 class MyClass {
48                         int a;
49                         int b;
50                         public MyClass (int a, int b)
51                         {
52                                 this.a = a;
53                                 this.b = b;
54                         }
55                         public override int GetHashCode ()
56                         {
57                                 return a + b;
58                         }
59         
60                         public override bool Equals (object obj)
61                         {
62                                 if (!(obj is MyClass))
63                                         return false;
64                                 return ((MyClass)obj).Value == a;
65                         }
66         
67         
68                         public int Value {
69                                 get { return a; }
70                         }
71         
72                 }
73         
74                 Dictionary <string, object> _dictionary = null;
75                 Dictionary <MyClass, MyClass> _dictionary2 = null;
76                 Dictionary <int, int> _dictionary3 = null;
77         
78                 [SetUp]
79                 public void SetUp ()
80                 {
81                         _dictionary = new Dictionary <string, object> ();
82                         _dictionary2 = new Dictionary <MyClass, MyClass> ();
83                         _dictionary3 = new Dictionary <int, int>();
84                 }
85         
86                 [Test]
87                 public void AddTest ()
88                 {
89                         _dictionary.Add ("key1", "value");
90                         Assert.AreEqual ("value", _dictionary ["key1"].ToString (), "Add failed!");
91                 }
92         
93                 [Test]
94                 public void AddTest2 ()
95                 {
96                         MyClass m1 = new MyClass (10,5);
97                         MyClass m2 = new MyClass (20,5);
98                         MyClass m3 = new MyClass (12,3);
99                         _dictionary2.Add (m1,m1);
100                         _dictionary2.Add (m2, m2);
101                         _dictionary2.Add (m3, m3);
102                         Assert.AreEqual (20, _dictionary2 [m2].Value, "#1");
103                         Assert.AreEqual (10, _dictionary2 [m1].Value, "#2");
104                         Assert.AreEqual (12, _dictionary2 [m3].Value, "#3");
105                 }
106
107                 [Test]
108                 public void AddTest3 ()
109                 {
110                         _dictionary3.Add (1, 2);
111                         _dictionary3.Add (2, 3);
112                         _dictionary3.Add (3, 4);
113                         Assert.AreEqual (2, _dictionary3[1], "#1");
114                         Assert.AreEqual (3, _dictionary3[2], "#2");
115                         Assert.AreEqual (4, _dictionary3[3], "#3");
116                 }
117
118                 [Test, ExpectedException(typeof(ArgumentNullException))]
119                 public void AddNullTest ()
120                 {
121                         _dictionary.Add (null, "");
122                 }
123         
124                 [Test, ExpectedException(typeof(ArgumentException))]
125                 public void AddDuplicateTest ()
126                 {
127                         _dictionary.Add("foo", "bar");
128                         _dictionary.Add("foo", "bar");
129                 }
130
131                 //Tests Add when resize takes place
132                 [Test]
133                 public void AddLargeTest ()
134                 {
135                         int i, numElems = 50;
136         
137                         for (i = 0; i < numElems; i++)
138                         {
139                                 _dictionary3.Add (i, i);
140                         }
141         
142                         i = 0;
143                         foreach (KeyValuePair <int, int> entry in _dictionary3)
144                         {
145                                 i++;
146                         }
147         
148                         Assert.AreEqual (i, numElems, "Add with resize failed!");
149                 }
150         
151                 [Test]
152                 public void IndexerGetExistingTest ()
153                 {
154                         _dictionary.Add ("key1", "value");
155                         Assert.AreEqual ("value", _dictionary ["key1"].ToString (), "Add failed!");
156                 }
157                 
158                 [Test, ExpectedException(typeof(KeyNotFoundException))]
159                 public void IndexerGetNonExistingTest ()
160                 {
161                         object foo = _dictionary ["foo"];
162                 }
163
164                 [Test, ExpectedException(typeof(ArgumentNullException))]
165                 public void IndexerGetNullTest()
166                 {
167                         object s = _dictionary[null];
168                 }
169
170                 [Test]
171                 public void IndexerSetExistingTest ()
172                 {
173                         _dictionary.Add ("key1", "value1");
174                         _dictionary ["key1"] =  "value2";
175                         Assert.AreEqual (1, _dictionary.Count);
176                         Assert.AreEqual ("value2", _dictionary ["key1"]);
177                 }
178
179                 [Test]
180                 public void IndexerSetNonExistingTest ()
181                 {
182                         _dictionary ["key1"] =  "value1";
183                         Assert.AreEqual (1, _dictionary.Count);
184                         Assert.AreEqual ("value1", _dictionary ["key1"]);
185                 }
186         
187                 [Test]
188                 public void RemoveTest ()
189                 {
190                         _dictionary.Add ("key1", "value1");
191                         _dictionary.Add ("key2", "value2");
192                         _dictionary.Add ("key3", "value3");
193                         _dictionary.Add ("key4", "value4");
194                         Assert.IsTrue (_dictionary.Remove ("key3"));
195                         Assert.IsFalse (_dictionary.Remove ("foo"));
196                         Assert.AreEqual (3, _dictionary.Count);
197                         Assert.IsFalse (_dictionary.ContainsKey ("key3"));
198                 }
199         
200                 [Test]
201                 public void RemoveTest2 ()
202                 {
203                         MyClass m1 = new MyClass (10, 5);
204                         MyClass m2 = new MyClass (20, 5);
205                         MyClass m3 = new MyClass (12, 3);
206                         _dictionary2.Add (m1, m1);
207                         _dictionary2.Add (m2, m2);
208                         _dictionary2.Add (m3, m3);
209                         _dictionary2.Remove (m1); // m2 is in rehash path
210                         Assert.AreEqual (20, _dictionary2 [m2].Value, "#4");
211                         
212                 }
213
214                 [Test]
215                 [Category ("NotWorking")]
216                 public void Remove_ZeroOut ()
217                 {
218                         object key = new object ();
219                         object value = new object ();
220
221                         WeakReference wrKey = new WeakReference (key);
222                         WeakReference wrValue = new WeakReference (value);
223
224                         Dictionary <object, object> dictionary = new Dictionary <object, object> ();
225                         dictionary.Add (key, value);
226                         dictionary.Remove (key);
227
228                         key = null;
229                         value = null;
230                         GC.Collect ();
231                         Thread.Sleep (200);
232
233                         Assert.IsNull (wrKey.Target, "#1");
234                         Assert.IsNull (wrValue.Target, "#2");
235                 }
236         
237                 [Test, ExpectedException(typeof(ArgumentNullException))]
238                 public void IndexerSetNullTest()
239                 {
240                         _dictionary[null] = "bar";
241                 }
242         
243                 [Test]
244                 public void ClearTest ()
245                 {
246                         _dictionary.Add ("key1", "value1");
247                         _dictionary.Add ("key2", "value2");
248                         _dictionary.Add ("key3", "value3");
249                         _dictionary.Add ("key4", "value4");
250                         _dictionary.Clear ();
251                         Assert.AreEqual (0, _dictionary.Count, "Clear method failed!");
252                         Assert.IsFalse (_dictionary.ContainsKey ("key2"));
253                 }
254         
255                 [Test] // bug 432441
256                 public void Clear_Iterators ()
257                 {
258                         Dictionary<object, object> d = new Dictionary <object, object> ();
259
260                         d [new object ()] = new object ();
261                         d.Clear ();
262                         int hash = 0;
263                         foreach (object o in d) {
264                                 hash += o.GetHashCode ();
265                         }
266                 }
267
268                 [Test]
269                 [Category ("NotWorking")]
270                 public void Clear_ZeroOut ()
271                 {
272                         object key = new object ();
273                         object value = new object ();
274
275                         WeakReference wrKey = new WeakReference (key);
276                         WeakReference wrValue = new WeakReference (value);
277
278                         Dictionary <object, object> dictionary = new Dictionary <object, object> ();
279                         dictionary.Add (key, value);
280                         dictionary.Clear ();
281
282                         key = null;
283                         value = null;
284                         GC.Collect ();
285                         Thread.Sleep (200);
286
287                         Assert.IsNull (wrKey.Target, "#1");
288                         Assert.IsNull (wrValue.Target, "#2");
289                 }
290
291                 [Test]
292                 public void ContainsKeyTest ()
293                 {
294                         _dictionary.Add ("key1", "value1");
295                         _dictionary.Add ("key2", "value2");
296                         _dictionary.Add ("key3", "value3");
297                         _dictionary.Add ("key4", "value4");
298                         bool contains = _dictionary.ContainsKey ("key4");
299                         Assert.IsTrue (contains, "ContainsKey does not return correct value!");
300                         contains = _dictionary.ContainsKey ("key5");
301                         Assert.IsFalse (contains, "ContainsKey for non existant does not return correct value!");
302                 }
303
304                 [Test, ExpectedException (typeof (ArgumentNullException))]
305                 public void ContainsKeyTest2 ()
306                 {
307                         _dictionary.ContainsKey (null);
308                 }
309         
310                 [Test]
311                 public void ContainsValueTest ()
312                 {
313                         _dictionary.Add ("key1", "value1");
314                         _dictionary.Add ("key2", "value2");
315                         _dictionary.Add ("key3", "value3");
316                         _dictionary.Add ("key4", "value4");
317                         bool contains = _dictionary.ContainsValue ("value2");
318                         Assert.IsTrue(contains, "ContainsValue does not return correct value!");
319                         contains = _dictionary.ContainsValue ("@@daisofja@@");
320                         Assert.IsFalse (contains, "ContainsValue for non existant does not return correct value!");
321                 }
322         
323                 [Test]
324                 public void TryGetValueTest()
325                 {
326                         _dictionary.Add ("key1", "value1");
327                         _dictionary.Add ("key2", "value2");
328                         _dictionary.Add ("key3", "value3");
329                         _dictionary.Add ("key4", "value4");
330                         object value = "";
331                         bool retrieved = _dictionary.TryGetValue ("key4", out value);
332                         Assert.IsTrue (retrieved);
333                         Assert.AreEqual ("value4", (string)value, "TryGetValue does not return value!");
334         
335                         retrieved = _dictionary.TryGetValue ("key7", out value);
336                         Assert.IsFalse (retrieved);
337                         Assert.IsNull (value, "value for non existant value should be null!");
338                 }
339         
340                 [Test]
341                 public void ValueTypeTest ()
342                 {
343                         Dictionary <int, float> dict = new Dictionary <int, float> ();
344                         dict.Add (10, 10.3f);
345                         dict.Add (11, 10.4f);
346                         dict.Add (12, 10.5f);
347                         Assert.AreEqual (10.4f, dict [11], "#5");
348                 }
349         
350                 private class MyTest
351                 {
352                         public string Name;
353                         public int RollNo;
354         
355                         public MyTest (string name, int number)
356                         {
357                                 Name = name;
358                                 RollNo = number;
359                         }
360
361                         public override int GetHashCode ()
362                         {
363                                 return Name.GetHashCode () ^ RollNo;
364                         }
365
366                         public override bool Equals (object obj)
367                         {
368                                 MyTest myt = obj as MyTest;
369                                 return myt.Name.Equals (this.Name) &&
370                                                 myt.RollNo.Equals (this.RollNo);
371                         }
372                 }
373         
374                 [Test]
375                 public void ObjectAsKeyTest ()
376                 {
377                         Dictionary <object, object> dict = new Dictionary <object, object> ();
378                         MyTest key1, key2, key3;
379                         dict.Add ( (key1 = new MyTest ("key1", 234)), "value1");
380                         dict.Add ( (key2 = new MyTest ("key2", 444)), "value2");
381                         dict.Add ( (key3 = new MyTest ("key3", 5655)), "value3");
382         
383                         Assert.AreEqual ("value2", dict [key2], "value is not returned!");
384                         Assert.AreEqual ("value3", dict [key3], "neg: exception should not be thrown!");
385                 }
386         
387                 [Test, ExpectedException (typeof (ArgumentException))]
388                 public void IDictionaryAddTest ()
389                 {
390                         IDictionary iDict = _dictionary as IDictionary;
391                         iDict.Add ("key1", "value1");
392                         iDict.Add ("key2", "value3");
393                         Assert.AreEqual (2, iDict.Count, "IDictioanry interface add is not working!");
394         
395                         //Negative test case
396                         iDict.Add (12, "value");
397                         iDict.Add ("key", 34);
398                 }
399         
400                 [Test]
401                 public void IEnumeratorTest ()
402                 {
403                         _dictionary.Add ("key1", "value1");
404                         _dictionary.Add ("key2", "value2");
405                         _dictionary.Add ("key3", "value3");
406                         _dictionary.Add ("key4", "value4");
407                         IEnumerator itr = ((IEnumerable)_dictionary).GetEnumerator ();
408                         while (itr.MoveNext ()) {
409                                 object o = itr.Current;
410                                 Assert.AreEqual (typeof (KeyValuePair<string,object>), o.GetType (), "Current should return a type of KeyValuePair");
411                                 KeyValuePair<string,object> entry = (KeyValuePair<string,object>) itr.Current;
412                         }
413                         Assert.AreEqual ("value4", _dictionary ["key4"].ToString (), "");
414                 }
415         
416         
417                 [Test]
418                 public void IEnumeratorGenericTest ()
419                 {
420                         _dictionary.Add ("key1", "value1");
421                         _dictionary.Add ("key2", "value2");
422                         _dictionary.Add ("key3", "value3");
423                         _dictionary.Add ("key4", "value4");
424                         IEnumerator <KeyValuePair <string, object>> itr = ((IEnumerable <KeyValuePair <string, object>>)_dictionary).GetEnumerator ();
425                         while (itr.MoveNext ()) {
426                                 object o = itr.Current;
427                                 Assert.AreEqual (typeof (KeyValuePair <string, object>), o.GetType (), "Current should return a type of KeyValuePair<object,string>");
428                                 KeyValuePair <string, object> entry = (KeyValuePair <string, object>)itr.Current;
429                         }
430                         Assert.AreEqual ("value4", _dictionary ["key4"].ToString (), "");
431                 }
432         
433                 [Test]
434                 public void IDictionaryEnumeratorTest ()
435                 {
436                         _dictionary.Add ("key1", "value1");
437                         _dictionary.Add ("key2", "value2");
438                         _dictionary.Add ("key3", "value3");
439                         _dictionary.Add ("key4", "value4");
440                         IDictionaryEnumerator itr = ((IDictionary)_dictionary).GetEnumerator ();
441                         while (itr.MoveNext ()) {
442                                 object o = itr.Current;
443                                 Assert.AreEqual (typeof (DictionaryEntry), o.GetType (), "Current should return a type of DictionaryEntry");
444                                 DictionaryEntry entry = (DictionaryEntry) itr.Current;
445                         }
446                         Assert.AreEqual ("value4", _dictionary ["key4"].ToString (), "");
447                 }
448         
449                 [Test]
450                 public void ForEachTest ()
451                 {
452                         _dictionary.Add ("key1", "value1");
453                         _dictionary.Add ("key2", "value2");
454                         _dictionary.Add ("key3", "value3");
455                         _dictionary.Add ("key4", "value4");
456         
457                         int i = 0;
458                         foreach (KeyValuePair <string, object> entry in _dictionary)
459                                 i++;
460                         Assert.AreEqual(4, i, "fail1: foreach entry failed!");
461         
462                         i = 0;
463                         foreach (KeyValuePair <string, object> entry in ((IEnumerable)_dictionary))
464                                 i++;
465                         Assert.AreEqual(4, i, "fail2: foreach entry failed!");
466         
467                         i = 0;
468                         foreach (DictionaryEntry entry in ((IDictionary)_dictionary))
469                                 i++;
470                         Assert.AreEqual (4, i, "fail3: foreach entry failed!");
471                 }
472         
473                 [Test]
474                 public void ResizeTest ()
475                 {
476                         Dictionary <string, object> dictionary = new Dictionary <string, object> (3);
477                         dictionary.Add ("key1", "value1");
478                         dictionary.Add ("key2", "value2");
479                         dictionary.Add ("key3", "value3");
480         
481                         Assert.AreEqual (3, dictionary.Count);
482         
483                         dictionary.Add ("key4", "value4");
484                         Assert.AreEqual (4, dictionary.Count);
485                         Assert.AreEqual ("value1", dictionary ["key1"].ToString (), "");
486                         Assert.AreEqual ("value2", dictionary ["key2"].ToString (), "");
487                         Assert.AreEqual ("value4", dictionary ["key4"].ToString (), "");
488                         Assert.AreEqual ("value3", dictionary ["key3"].ToString (), "");
489                 }
490         
491                 [Test]
492                 public void KeyCollectionTest ()
493                 {
494                         _dictionary.Add ("key1", "value1");
495                         _dictionary.Add ("key2", "value2");
496                         _dictionary.Add ("key3", "value3");
497                         _dictionary.Add ("key4", "value4");
498         
499                         ICollection <string> keys = ((IDictionary <string, object>)_dictionary).Keys;
500                         Assert.AreEqual (4, keys.Count);
501                         int i = 0;
502                         foreach (string key in keys)
503                         {
504                                 i++;
505                         }
506                         Assert.AreEqual(4, i);
507                 }
508
509                 [Test]
510                 public void KeyValueEnumeratorTest ()
511                 {
512                         IDictionary<int, int> d = new Dictionary<int, int>();
513
514                         // Values are chosen such that two keys map to the same bucket.
515                         // Default dictionary table size == 10
516                         d [9] = 1;
517                         d [10] = 2;
518                         d [19] = 3;
519
520                         Assert.AreEqual (d.Count, d.Keys.Count, "d and d.Keys don't appear to match");
521                         Assert.AreEqual (d.Values.Count, d.Keys.Count, "d.Keys and d.Values don't appear to match");
522
523                         int count = 0;
524                         foreach (int i in d.Values)
525                                 ++count;
526                         Assert.AreEqual (count, d.Values.Count, "d.Values doesn't have the correct number of elements");
527         
528                         count = 0;
529                         foreach (int i in d.Keys)
530                                 ++count;
531                         Assert.AreEqual (count, d.Keys.Count, "d.Keys doesn't have the correct number of elements");
532
533                         int nkeys = count;
534                         count = 0;
535                         foreach (int i in d.Keys) {
536                                 int foo = d [i];
537                                 if (count++ >= nkeys)
538                                         Assert.Fail ("Reading a value appears to trash enumerator state");
539                         }
540                 }
541
542                 [Test] // bug 75073
543                 public void SliceCollectionsEnumeratorTest ()
544                 {
545                         Dictionary<string, int> values = new Dictionary<string, int> ();
546
547                         IEnumerator <string> ke = values.Keys.GetEnumerator ();
548                         IEnumerator <int>    ve = values.Values.GetEnumerator ();
549
550                         Assert.IsTrue (ke is Dictionary<string, int>.KeyCollection.Enumerator);
551                         Assert.IsTrue (ve is Dictionary<string, int>.ValueCollection.Enumerator);
552                 }
553
554                 [Test]
555                 public void PlainEnumeratorReturnTest ()
556                 {
557                         // Test that we return a KeyValuePair even for non-generic dictionary iteration
558                         _dictionary["foo"] = "bar";
559                         IEnumerator<KeyValuePair<string, object>> enumerator = _dictionary.GetEnumerator();
560                         Assert.IsTrue(enumerator.MoveNext(), "#1");
561                         Assert.AreEqual (typeof (KeyValuePair<string,object>), ((IEnumerator)enumerator).Current.GetType (), "#2");
562                         Assert.AreEqual (typeof (DictionaryEntry), ((IDictionaryEnumerator)enumerator).Entry.GetType (), "#3");
563                         Assert.AreEqual (typeof (KeyValuePair<string,object>), ((IDictionaryEnumerator)enumerator).Current.GetType (), "#4");
564                         Assert.AreEqual (typeof (KeyValuePair<string,object>), ((object) enumerator.Current).GetType (), "#5");
565                 }
566
567                 [Test, ExpectedException (typeof (InvalidOperationException))]
568                 public void FailFastTest1 ()
569                 {
570                         Dictionary<int, int> d = new Dictionary<int, int> ();
571                         d [1] = 1;
572                         int count = 0;
573                         foreach (KeyValuePair<int, int> kv in d) {
574                                 d [kv.Key + 1] = kv.Value + 1;
575                                 if (count++ != 0)
576                                         Assert.Fail ("Should not be reached");
577                         }
578                         Assert.Fail ("Should not be reached");
579                 }
580
581                 [Test, ExpectedException (typeof (InvalidOperationException))]
582                 public void FailFastTest2 ()
583                 {
584                         Dictionary<int, int> d = new Dictionary<int, int> ();
585                         d [1] = 1;
586                         int count = 0;
587                         foreach (int i in d.Keys) {
588                                 d [i + 1] = i + 1;
589                                 if (count++ != 0)
590                                         Assert.Fail ("Should not be reached");
591                         }
592                         Assert.Fail ("Should not be reached");
593                 }
594
595                 [Test, ExpectedException (typeof (InvalidOperationException))]
596                 public void FailFastTest3 ()
597                 {
598                         Dictionary<int, int> d = new Dictionary<int, int> ();
599                         d [1] = 1;
600                         int count = 0;
601                         foreach (int i in d.Keys) {
602                                 d [i] = i;
603                                 if (count++ != 0)
604                                         Assert.Fail ("Should not be reached");
605                         }
606                         Assert.Fail ("Should not be reached");
607                 }
608
609                 [Test]
610                 [Category ("TargetJvmNotWorking")] // BUGBUG Very very slow on TARGET_JVM.
611                 public void SerializationTest()
612                 {
613                         for (int i = 0; i < 50; i++)
614                         {
615                                 _dictionary3.Add(i, i);
616                         }
617
618                         BinaryFormatter formatter = new BinaryFormatter();
619                         MemoryStream stream = new MemoryStream();
620                         formatter.Serialize(stream, _dictionary3);
621
622                         stream.Position = 0;
623                         object deserialized = formatter.Deserialize(stream);
624
625                         Assert.IsNotNull(deserialized);
626                         Assert.IsFalse(deserialized == _dictionary3);
627
628                         Assert.IsTrue(deserialized is Dictionary<int, int>);
629                         Dictionary<int, int> d3 = deserialized as Dictionary<int, int>;
630
631                         Assert.AreEqual(50, d3.Count);
632                         for (int i = 0; i < 50; i++)
633                         {
634                                 Assert.AreEqual(i, d3[i]);
635                         }
636                 }
637
638                 [Test]
639                 public void ZeroCapacity ()
640                 {
641                         Dictionary<int, int> x = new Dictionary <int, int> (0);
642                         x.Add (1, 2);
643                         
644                         x = new Dictionary <int, int> (0);
645                         x.Clear ();
646
647                         x = new Dictionary <int, int> (0);
648                         int aa = x.Count;
649                         
650                         x = new Dictionary <int, int> (0);
651                         try {
652                                 int j = x [1];
653                         } catch (KeyNotFoundException){
654                         }
655
656                         bool b;
657                         b = x.ContainsKey (10);
658                         b = x.ContainsValue (10);
659
660                         x = new Dictionary <int, int> (0);
661                         x.Remove (10);
662                         
663                         x = new Dictionary <int, int> (0);
664                         int intv;
665                         x.TryGetValue (1, out intv);
666
667                         object oa = x.Keys;
668                         object ob = x.Values;
669                         foreach (KeyValuePair<int,int> a in x){
670                         }
671                 }
672
673                 [Test]
674                 public void Empty_KeysValues_CopyTo ()
675                 {
676                         Dictionary<int, int> d = new Dictionary<int, int> ();
677                         int[] array = new int[1];
678                         d.Keys.CopyTo (array, array.Length);
679                         d.Values.CopyTo (array, array.Length);
680                 }
681
682                 [Test]
683                 public void Empty_CopyTo ()
684                 {
685                         Dictionary<int, int> d = new Dictionary<int, int> ();
686                         ICollection c = (ICollection) d;
687                         DictionaryEntry [] array = new DictionaryEntry [1];
688                         c.CopyTo (array, array.Length);
689
690                         ICollection<KeyValuePair<int,int>> c2 = d;
691                         KeyValuePair<int,int> [] array2 = new KeyValuePair<int,int> [1];
692                         c2.CopyTo (array2, array2.Length);
693                 }
694
695                 [Test]
696                 public void IDictionary_Contains ()
697                 {
698                         IDictionary d = new Dictionary<int, int> ();
699                         d.Add (1, 2);
700                         Assert.IsTrue (d.Contains (1));
701                         Assert.IsFalse (d.Contains (2));
702                         Assert.IsFalse (d.Contains ("x"));
703                 }
704
705                 [Test, ExpectedException (typeof (ArgumentNullException))]
706                 public void IDictionary_Contains2 ()
707                 {
708                         IDictionary d = new Dictionary<int, int> ();
709                         d.Contains (null);
710                 }
711
712                 [Test, ExpectedException (typeof (ArgumentNullException))]
713                 public void IDictionary_Add1 ()
714                 {
715                         IDictionary d = new Dictionary<int, int> ();
716                         d.Add (null, 1);
717                 }
718
719                 [Test, ExpectedException (typeof (ArgumentException))]
720                 public void IDictionary_Add2 ()
721                 {
722                         IDictionary d = new Dictionary<int, int> ();
723                         d.Add ("bar", 1);
724                 }
725
726                 [Test, ExpectedException (typeof (ArgumentException))]
727                 public void IDictionary_Add3 ()
728                 {
729                         IDictionary d = new Dictionary<int, int> ();
730                         d.Add (1, "bar");
731                 }
732
733                 [Test]
734                 public void IDictionary_Add_Null ()
735                 {
736                         IDictionary d = new Dictionary<int, string> ();
737                         d.Add (1, null);
738                         d [2] = null;
739
740                         Assert.IsNull (d [1]);
741                         Assert.IsNull (d [2]);
742                 }
743
744                 [Test]
745                 [ExpectedException (typeof (ArgumentException))]
746                 public void IDictionary_Add_Null_2 ()
747                 {
748                         IDictionary d = new Dictionary<int, int> ();
749                         d.Add (1, null);
750                 }
751
752                 [Test]
753                 public void IDictionary_Remove1 ()
754                 {
755                         IDictionary d = new Dictionary<int, int> ();
756                         d.Add (1, 2);
757                         d.Remove (1);
758                         d.Remove (5);
759                         d.Remove ("foo");
760                 }
761
762                 [Test, ExpectedException (typeof (ArgumentNullException))]
763                 public void IDictionary_Remove2 ()
764                 {
765                         IDictionary d = new Dictionary<int, int> ();
766                         d.Remove (null);
767                 }
768                 
769                 [Test]
770                 public void IDictionary_IndexerGetNonExistingTest ()
771                 {
772                         IDictionary d = new Dictionary<int, int> ();
773                         d.Add(1, 2);
774                         Assert.IsNull(d[2]);
775                         Assert.IsNull(d["foo"]);
776                 }
777
778                 [Test] // bug #332534
779                 public void Dictionary_MoveNext ()
780                 {
781                         Dictionary<int,int> a = new Dictionary<int,int>();
782                         a.Add(3,1);
783                         a.Add(4,1);
784
785                         IEnumerator en = a.GetEnumerator();
786                         for (int i = 1; i < 10; i++)
787                                 en.MoveNext();
788                 }
789
790                 [Test]
791                 public void CopyToArray ()
792                 {
793                         Dictionary<string, string> test = new Dictionary<string, string> ();
794                         test.Add ("monkey", "singe");
795                         test.Add ("singe", "mono");
796                         test.Add ("mono", "monkey");
797                         Assert.AreEqual (3, test.Keys.Count, "Dictionary.Count");
798                         
799                         ArrayList list = new ArrayList (test.Keys);
800                         Assert.AreEqual (3, list.Count, "ArrayList.Count");
801                         Assert.IsTrue (list.Contains ("monkey"), "monkey");
802                         Assert.IsTrue (list.Contains ("singe"), "singe");
803                         Assert.IsTrue (list.Contains ("mono"), "mono");
804                 }
805
806                 [Test]
807                 public void KeyObjectMustNotGetChangedIfKeyAlreadyExists ()
808                 {
809                         Dictionary<String, int> d = new Dictionary<string, int> ();
810                         string s1 = "Test";
811                         string s2 = "Tes" + "T".ToLowerInvariant();
812                         d[s1] = 1;
813                         d[s2] = 2;
814                         string comp = String.Empty;
815                         foreach (String s in d.Keys)
816                                 comp = s;
817                         Assert.IsTrue (Object.ReferenceEquals (s1, comp));
818                 }
819
820                 [Test]
821                 public void ResetKeysEnumerator ()
822                 {
823                         Dictionary<string, string> test = new Dictionary<string, string> ();
824                         test.Add ("monkey", "singe");
825                         test.Add ("singe", "mono");
826                         test.Add ("mono", "monkey");
827
828                         IEnumerator enumerator = test.Keys.GetEnumerator ();
829
830                         Assert.IsTrue (enumerator.MoveNext ());
831                         Assert.IsTrue (enumerator.MoveNext ());
832
833                         enumerator.Reset ();
834
835                         Assert.IsTrue (enumerator.MoveNext ());
836                         Assert.IsTrue (enumerator.MoveNext ());
837                         Assert.IsTrue (enumerator.MoveNext ());
838                         Assert.IsFalse (enumerator.MoveNext ());
839                 }
840
841                 [Test]
842                 public void ResetValuesEnumerator ()
843                 {
844                         Dictionary<string, string> test = new Dictionary<string, string> ();
845                         test.Add ("monkey", "singe");
846                         test.Add ("singe", "mono");
847                         test.Add ("mono", "monkey");
848
849                         IEnumerator enumerator = test.Values.GetEnumerator ();
850
851                         Assert.IsTrue (enumerator.MoveNext ());
852                         Assert.IsTrue (enumerator.MoveNext ());
853
854                         enumerator.Reset ();
855
856                         Assert.IsTrue (enumerator.MoveNext ());
857                         Assert.IsTrue (enumerator.MoveNext ());
858                         Assert.IsTrue (enumerator.MoveNext ());
859                         Assert.IsFalse (enumerator.MoveNext ());
860                 }
861
862                 [Test]
863                 public void ResetShimEnumerator ()
864                 {
865                         IDictionary test = new Dictionary<string, string> ();
866                         test.Add ("monkey", "singe");
867                         test.Add ("singe", "mono");
868                         test.Add ("mono", "monkey");
869
870                         IEnumerator enumerator = test.GetEnumerator ();
871
872                         Assert.IsTrue (enumerator.MoveNext ());
873                         Assert.IsTrue (enumerator.MoveNext ());
874
875                         enumerator.Reset ();
876
877                         Assert.IsTrue (enumerator.MoveNext ());
878                         Assert.IsTrue (enumerator.MoveNext ());
879                         Assert.IsTrue (enumerator.MoveNext ());
880                         Assert.IsFalse (enumerator.MoveNext ());
881                 }
882
883                 [Test]
884                 public void ICollectionOfKeyValuePairContains ()
885                 {
886                         var dictionary = new Dictionary<string, int> ();
887                         dictionary.Add ("foo", 42);
888                         dictionary.Add ("bar", 12);
889
890                         var collection = dictionary as ICollection<KeyValuePair<string, int>>;
891
892                         Assert.AreEqual (2, collection.Count);
893
894                         Assert.IsFalse (collection.Contains (new KeyValuePair<string, int> ("baz", 13)));
895                         Assert.IsFalse (collection.Contains (new KeyValuePair<string, int> ("foo", 13)));
896                         Assert.IsTrue (collection.Contains (new KeyValuePair<string, int> ("foo", 42)));
897                 }
898
899                 [Test]
900                 public void ICollectionOfKeyValuePairRemove ()
901                 {
902                         var dictionary = new Dictionary<string, int> ();
903                         dictionary.Add ("foo", 42);
904                         dictionary.Add ("bar", 12);
905
906                         var collection = dictionary as ICollection<KeyValuePair<string, int>>;
907
908                         Assert.AreEqual (2, collection.Count);
909
910                         Assert.IsFalse (collection.Remove (new KeyValuePair<string, int> ("baz", 13)));
911                         Assert.IsFalse (collection.Remove (new KeyValuePair<string, int> ("foo", 13)));
912                         Assert.IsTrue (collection.Remove (new KeyValuePair<string, int> ("foo", 42)));
913
914                         Assert.AreEqual (12, dictionary ["bar"]);
915                         Assert.IsFalse (dictionary.ContainsKey ("foo"));
916                 }
917
918                 [Test]
919                 public void ICollectionCopyToKeyValuePairArray ()
920                 {
921                         var dictionary = new Dictionary<string, int> ();
922                         dictionary.Add ("foo", 42);
923
924                         var collection = dictionary as ICollection;
925
926                         Assert.AreEqual (1, collection.Count);
927
928                         var pairs = new KeyValuePair<string, int> [1];
929
930                         collection.CopyTo (pairs, 0);
931
932                         Assert.AreEqual ("foo", pairs [0].Key);
933                         Assert.AreEqual (42, pairs [0].Value);
934                 }
935
936                 [Test]
937                 public void ICollectionCopyToDictionaryEntryArray ()
938                 {
939                         var dictionary = new Dictionary<string, int> ();
940                         dictionary.Add ("foo", 42);
941
942                         var collection = dictionary as ICollection;
943
944                         Assert.AreEqual (1, collection.Count);
945
946                         var entries = new DictionaryEntry [1];
947
948                         collection.CopyTo (entries, 0);
949
950                         Assert.AreEqual ("foo", (string) entries [0].Key);
951                         Assert.AreEqual (42, (int) entries [0].Value);
952                 }
953
954                 [Test]
955                 public void ICollectionCopyToObjectArray ()
956                 {
957                         var dictionary = new Dictionary<string, int> ();
958                         dictionary.Add ("foo", 42);
959
960                         var collection = dictionary as ICollection;
961
962                         Assert.AreEqual (1, collection.Count);
963
964                         var array = new object [1];
965
966                         collection.CopyTo (array, 0);
967
968                         var pair = (KeyValuePair<string, int>) array [0];
969
970                         Assert.AreEqual ("foo", pair.Key);
971                         Assert.AreEqual (42, pair.Value);
972                 }
973
974                 [Test]
975                 [ExpectedException (typeof (ArgumentException))]
976                 public void ICollectionCopyToInvalidArray ()
977                 {
978                         var dictionary = new Dictionary<string, int> ();
979                         dictionary.Add ("foo", 42);
980
981                         var collection = dictionary as ICollection;
982
983                         Assert.AreEqual (1, collection.Count);
984
985                         var array = new int [1];
986
987                         collection.CopyTo (array, 0);
988                 }
989
990                 [Test]
991                 public void ValuesCopyToObjectArray ()
992                 {
993                         var dictionary = new Dictionary<string, string> { { "foo", "bar" } };
994
995                         var values = dictionary.Values as ICollection;
996
997                         var array = new object [values.Count];
998
999                         values.CopyTo (array, 0);
1000
1001                         Assert.AreEqual ("bar", array [0]);
1002                 }
1003
1004                 delegate void D ();
1005                 bool Throws (D d)
1006                 {
1007                         try {
1008                                 d ();
1009                                 return false;
1010                         } catch {
1011                                 return true;
1012                         }
1013                 }
1014
1015                 [Test]
1016                 // based on #491858, #517415
1017                 public void Enumerator_Current ()
1018                 {
1019                         var e1 = new Dictionary<int,int>.Enumerator ();
1020                         Assert.IsFalse (Throws (delegate { var x = e1.Current; }));
1021
1022                         var d = new Dictionary<int,int> ();
1023                         var e2 = d.GetEnumerator ();
1024                         Assert.IsFalse (Throws (delegate { var x = e2.Current; }));
1025                         e2.MoveNext ();
1026                         Assert.IsFalse (Throws (delegate { var x = e2.Current; }));
1027                         e2.Dispose ();
1028                         Assert.IsFalse (Throws (delegate { var x = e2.Current; }));
1029
1030                         var e3 = ((IEnumerable<KeyValuePair<int,int>>) d).GetEnumerator ();
1031                         Assert.IsFalse (Throws (delegate { var x = e3.Current; }));
1032                         e3.MoveNext ();
1033                         Assert.IsFalse (Throws (delegate { var x = e3.Current; }));
1034                         e3.Dispose ();
1035                         Assert.IsFalse (Throws (delegate { var x = e3.Current; }));
1036
1037                         var e4 = ((IEnumerable) d).GetEnumerator ();
1038                         Assert.IsTrue (Throws (delegate { var x = e4.Current; }));
1039                         e4.MoveNext ();
1040                         Assert.IsTrue (Throws (delegate { var x = e4.Current; }));
1041                         ((IDisposable) e4).Dispose ();
1042                         Assert.IsTrue (Throws (delegate { var x = e4.Current; }));
1043                 }
1044
1045                 [Test]
1046                 // based on #491858, #517415
1047                 public void KeyEnumerator_Current ()
1048                 {
1049                         var e1 = new Dictionary<int,int>.KeyCollection.Enumerator ();
1050                         Assert.IsFalse (Throws (delegate { var x = e1.Current; }));
1051
1052                         var d = new Dictionary<int,int> ().Keys;
1053                         var e2 = d.GetEnumerator ();
1054                         Assert.IsFalse (Throws (delegate { var x = e2.Current; }));
1055                         e2.MoveNext ();
1056                         Assert.IsFalse (Throws (delegate { var x = e2.Current; }));
1057                         e2.Dispose ();
1058                         Assert.IsFalse (Throws (delegate { var x = e2.Current; }));
1059
1060                         var e3 = ((IEnumerable<int>) d).GetEnumerator ();
1061                         Assert.IsFalse (Throws (delegate { var x = e3.Current; }));
1062                         e3.MoveNext ();
1063                         Assert.IsFalse (Throws (delegate { var x = e3.Current; }));
1064                         e3.Dispose ();
1065                         Assert.IsFalse (Throws (delegate { var x = e3.Current; }));
1066
1067                         var e4 = ((IEnumerable) d).GetEnumerator ();
1068                         Assert.IsTrue (Throws (delegate { var x = e4.Current; }));
1069                         e4.MoveNext ();
1070                         Assert.IsTrue (Throws (delegate { var x = e4.Current; }));
1071                         ((IDisposable) e4).Dispose ();
1072                         Assert.IsTrue (Throws (delegate { var x = e4.Current; }));
1073                 }
1074
1075                 [Test]
1076                 // based on #491858, #517415
1077                 public void ValueEnumerator_Current ()
1078                 {
1079                         var e1 = new Dictionary<int,int>.ValueCollection.Enumerator ();
1080                         Assert.IsFalse (Throws (delegate { var x = e1.Current; }));
1081
1082                         var d = new Dictionary<int,int> ().Values;
1083                         var e2 = d.GetEnumerator ();
1084                         Assert.IsFalse (Throws (delegate { var x = e2.Current; }));
1085                         e2.MoveNext ();
1086                         Assert.IsFalse (Throws (delegate { var x = e2.Current; }));
1087                         e2.Dispose ();
1088                         Assert.IsFalse (Throws (delegate { var x = e2.Current; }));
1089
1090                         var e3 = ((IEnumerable<int>) d).GetEnumerator ();
1091                         Assert.IsFalse (Throws (delegate { var x = e3.Current; }));
1092                         e3.MoveNext ();
1093                         Assert.IsFalse (Throws (delegate { var x = e3.Current; }));
1094                         e3.Dispose ();
1095                         Assert.IsFalse (Throws (delegate { var x = e3.Current; }));
1096
1097                         var e4 = ((IEnumerable) d).GetEnumerator ();
1098                         Assert.IsTrue (Throws (delegate { var x = e4.Current; }));
1099                         e4.MoveNext ();
1100                         Assert.IsTrue (Throws (delegate { var x = e4.Current; }));
1101                         ((IDisposable) e4).Dispose ();
1102                         Assert.IsTrue (Throws (delegate { var x = e4.Current; }));
1103                 }
1104
1105                 [Test]
1106                 public void ICollectionCopyTo ()
1107                 {
1108                         var d = new Dictionary<int, string> ();
1109
1110                         ICollection c = d;
1111                         c.CopyTo (new object [0], 0);
1112                         c.CopyTo (new string [0], 0);
1113                         c.CopyTo (new MyClass [0], 0);
1114
1115                         c = d.Keys;
1116                         c.CopyTo (new object [0], 0);
1117                         c.CopyTo (new ValueType [0], 0);
1118
1119                         c = d.Values;
1120                         c.CopyTo (new object [0], 0);
1121                         c.CopyTo (new MyClass [0], 0);
1122
1123                         d [3] = null;
1124
1125                         c = d.Keys;
1126                         c.CopyTo (new object [1], 0);
1127                         c.CopyTo (new ValueType [1], 0);
1128
1129                         c = d.Values;
1130                         c.CopyTo (new object [1], 0);
1131                         c.CopyTo (new MyClass [1], 0);
1132                 }
1133
1134                 [Test, ExpectedException (typeof (ArgumentException))]
1135                 public void ICollectionCopyTo_ex1 ()
1136                 {
1137                         var d = new Dictionary<int, string> ();
1138                         ICollection c = d.Keys;
1139                         c.CopyTo (new string [1], 0);
1140                 }
1141
1142                 [Test, ExpectedException (typeof (ArgumentException))]
1143                 public void ICollectionCopyTo_ex2 ()
1144                 {
1145                         var d = new Dictionary<int, string> ();
1146                         ICollection c = d.Values;
1147                         c.CopyTo (new int [1], 0);
1148                 }
1149
1150                 [Test, ExpectedException (typeof (ArgumentException))]
1151                 public void ICollectionCopyTo_ex3 ()
1152                 {
1153                         var d = new Dictionary<int, string> ();
1154                         d [3] = "5";
1155
1156                         ICollection c = d.Keys;
1157                         c.CopyTo (new MyClass [1], 0);
1158                 }
1159
1160                 [Test, ExpectedException (typeof (ArgumentException))]
1161                 public void ICollectionCopyTo_ex4 ()
1162                 {
1163                         var d = new Dictionary<int, string> ();
1164                         d [3] = "5";
1165
1166                         ICollection c = d.Values;
1167                         c.CopyTo (new MyClass [1], 0);
1168                 }
1169
1170                 [Test] // bug 474009
1171                 public void DeserializeEmptyDictionary ()
1172                 {
1173                         // contains a Dictionary<string, int> with Count = 0
1174                         // serialized with MS.NET 3.5
1175                         string data =
1176 @"AAEAAAD/////AQAAAAAAAAAEAQAAAOEBU3lzdGVtLkNvbGxlY3Rpb25zLkdlbmVyaWMuRGljdGlv
1177 bmFyeWAyW1tTeXN0ZW0uU3RyaW5nLCBtc2NvcmxpYiwgVmVyc2lvbj0yLjAuMC4wLCBDdWx0dXJl
1178 PW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODldLFtTeXN0ZW0uSW50MzIs
1179 IG1zY29ybGliLCBWZXJzaW9uPTIuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9r
1180 ZW49Yjc3YTVjNTYxOTM0ZTA4OV1dAwAAAAdWZXJzaW9uCENvbXBhcmVyCEhhc2hTaXplAAMACJIB
1181 U3lzdGVtLkNvbGxlY3Rpb25zLkdlbmVyaWMuR2VuZXJpY0VxdWFsaXR5Q29tcGFyZXJgMVtbU3lz
1182 dGVtLlN0cmluZywgbXNjb3JsaWIsIFZlcnNpb249Mi4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQ
1183 dWJsaWNLZXlUb2tlbj1iNzdhNWM1NjE5MzRlMDg5XV0IAAAAAAkCAAAAAAAAAAQCAAAAkgFTeXN0
1184 ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYy5HZW5lcmljRXF1YWxpdHlDb21wYXJlcmAxW1tTeXN0ZW0u
1185 U3RyaW5nLCBtc2NvcmxpYiwgVmVyc2lvbj0yLjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1Ymxp
1186 Y0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODldXQAAAAAL";
1187
1188                         var stream = new MemoryStream (Convert.FromBase64String (data));
1189                         var fmt = new BinaryFormatter ();
1190                         var dict = (Dictionary <string, int>) fmt.Deserialize (stream);
1191                         Assert.AreEqual (0, dict.Count);
1192                 }
1193
1194                 [Test]
1195                 public void DeserializeNonEmptyDictionary ()
1196                 {
1197                         // contains a Dictionary<string, int> with Count = 2
1198                         // and dict [i.ToString()] == i for each i.
1199                         // serialized with MS.NET 3.5
1200                         string data =
1201 @"AAEAAAD/////AQAAAAAAAAAEAQAAAOEBU3lzdGVtLkNvbGxlY3Rpb25zLkdlbmVyaWMuRGljdGlv
1202 bmFyeWAyW1tTeXN0ZW0uU3RyaW5nLCBtc2NvcmxpYiwgVmVyc2lvbj0yLjAuMC4wLCBDdWx0dXJl
1203 PW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODldLFtTeXN0ZW0uSW50MzIs
1204 IG1zY29ybGliLCBWZXJzaW9uPTIuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9r
1205 ZW49Yjc3YTVjNTYxOTM0ZTA4OV1dBAAAAAdWZXJzaW9uCENvbXBhcmVyCEhhc2hTaXplDUtleVZh
1206 bHVlUGFpcnMAAwADCJIBU3lzdGVtLkNvbGxlY3Rpb25zLkdlbmVyaWMuR2VuZXJpY0VxdWFsaXR5
1207 Q29tcGFyZXJgMVtbU3lzdGVtLlN0cmluZywgbXNjb3JsaWIsIFZlcnNpb249Mi4wLjAuMCwgQ3Vs
1208 dHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1iNzdhNWM1NjE5MzRlMDg5XV0I5QFTeXN0ZW0u
1209 Q29sbGVjdGlvbnMuR2VuZXJpYy5LZXlWYWx1ZVBhaXJgMltbU3lzdGVtLlN0cmluZywgbXNjb3Js
1210 aWIsIFZlcnNpb249Mi4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1iNzdh
1211 NWM1NjE5MzRlMDg5XSxbU3lzdGVtLkludDMyLCBtc2NvcmxpYiwgVmVyc2lvbj0yLjAuMC4wLCBD
1212 dWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODldXVtdAgAAAAkC
1213 AAAAAwAAAAkDAAAABAIAAACSAVN5c3RlbS5Db2xsZWN0aW9ucy5HZW5lcmljLkdlbmVyaWNFcXVh
1214 bGl0eUNvbXBhcmVyYDFbW1N5c3RlbS5TdHJpbmcsIG1zY29ybGliLCBWZXJzaW9uPTIuMC4wLjAs
1215 IEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49Yjc3YTVjNTYxOTM0ZTA4OV1dAAAAAAcD
1216 AAAAAAEAAAACAAAAA+MBU3lzdGVtLkNvbGxlY3Rpb25zLkdlbmVyaWMuS2V5VmFsdWVQYWlyYDJb
1217 W1N5c3RlbS5TdHJpbmcsIG1zY29ybGliLCBWZXJzaW9uPTIuMC4wLjAsIEN1bHR1cmU9bmV1dHJh
1218 bCwgUHVibGljS2V5VG9rZW49Yjc3YTVjNTYxOTM0ZTA4OV0sW1N5c3RlbS5JbnQzMiwgbXNjb3Js
1219 aWIsIFZlcnNpb249Mi4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1iNzdh
1220 NWM1NjE5MzRlMDg5XV0E/P///+MBU3lzdGVtLkNvbGxlY3Rpb25zLkdlbmVyaWMuS2V5VmFsdWVQ
1221 YWlyYDJbW1N5c3RlbS5TdHJpbmcsIG1zY29ybGliLCBWZXJzaW9uPTIuMC4wLjAsIEN1bHR1cmU9
1222 bmV1dHJhbCwgUHVibGljS2V5VG9rZW49Yjc3YTVjNTYxOTM0ZTA4OV0sW1N5c3RlbS5JbnQzMiwg
1223 bXNjb3JsaWIsIFZlcnNpb249Mi4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tl
1224 bj1iNzdhNWM1NjE5MzRlMDg5XV0CAAAAA2tleQV2YWx1ZQEACAYFAAAAATAAAAAAAfr////8////
1225 BgcAAAABMQEAAAAL";
1226                         var stream = new MemoryStream (Convert.FromBase64String (data));
1227                         var fmt = new BinaryFormatter ();
1228                         var dict = (Dictionary <string, int>) fmt.Deserialize (stream);
1229                         Assert.AreEqual (2, dict.Count);
1230                         for (int i = 0; i < dict.Count; i++)
1231                                 Assert.AreEqual (i, dict[i.ToString ()]);
1232                 }
1233         }
1234 }
1235
1236 #endif // NET_2_0