Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DictionaryBaseTests.cs « tests « System.Collections.NonGeneric « src - github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5b5d36c0bea7cc238407f1690bb6e76f8fc56b85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Xunit;

namespace System.Collections.Tests
{
    public static class DictionaryBaseTests
    {
        private static FooKey CreateKey(int i) => new FooKey(i, i.ToString());

        private static FooValue CreateValue(int i) => new FooValue(i, i.ToString());

        private static MyDictionary CreateDictionary(int count)
        {
            var dictionary = new MyDictionary();
            for (int i = 0; i < count; i++)
            {
                dictionary.Add(CreateKey(i), CreateValue(i));
            }
            return dictionary;
        }

        [Fact]
        public static void Add()
        {
            var dictBase = new MyDictionary();
            for (int i = 0; i < 100; i++)
            {
                FooKey key = CreateKey(i);
                dictBase.Add(key, CreateValue(i));
                Assert.True(dictBase.Contains(key));
            }

            Assert.Equal(100, dictBase.Count);
            for (int i = 0; i < dictBase.Count; i++)
            {
                Assert.Equal(CreateValue(i), dictBase[CreateKey(i)]);
            }

            FooKey nullKey = CreateKey(101);
            dictBase.Add(nullKey, null);
            Assert.Equal(null, dictBase[nullKey]);
        }

        [Fact]
        public static void Remove()
        {
            MyDictionary dictBase = CreateDictionary(100);
            for (int i = 0; i < 100; i++)
            {
                FooKey key = CreateKey(i);
                dictBase.Remove(key);
                Assert.False(dictBase.Contains(key));
            }
            Assert.Equal(0, dictBase.Count);
            dictBase.Remove(new FooKey()); // Doesn't exist, but doesn't throw
        }

        [Fact]
        public static void Contains()
        {
            MyDictionary dictBase = CreateDictionary(100);
            for (int i = 0; i < dictBase.Count; i++)
            {
                Assert.True(dictBase.Contains(CreateKey(i)));
            }
            Assert.False(dictBase.Contains(new FooKey()));
        }

        [Fact]
        public static void Keys()
        {
            MyDictionary dictBase = CreateDictionary(100);
            ICollection keys = dictBase.Keys;

            Assert.Equal(dictBase.Count, keys.Count);
            foreach (FooKey key in keys)
            {
                Assert.True(dictBase.Contains(key));
            }
        }

        [Fact]
        public static void Values()
        {
            MyDictionary dictBase = CreateDictionary(100);
            ICollection values = dictBase.Values;

            Assert.Equal(dictBase.Count, values.Count);
            foreach (FooValue value in values)
            {
                FooKey key = CreateKey(value.IntValue);
                Assert.Equal(value, dictBase[key]);
            }
        }

        [Fact]
        public static void Item_Get()
        {
            MyDictionary dictBase = CreateDictionary(100);
            for (int i = 0; i < dictBase.Count; i++)
            {
                Assert.Equal(CreateValue(i), dictBase[CreateKey(i)]);
            }
            Assert.Equal(null, dictBase[new FooKey()]);
        }

        [Fact]
        public static void Item_Get_NullKey_ThrowsArgumentNullException()
        {
            var dictBase = new MyDictionary();
            Assert.Throws<ArgumentNullException>("key", () => dictBase[null]);
        }

        [Fact]
        public static void Item_Set()
        {
            MyDictionary dictBase = CreateDictionary(100);

            for (int i = 0; i < dictBase.Count; i++)
            {
                FooKey key = CreateKey(i);
                FooValue value = CreateValue(dictBase.Count - i - 1);
                dictBase[key] = value;
                Assert.Equal(value, dictBase[key]);
            }

            FooKey nonExistentKey = CreateKey(101);

            dictBase[nonExistentKey] = null;
            Assert.Equal(101, dictBase.Count); // Should add a key/value pair if the key 
            Assert.Equal(null, dictBase[nonExistentKey]);
        }

