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