コード例 #1
0
        public void TestEvents2()
        {
            // Build list { [1] = 11, [2] = 22, [3] = 33, [4] = 44, [5] = 55, [6] = 66 }, then remove some things and clear
            var dict = new DictionaryWithChangeEventsForTesting <object, object>();

            dict.Add(1, 11);
            CheckNoEventOccurs(dict, d => ThrowsAny <SystemException>(() => d.Add(P(1, 111))));
            dict.Add(2, 22);
            CheckNoEventOccurs(dict, d => ThrowsAny <SystemException>(() => d.Add(2, 222)));
            dict.Add(3, 3333);
            CheckListChanging(dict, d => d[3] = 33, A(3, 33), A(3, 3333), 1, 11, 2, 22, 3, 3333);
            dict.Add(4, 4444);
            CheckListChanged(dict, d => d[4]  = 44, A(4, 44), A(4, 4444), 1, 11, 2, 22, 3, 33, 4, 44);
            CheckListChanging(dict, d => d[5] = 55, A(5, 55), A(), 1, 11, 2, 22, 3, 33, 4, 44);
            CheckListChanged(dict, d => d[6]  = 66, A(6, 66), A(), 1, 11, 2, 22, 3, 33, 4, 44, 5, 55, 6, 66);

            CheckNoEventOccurs(dict, d => IsFalse(d.Remove(123)));
            CheckListChanging(dict, d => IsTrue(d.Remove(2)), A(), A(2, 22), 1, 11, 2, 22, 3, 33, 4, 44, 5, 55, 6, 66);
            CheckListChanged(dict, d => IsTrue(d.Remove(3)), A(), A(3, 33), 1, 11, 4, 44, 5, 55, 6, 66);
            CheckNoEventOccurs(dict, d => IsFalse((d as ICollection <KeyValuePair <object, object> >).Remove(P(1, -111))));
            CheckListChanging(dict, d => IsTrue((d as ICollection <KeyValuePair <object, object> >).Remove(P(4, 44))), A(), A(4, 44), 1, 11, 4, 44, 5, 55, 6, 66);
            CheckListChanged(dict, d => IsTrue((d as ICollection <KeyValuePair <object, object> >).Remove(P(6, 66))), A(), A(6, 66), 1, 11, 5, 55);

            CheckListChanged(dict, d => d.Clear(), A(), A(1, 11, 5, 55));
            CheckNoEventOccurs(dict, d => IsFalse(d.Remove(1)));
            CheckNoEventOccurs(dict, d => d.Clear());
        }
コード例 #2
0
        public void TestEvents3()
        {
            // Use both overloads of AddRange to build a list { [1] = 11, [2] = 22, ... [7] = 77 }
            var dict = new DictionaryWithChangeEventsForTesting <object, object>();

            CheckListChanging(dict, d => d.AddRange(A(1, 11, 3, 33) as IEnumerable <KeyValuePair <object, object> >), A(1, 11, 3, 33), A());
            CheckListChanged(dict, d => d.AddRange(A(5, 55) as IEnumerable <KeyValuePair <object, object> >), A(5, 55), A(), 1, 11, 3, 33, 5, 55);
            CheckNoEventOccurs(dict, d => d.AddRange(A() as IEnumerable <KeyValuePair <object, object> >));
            CheckNoEventOccurs(dict, d => d.AddRange(A()));
            CheckListChanging(dict, d => d.AddRange(A(7, 77, 2, 22, 4, 44)), A(7, 77, 2, 22, 4, 44), A(), 1, 11, 3, 33, 5, 55);
            CheckListChanged(dict, d => d.AddRange(A(6, 66)), A(6, 66), A(), 1, 11, 3, 33, 5, 55, 7, 77, 2, 22, 4, 44, 6, 66);

            CheckListChanged(dict, d => d.Clear(), A(), A(1, 11, 3, 33, 5, 55, 7, 77, 2, 22, 4, 44, 6, 66));
        }
コード例 #3
0
        public void TestEvents1()
        {
            // Build list { ["five"] = 5, ["six"] = 6, ["seven"] = 7 }, then clear
            var dict = new DictionaryWithChangeEventsForTesting <object, object>();

            CheckListChanging(dict, d => d.Add("five", 5), A("five", 5), A());
            CheckListChanged(dict, d => d.Add("six", 6), A("six", 6), A(), "five", 5, "six", 6);
            CheckListChanging(dict, d => d.Add(P("two", 2)), A("two", 2), A(), "five", 5, "six", 6);
            CheckListChanged(dict, d => d.Add(P("seven", 7)), A("seven", 7), A(), "five", 5, "six", 6, "two", 2, "seven", 7);
            CheckNoEventOccurs(dict, d => IsFalse(d.Remove(P("two", 123))));
            CheckListChanged(dict, d => IsTrue(d.Remove("two")), A(), A("two", 2), "five", 5, "six", 6, "seven", 7);
            CheckListChanging(dict, d => d.Clear(), A(), A("five", 5, "six", 6, "seven", 7), "five", 5, "six", 6, "seven", 7);
            CheckNoEventOccurs(dict, d => d.Clear());
            CheckNoEventOccurs(dict, d => IsFalse(d.Remove(123)));
        }