コード例 #1
0
        public void BubblingOfCollectionChangedEventAfterListPropertyIsChanged()
        {
            var o = new CollectionChangedAspectTestClass();

            var changeCount = 0;

            Post.Cast <CollectionChangedAspectTestClass, INotifyCollectionChanged>(o).CollectionChanged +=
                delegate {
                changeCount++;
            };

            o.Integers = new EventedList <int>();

            o.Integers.Add(1);
            Assert.AreEqual(1, changeCount);

            o.Integers[0] = 11;
            Assert.AreEqual(2, changeCount);

            o.Integers.Remove(11);
            Assert.AreEqual(3, changeCount);

            // the list is empty so add one item again and use clear to get
            // a (single) change event notification
            o.Integers.Add(1);
            o.Integers.Clear();
            Assert.AreEqual(5, changeCount);

            // the list is empty so clear should not fire another change event
            o.Integers.Clear();
            Assert.AreEqual(5, changeCount);
        }
コード例 #2
0
        public void TestNoBubbling()
        {
            var o = new CollectionChangedAspectTestClass();

            var changeCount = 0;

            Post.Cast <CollectionChangedAspectTestClass, INotifyCollectionChanged>(o).CollectionChanged +=
                delegate { changeCount++; };

            o.NoBubblingIntegers.Add(5);

            Assert.AreEqual(0, changeCount);
        }
コード例 #3
0
        public void BubblingWorksWhenUsingEventedListsAsElementsInEventedList()
        {
            var o = new CollectionChangedAspectTestClass();

            var changeCount = 0;

            Post.Cast <CollectionChangedAspectTestClass, INotifyCollectionChanged>(o).CollectionChanged +=
                delegate {
                changeCount++;
            };

            o.Lists.Add(new EventedList <int>(new int[] { 1, 2, 3 }));
            o.Lists[0][0] = 4;

            Assert.AreEqual(2, changeCount);
        }
コード例 #4
0
        public void BubbleEventFromContainingList()
        {
            var o = new CollectionChangedAspectTestClass();

            var changeCount = 0;

            Post.Cast <CollectionChangedAspectTestClass, INotifyCollectionChanged>(o).CollectionChanged +=
                delegate(object sender, NotifyCollectionChangedEventArgs e)
            {
                Assert.AreEqual(5, e.Item);
                changeCount++;
            };

            o.Integers.Add(5);

            Assert.AreEqual(1, changeCount);
        }
コード例 #5
0
        public void BubblingOfCollectionChangedEventAfterObjectsListIsChanged()
        {
            var o = new CollectionChangedAspectTestClass();

            var element = new CollectionChangedAspectTestClass();

            o.ListContainers.Add(element);

            var changeCount = 0;

            Post.Cast <CollectionChangedAspectTestClass, INotifyCollectionChanged>(o).CollectionChanged +=
                delegate {
                changeCount++;
            };

            o.ListContainers.Remove(element);

            Assert.AreEqual(1, changeCount);
        }
コード例 #6
0
        public void BubblingWorksWhenPropertyOfContainerIsResetWithAnotherEventedList()
        {
            var o = new CollectionChangedAspectTestClass();

            var oldIntegers = o.Integers;

            o.Integers = new EventedList <int>(); // <- reset list property to a new value

            var changeCount = 0;

            Post.Cast <CollectionChangedAspectTestClass, INotifyCollectionChanged>(o).CollectionChanged +=
                delegate {
                changeCount++;
            };

            oldIntegers.Add(0); // <- shouldn't generate event in o anymore
            o.Integers.Add(100);

            Assert.AreEqual(1, changeCount);
        }