        [Fact]
        public static void Indexer_Set_NullKey_ThrowsArgumentNullException()
        {
            var dictBase = new MyDictionary();
            Assert.Throws<ArgumentNullException>("key", () => dictBase[null] = new FooValue());
        }

        [Fact]
        public static void Clear()
        {
            MyDictionary dictBase = CreateDictionary(100);
            dictBase.Clear();
            Assert.Equal(0, dictBase.Count);
        }

        [Fact]
        public static void CopyTo()
        {
            MyDictionary dictBase = CreateDictionary(100);
            // Basic
            var entries = new DictionaryEntry[dictBase.Count];
            dictBase.CopyTo(entries, 0);

            Assert.Equal(dictBase.Count, entries.Length);
            for (int i = 0; i < entries.Length; i++)
            {
                DictionaryEntry entry = entries[i];
                Assert.Equal(CreateKey(entries.Length - i - 1), entry.Key);
                Assert.Equal(CreateValue(entries.Length - i - 1), entry.Value);
            }

            // With index
            entries = new DictionaryEntry[dictBase.Count * 2];
            dictBase.CopyTo(entries, dictBase.Count);

            Assert.Equal(dictBase.Count * 2, entries.Length);
            for (int i = dictBase.Count; i < entries.Length; i++)
            {
                DictionaryEntry entry = entries[i];
                Assert.Equal(CreateKey(entries.Length - i - 1), entry.Key);
                Assert.Equal(CreateValue(entries.Length - i - 1), entry.Value);
            }
        }

        [Fact]
        public static void CopyTo_Invalid()
        {
            MyDictionary dictBase = CreateDictionary(100);
            Assert.Throws<ArgumentNullException>("array", () => dictBase.CopyTo(null, 0)); // Array is null

            Assert.Throws<ArgumentException>(() => dictBase.CopyTo(new object[100, 100], 0)); // Array is multidimensional

            Assert.Throws<ArgumentOutOfRangeException>("arrayIndex", () => dictBase.CopyTo(new DictionaryEntry[100], -1)); // Index < 0

            Assert.Throws<ArgumentException>(null, () => dictBase.CopyTo(new DictionaryEntry[100], 100)); // Index >= count
            Assert.Throws<ArgumentException>(null, () => dictBase.CopyTo(new DictionaryEntry[100], 50)); // Index + array.Count >= count
        }

        [Fact]
        public static void GetEnumerator_IDictionaryEnumerator()
        {
            MyDictionary dictBase = CreateDictionary(100);
            IDictionaryEnumerator enumerator = dictBase.GetEnumerator();
            Assert.NotNull(enumerator);

            int count = 0;
            while (enumerator.MoveNext())
            {
                DictionaryEntry entry1 = (DictionaryEntry)enumerator.Current;
                DictionaryEntry entry2 = enumerator.Entry;

                Assert.Equal(entry1.Key, entry2.Key);
                Assert.Equal(entry1.Value, entry2.Value);

                Assert.Equal(enumerator.Key, entry1.Key);
                Assert.Equal(enumerator.Value, entry1.Value);

                Assert.Equal(enumerator.Value, dictBase[(FooKey)enumerator.Key]);
                count++;
            }

            Assert.Equal(dictBase.Count, count);
        }

