public void BeginEndBulkOperationTest()
        {
            DictionaryChangedEventArgs <int, string> args = null;

            var dictionary = new ObservableDictionary <int, string>();

            dictionary.DictionaryChanged += (sender, e) => args = e;

            dictionary.BeginBatch();
            dictionary.Add(1, "1");
            Assert.IsNull(args);
            dictionary.Add(2, "2");
            Assert.IsNull(args);
            dictionary.EndBatch();
            Assert.IsNotNull(args);

            args = null;
            dictionary.BeginBatch();
            dictionary.AddRange(MakeTestPairs(4, 5, 6));
            Assert.IsNull(args);
            dictionary.Add(10, "10");
            Assert.IsNull(args);
            dictionary.Remove(4);
            Assert.IsNull(args);
            dictionary[4] = "44";
            Assert.IsNull(args);
            dictionary[44] = "44";
            Assert.IsNull(args);
            dictionary.Clear();
            Assert.IsNull(args);
            dictionary.EndBatch();
            Assert.IsNotNull(args);
        }
        public void OperationCollapseTest()
        {
            var argsList   = new List <DictionaryChangedEventArgs <int, string> >();
            var dictionary = new ObservableDictionary <int, string>();

            dictionary.DictionaryChanged += (sender, e) => argsList.Add(e);

            dictionary.BeginBatch();
            dictionary.Add(1, "1");                      //  \
            dictionary.Add(2, "2");                      //   > collapse into [0] add
            dictionary.Add(3, "3");                      //  /
            dictionary.Remove(1);                        //  \
            dictionary.Remove(2);                        //   > collapse into [1] remove
            dictionary.Remove(3);                        //  /
            dictionary.AddRange(MakeTestPairs(1, 2, 3)); //  \
            dictionary.Add(4, "4");                      //   > collapse into [2] add
            dictionary.AddRange(MakeTestPairs(5, 6, 7)); //  /
            dictionary.Remove(7);                        //  \
            dictionary.Remove(6);                        //   > collapse into [3] reset
            dictionary.Clear();                          //  /
            dictionary[1] = "1";                         //  \
            dictionary[2] = "2";                         //   > collapse into [4] add
            dictionary[3] = "3";                         //  /
            dictionary[1] = "1234";                      // no collapse - [5] replace
            dictionary.Remove(1);                        //  \ 
            dictionary.Clear();                          //  / collapse into [6] reset
            Assert.AreEqual(0, argsList.Count);
            dictionary.EndBatch();

            Assert.AreEqual(7, argsList.Count);

            Assert.AreEqual(NotifyCollectionChangedAction.Add, argsList[0].Action);
            Assert.IsTrue(Enumerable.SequenceEqual(MakeTestPairs(1, 2, 3), argsList[0].NewItems));

            Assert.AreEqual(NotifyCollectionChangedAction.Remove, argsList[1].Action);
            Assert.IsTrue(Enumerable.SequenceEqual(MakeTestPairs(1, 2, 3), argsList[1].OldItems));

            Assert.AreEqual(NotifyCollectionChangedAction.Add, argsList[2].Action);
            Assert.IsTrue(Enumerable.SequenceEqual(MakeTestPairs(1, 2, 3, 4, 5, 6, 7), argsList[2].NewItems));

            Assert.AreEqual(NotifyCollectionChangedAction.Reset, argsList[3].Action);

            Assert.AreEqual(NotifyCollectionChangedAction.Add, argsList[4].Action);
            Assert.IsTrue(Enumerable.SequenceEqual(MakeTestPairs(1, 2, 3), argsList[4].NewItems));

            Assert.AreEqual(NotifyCollectionChangedAction.Replace, argsList[5].Action);

            Assert.AreEqual(NotifyCollectionChangedAction.Reset, argsList[6].Action);
        }