Exemple #1
0
        public void EventAddUpdate()
        {               //****************************************
            var MySeed = Environment.TickCount;
            var MyRandom = new Random(MySeed);
            var MyRecords = new ObservableSortedList <int, int>(1);
            NotifyCollectionChangedEventArgs MyEventArgs = null, MyKeyEventArgs = null, MyValueEventArgs = null;

            //****************************************

            MyRecords.CollectionChanged        += (sender, e) => MyEventArgs = e;
            MyRecords.Keys.CollectionChanged   += (sender, e) => MyKeyEventArgs = e;
            MyRecords.Values.CollectionChanged += (sender, e) => MyValueEventArgs = e;

            var Pair = new KeyValuePair <int, int>(MyRandom.Next(), MyRandom.Next());

            MyRecords.BeginUpdate();

            MyRecords.Add(Pair);

            //****************************************

            Assert.IsNull(MyEventArgs, "Event Raised");
            Assert.IsNull(MyKeyEventArgs, "Event Raised");
            Assert.IsNull(MyValueEventArgs, "Event Raised");

            //****************************************

            MyRecords.EndUpdate();

            Assert.AreEqual(1, MyRecords.Count, "Item count does not match");

            Assert.IsNotNull(MyEventArgs, "No Event Raised");
            Assert.AreEqual(NotifyCollectionChangedAction.Reset, MyEventArgs.Action);

            Assert.IsNotNull(MyKeyEventArgs, "No Key Event Raised");
            Assert.AreEqual(NotifyCollectionChangedAction.Reset, MyKeyEventArgs.Action);

            Assert.IsNotNull(MyValueEventArgs, "No Value Event Raised");
            Assert.AreEqual(NotifyCollectionChangedAction.Reset, MyEventArgs.Action);
        }