        [Fact]
        public static void GetEnumerator_IDictionaryEnumerator_Invalid()
        {
            MyDictionary dictBase = CreateDictionary(100);
            IDictionaryEnumerator enumerator = dictBase.GetEnumerator();

            // Index < 0
            Assert.Throws<InvalidOperationException>(() => enumerator.Current);
            Assert.Throws<InvalidOperationException>(() => enumerator.Entry);
            Assert.Throws<InvalidOperationException>(() => enumerator.Key);
            Assert.Throws<InvalidOperationException>(() => enumerator.Value);

            // Index > dictionary.Count
            while (enumerator.MoveNext()) ;
            Assert.False(enumerator.MoveNext());
            Assert.Throws<InvalidOperationException>(() => enumerator.Current);
            Assert.Throws<InvalidOperationException>(() => enumerator.Entry);
            Assert.Throws<InvalidOperationException>(() => enumerator.Key);
            Assert.Throws<InvalidOperationException>(() => enumerator.Value);

            // Current throws after resetting
            enumerator.Reset();
            Assert.True(enumerator.MoveNext());

            enumerator.Reset();
            Assert.Throws<InvalidOperationException>(() => enumerator.Current);
            Assert.Throws<InvalidOperationException>(() => enumerator.Entry);
            Assert.Throws<InvalidOperationException>(() => enumerator.Key);
            Assert.Throws<InvalidOperationException>(() => enumerator.Value);
        }

        [Fact]
        public static void GetEnumerator_IEnumerator()
        {
            MyDictionary dictBase = CreateDictionary(100);
            IEnumerator enumerator = ((IEnumerable)dictBase).GetEnumerator();
            Assert.NotNull(enumerator);

            int count = 0;
            while (enumerator.MoveNext())
            {
                DictionaryEntry entry = (DictionaryEntry)enumerator.Current;
                Assert.Equal((FooValue)entry.Value, dictBase[(FooKey)entry.Key]);
                count++;
            }

            Assert.Equal(dictBase.Count, count);
        }

        [Fact]
        public static void GetEnumerator_IEnumerator_Invalid()
        {
            MyDictionary dictBase = CreateDictionary(100);
            IEnumerator enumerator = ((IEnumerable)dictBase).GetEnumerator();

            // Index < 0
            Assert.Throws<InvalidOperationException>(() => enumerator.Current);

            // Index >= dictionary.Count
            while (enumerator.MoveNext()) ;
            Assert.Throws<InvalidOperationException>(() => enumerator.Current);
            Assert.False(enumerator.MoveNext());

            // Current throws after resetting
            enumerator.Reset();
            Assert.True(enumerator.MoveNext());

            enumerator.Reset();
            Assert.Throws<InvalidOperationException>(() => enumerator.Current);
        }

        [Fact]
        public static void SyncRoot()
        {
            // SyncRoot should be the reference to the underlying dictionary, not to MyDictionary
            var dictBase = new MyDictionary();
            object syncRoot = dictBase.SyncRoot;
            Assert.NotEqual(syncRoot, dictBase);
            Assert.Equal(dictBase.SyncRoot, dictBase.SyncRoot);
        }

        [Fact]
        public static void IDictionaryProperties()
        {
            var dictBase = new MyDictionary();
            Assert.False(dictBase.IsFixedSize);
            Assert.False(dictBase.IsReadOnly);
            Assert.False(dictBase.IsSynchronized);
        }

        [Fact]
        public static void Add_Called()
        {
            var f = new FooKey(0, "0");
            var dictBase = new OnMethodCalledDictionary();
            dictBase.Add(f, "hello");
            Assert.True(dictBase.OnValidateCalled);
            Assert.True(dictBase.OnInsertCalled);
            Assert.True(dictBase.OnInsertCompleteCalled);

            Assert.True(dictBase.Contains(f));
        }

        [Fact]
        public static void Add_Throws_Called()
        {
            var f = new FooKey(0, "0");

            // Throw OnValidate
            var dictBase = new OnMethodCalledDictionary();
            dictBase.OnValidateThrow = true;

            Assert.Throws<Exception>(() => dictBase.Add(f, ""));
            Assert.Equal(0, dictBase.Count);

            // Throw OnInsert
            dictBase = new OnMethodCalledDictionary();
            dictBase.OnInsertThrow = true;

            Assert.Throws<Exception>(() => dictBase.Add(f, ""));
            Assert.Equal(0, dictBase.Count);

            // Throw OnInsertComplete
            dictBase = new OnMethodCalledDictionary();
            dictBase.OnInsertCompleteThrow = true;

            Assert.Throws<Exception>(() => dictBase.Add(f, ""));
            Assert.Equal(0, dictBase.Count);
        }

