Пример #1
0
        public void EventRemoveMany()
        {               //****************************************
            var MySeed     = Environment.TickCount;
            var MyRandom   = new Random(MySeed);
            var MyRecords  = new ObservableSortedList <int, int>(1024);
            var EventCount = 0;

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

            for (var Index = 0; Index < 1024; Index++)
            {
                MyRecords.Add(MyRandom.Next(), MyRandom.Next());
            }

            MyRecords.CollectionChanged += (sender, e) => { if (e.Action == NotifyCollectionChangedAction.Remove)
                                                            {
                                                                EventCount++;
                                                            }
            };

            while (MyRecords.Count > 0)
            {
                MyRecords.RemoveAt(MyRecords.Count - 1);
            }

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

            Assert.AreEqual(0, MyRecords.Count, "Item count does not match");
            Assert.AreEqual(1024, EventCount, "Event Count does not match");
        }
Пример #2
0
        public void RemoveAt()
        {               //****************************************
            var MySeed   = Environment.TickCount;
            var MyRandom = new Random(MySeed);

            var MyDictionary = new SortedList <int, int>(1024);

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

            for (var Index = 0; Index < 1024; Index++)
            {
                int Key, Value;

                do
                {
                    Key = MyRandom.Next();
                } while (MyDictionary.ContainsKey(Key));

                Value = MyRandom.Next();

                MyDictionary.Add(Key, Value);
            }

            var MyRecords = new ObservableSortedList <int, int>(MyDictionary);

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

            for (var Index = 0; Index < 512; Index++)
            {
                var InnerIndex = MyRandom.Next(MyRecords.Count);

                var Key = MyRecords.Keys[InnerIndex];

                MyRecords.RemoveAt(InnerIndex);
                Assert.IsTrue(MyDictionary.Remove(Key));
            }

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

            Assert.AreEqual(512, MyRecords.Count, "Count incorrect. Bad Seed was {0}", MySeed);

            CollectionAssert.AreEquivalent(MyDictionary, MyRecords, "Collections don't match. Bad Seed was {0}", MySeed);

            foreach (var MyPair in MyDictionary)
            {
                Assert.IsTrue(MyRecords.TryGetValue(MyPair.Key, out var Value));
                Assert.AreEqual(MyPair.Value, Value);
            }

            Thread.Sleep(1);
        }
Пример #3
0
        public void EventRemove()
        {               //****************************************
            var MySeed = Environment.TickCount;
            var MyRandom = new Random(MySeed);
            var MyRecords = new ObservableSortedList <int, int>(1);
            NotifyCollectionChangedEventArgs MyEventArgs = null, MyKeyEventArgs = null, MyValueEventArgs = null;

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

            MyRecords.Add(42, 84);

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

            MyRecords.RemoveAt(0);

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

            Assert.AreEqual(0, MyRecords.Count, "Item count does not match");
            Assert.IsNotNull(MyEventArgs, "No Event Raised");
            Assert.AreEqual(NotifyCollectionChangedAction.Remove, MyEventArgs.Action);
            Assert.IsNotNull(MyEventArgs.OldItems, "No Old Items");
            Assert.AreEqual(0, MyEventArgs.OldStartingIndex, "Starting Index incorrect");
            Assert.AreEqual(1, MyEventArgs.OldItems.Count, "Old Items Count incorrect");
            Assert.AreEqual(new KeyValuePair <int, int>(42, 84), MyEventArgs.OldItems[0], "Old Items Value incorrect");

            Assert.IsNotNull(MyKeyEventArgs, "No Key Event Raised");
            Assert.AreEqual(NotifyCollectionChangedAction.Remove, MyKeyEventArgs.Action);
            Assert.IsNotNull(MyKeyEventArgs.OldItems, "No Key Old Items");
            Assert.AreEqual(0, MyKeyEventArgs.OldStartingIndex, "Key Starting Index incorrect");
            Assert.AreEqual(1, MyKeyEventArgs.OldItems.Count, "Old Key Items Count incorrect");
            Assert.AreEqual(42, MyKeyEventArgs.OldItems[0], "Old Key Items Value incorrect");

            Assert.IsNotNull(MyValueEventArgs, "No Value Event Raised");
            Assert.AreEqual(NotifyCollectionChangedAction.Remove, MyEventArgs.Action);
            Assert.IsNotNull(MyValueEventArgs.OldItems, "No Value Old Items");
            Assert.AreEqual(0, MyValueEventArgs.OldStartingIndex, "Value Starting Index incorrect");
            Assert.AreEqual(1, MyValueEventArgs.OldItems.Count, "Old Value Items Count incorrect");
            Assert.AreEqual(84, MyValueEventArgs.OldItems[0], "Old Value Items Value incorrect");
        }