        [Fact]
        public static void Remove_Called()
        {
            var f = new FooKey(0, "0");
            var dictBase = new OnMethodCalledDictionary();
            dictBase.Add(f, "");
            dictBase.OnValidateCalled = false;

            dictBase.Remove(f);

            Assert.True(dictBase.OnValidateCalled);
            Assert.True(dictBase.OnRemoveCalled);
            Assert.True(dictBase.OnRemoveCompleteCalled);

            Assert.False(dictBase.Contains(f));
        }

        [Fact]
        public static void Remove_Throws_Called()
        {
            var f = new FooKey(0, "0");

            // Throw OnValidate
            var dictBase = new OnMethodCalledDictionary();
            dictBase.Add(f, "");
            dictBase.OnValidateThrow = true;

            Assert.Throws<Exception>(() => dictBase.Remove(f));
            Assert.Equal(1, dictBase.Count);

            // Throw OnRemove
            dictBase = new OnMethodCalledDictionary();
            dictBase.Add(f, "");
            dictBase.OnRemoveThrow = true;

            Assert.Throws<Exception>(() => dictBase.Remove(f));
            Assert.Equal(1, dictBase.Count);

            // Throw OnRemoveComplete
            dictBase = new OnMethodCalledDictionary();
            dictBase.Add(f, "");
            dictBase.OnRemoveCompleteThrow = true;

            Assert.Throws<Exception>(() => dictBase.Remove(f));
            Assert.Equal(1, dictBase.Count);
        }

        [Fact]
        public static void Clear_Called()
        {
            var f = new FooKey(0, "0");
            var dictBase = new OnMethodCalledDictionary();
            dictBase.Add(f, "");
            dictBase.Clear();

            Assert.True(dictBase.OnClearCalled);
            Assert.True(dictBase.OnClearCompleteCalled);

            Assert.Equal(0, dictBase.Count);
        }

        [Fact]
        public static void Clear_Throws_Called()
        {
            var f = new FooKey(0, "0");

            // Throw OnValidate
            var dictBase = new OnMethodCalledDictionary();
            dictBase.Add(f, "");
            dictBase.OnValidateThrow = true;

            dictBase.Clear();
            Assert.Equal(0, dictBase.Count);

            // Throw OnClear
            dictBase = new OnMethodCalledDictionary();
            dictBase.Add(f, "");
            dictBase.OnClearThrow = true;

            Assert.Throws<Exception>(() => dictBase.Clear());
            Assert.Equal(1, dictBase.Count);

            // Throw OnClearComplete
            dictBase = new OnMethodCalledDictionary();
            dictBase.Add(f, "");
            dictBase.OnClearCompleteThrow = true;

            Assert.Throws<Exception>(() => dictBase.Clear());
            Assert.Equal(0, dictBase.Count);
        }

        [Fact]
        public static void Set_New_Called()
        {
            var f = new FooKey(1, "1");

            var dictBase = new OnMethodCalledDictionary();
            dictBase.OnValidateCalled = false;

            dictBase[f] = "hello";

            Assert.True(dictBase.OnValidateCalled);
            Assert.True(dictBase.OnSetCalled);
            Assert.True(dictBase.OnSetCompleteCalled);

            Assert.Equal(1, dictBase.Count);
            Assert.Equal("hello", dictBase[f]);
        }

        [Fact]
        public static void Set_New_Throws_Called()
        {
            var f = new FooKey(0, "0");

            // Throw OnValidate
            var dictBase = new OnMethodCalledDictionary();
            dictBase.OnValidateThrow = true;

            Assert.Throws<Exception>(() => dictBase[f] = "hello");
            Assert.Equal(0, dictBase.Count);

            // Throw OnSet
            dictBase = new OnMethodCalledDictionary();
            dictBase.OnSetThrow = true;

            Assert.Throws<Exception>(() => dictBase[f] = "hello");
            Assert.Equal(0, dictBase.Count);

            // Throw OnSetComplete
            dictBase = new OnMethodCalledDictionary();
            dictBase.OnSetCompleteThrow = true;

            Assert.Throws<Exception>(() => dictBase[f] = "hello");
            Assert.Equal(0, dictBase.Count);
        }

        [Fact]
        public static void Set_Existing_Called()
        {
            var f = new FooKey(1, "1");

            var dictBase = new OnMethodCalledDictionary();
            dictBase.Add(new FooKey(), "");
            dictBase.OnValidateCalled = false;

            dictBase[f] = "hello";

            Assert.True(dictBase.OnValidateCalled);
            Assert.True(dictBase.OnSetCalled);
            Assert.True(dictBase.OnSetCompleteCalled);

            Assert.Equal("hello", dictBase[f]);
        }

        [Fact]
        public static void Set_Existing_Throws_Called()
        {
            var f = new FooKey(0, "0");

            // Throw OnValidate
            var dictBase = new OnMethodCalledDictionary();
            dictBase.Add(f, "");
            dictBase.OnValidateThrow = true;

            Assert.Throws<Exception>(() => dictBase[f] = "hello");
            Assert.Equal("", dictBase[f]);

            // Throw OnSet
            dictBase = new OnMethodCalledDictionary();
            dictBase.Add(f, "");
            dictBase.OnSetThrow = true;

            Assert.Throws<Exception>(() => dictBase[f] = "hello");
            Assert.Equal("", dictBase[f]);

            // Throw OnSetComplete
            dictBase = new OnMethodCalledDictionary();
            dictBase.Add(f, "");
            dictBase.OnSetCompleteThrow = true;

            Assert.Throws<Exception>(() => dictBase[f] = "hello");
            Assert.Equal("", dictBase[f]);
        }

        // DictionaryBase is provided to be used as the base class for strongly typed collections. Lets use one of our own here
        private class MyDictionary : DictionaryBase
        {
            public void Add(FooKey key, FooValue value) => Dictionary.Add(key, value);

            public FooValue this[FooKey key]
            {
                get { return (FooValue)Dictionary[key]; }
                set { Dictionary[key] = value; }
            }

            public bool IsSynchronized
            {
                get { return Dictionary.IsSynchronized; }
            }

            public object SyncRoot
            {
                get { return Dictionary.SyncRoot; }
            }

            public bool Contains(FooKey key) => Dictionary.Contains(key);

            public void Remove(FooKey key) => Dictionary.Remove(key);

            public bool IsFixedSize
            {
                get { return Dictionary.IsFixedSize; }
            }

            public bool IsReadOnly
            {
                get { return Dictionary.IsReadOnly; }
            }

            public ICollection Keys
            {
                get { return Dictionary.Keys; }
            }

            public ICollection Values
            {
                get { return Dictionary.Values; }
            }
        }

        private class FooKey : IComparable
        {
            public FooKey()
            {
            }

            public FooKey(int i, string str)
            {
                IntValue = i;
                StringValue = str;
            }

            public int IntValue { get; set; }            
            public string StringValue { get; set; }

            public override bool Equals(object obj)
            {
                FooKey foo = obj as FooKey;
                if (foo == null)
                    return false;
                return foo.IntValue == IntValue && foo.StringValue == StringValue;
            }

            public override int GetHashCode() =>IntValue;

            public int CompareTo(object obj)
            {
                FooKey temp = (FooKey)obj;
                return IntValue.CompareTo(temp.IntValue);
            }
        }

        private class FooValue : IComparable
        {
            public FooValue()
            {
            }

            public FooValue(int intValue, string stringValue)
            {
                IntValue = intValue;
                StringValue = stringValue;
            }
            
            public int IntValue { get; set; }
            public string StringValue { get; set; }

            public override bool Equals(object obj)
            {
                FooValue foo = obj as FooValue;
                if (foo == null)
                    return false;
                return foo.IntValue == IntValue && foo.StringValue == StringValue;
            }

            public override int GetHashCode() => IntValue;

            public int CompareTo(object obj)
            {
                FooValue temp = (FooValue)obj;
                return IntValue.CompareTo(temp.IntValue);
            }
        }

        // DictionaryBase is provided to be used as the base class for strongly typed collections. Lets use one of our own here
        private class OnMethodCalledDictionary : DictionaryBase
        {
            public bool OnValidateCalled;
            public bool OnSetCalled;
            public bool OnSetCompleteCalled;
            public bool OnInsertCalled;
            public bool OnInsertCompleteCalled;
            public bool OnClearCalled;
            public bool OnClearCompleteCalled;
            public bool OnRemoveCalled;
            public bool OnRemoveCompleteCalled;

            public bool OnValidateThrow;
            public bool OnSetThrow;
            public bool OnSetCompleteThrow;
            public bool OnInsertThrow;
            public bool OnInsertCompleteThrow;
            public bool OnClearThrow;
            public bool OnClearCompleteThrow;
            public bool OnRemoveThrow;
            public bool OnRemoveCompleteThrow;

            public void Add(FooKey key, string value) => Dictionary.Add(key, value);

            public string this[FooKey key]
            {
                get { return (string)Dictionary[key]; }
                set { Dictionary[key] = value; }
            }

            public bool Contains(FooKey key) => Dictionary.Contains(key);

            public void Remove(FooKey key) => Dictionary.Remove(key);

            protected override void OnSet(object key, object oldValue, object newValue)
            {
                Assert.True(OnValidateCalled);
                Assert.Equal(oldValue, this[(FooKey)key]);

                OnSetCalled = true;

                if (OnSetThrow)
                    throw new Exception("OnSet");
            }

            protected override void OnInsert(object key, object value)
            {
                Assert.True(OnValidateCalled);
                Assert.NotEqual(value, this[(FooKey)key]);

                OnInsertCalled = true;

                if (OnInsertThrow)
                    throw new Exception("OnInsert");
            }

            protected override void OnClear()
            {
                OnClearCalled = true;

                if (OnClearThrow)
                    throw new Exception("OnClear");
            }

            protected override void OnRemove(object key, object value)
            {
                Assert.True(OnValidateCalled);
                Assert.Equal(value, this[(FooKey)key]);

                OnRemoveCalled = true;

                if (OnRemoveThrow)
                    throw new Exception("OnRemove");
            }

            protected override void OnValidate(object key, object value)
            {
                OnValidateCalled = true;

                if (OnValidateThrow)
                    throw new Exception("OnValidate");
            }

            protected override void OnSetComplete(object key, object oldValue, object newValue)
            {
                Assert.True(OnSetCalled);
                Assert.Equal(newValue, this[(FooKey)key]);

                OnSetCompleteCalled = true;

                if (OnSetCompleteThrow)
                    throw new Exception("OnSetComplete");
            }

            protected override void OnInsertComplete(object key, object value)
            {
                Assert.True(OnInsertCalled);
                Assert.Equal(value, this[(FooKey)key]);

                OnInsertCompleteCalled = true;

                if (OnInsertCompleteThrow)
                    throw new Exception("OnInsertComplete");
            }

            protected override void OnClearComplete()
            {
                Assert.True(OnClearCalled);

                OnClearCompleteCalled = true;

                if (OnClearCompleteThrow)
                    throw new Exception("OnClearComplete");
            }

            protected override void OnRemoveComplete(object key, object value)
            {
                Assert.True(OnRemoveCalled);
                Assert.False(Contains((FooKey)key));

                OnRemoveCompleteCalled = true;

                if (OnRemoveCompleteThrow)
                    throw new Exception("OnRemoveComplete");
            }
        }
    }
}