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

            var collectionChangeCount = 0;
            var propertyChangeCount   = 0;

            ((INotifyCollectionChanged)o).CollectionChanged += delegate { collectionChangeCount++; };
            ((INotifyPropertyChanged)o).PropertyChanged     += delegate { propertyChangeCount++; };

            // replace collection should result in correct subscribe / unsubscribe in the aspecs
            var oldItems = o.Items;

            o.Items = new EventedList <ClassWithPropertyChangedAspect>();

            // first add item and change its property in the new list
            var item = new ClassWithPropertyChangedAspect();

            o.Items.Add(item);                     // <-- bubbles collection changed
            item.Name = "bubble property changed"; // <-- bubbles property changed

            // then add item and change its property in the old list
            // ERROR IS HERE, adding items to oldItems should not fire events in "o"
            item = new ClassWithPropertyChangedAspect();
            oldItems.Add(item);                    // <-- bubbles collection changed
            item.Name = "bubble property changed"; // <-- bubbles property changed

            collectionChangeCount
            .Should().Be.EqualTo(1);

            propertyChangeCount
            .Should().Be.EqualTo(2);
        }
コード例 #2
0
        public void MultipleFieldBasedAspectsShouldBubbleEventsOnlyOnce()
        {
            var o = new ClassWithMultipleAspects();

            var collectionChangeCount = 0;
            var propertyChangeCount   = 0;

            ((INotifyCollectionChanged)o).CollectionChanged += delegate { collectionChangeCount++; };
            ((INotifyPropertyChanged)o).PropertyChanged     += delegate { propertyChangeCount++; };

            var item = new ClassWithPropertyChangedAspect();

            o.Items.Add(item);                     // <-- bubbles collection changed

            item.Name = "bubble property changed"; // <-- bubbles property changed

            collectionChangeCount
            .Should().Be.EqualTo(1);

            propertyChangeCount
            .Should().Be.EqualTo(1);
        }
コード例 #3
0
        public void MultipleFieldBasedAspectsShouldBubbleEventsOnlyOnce()
        {
            var o = new ClassWithMultipleAspects();

            var collectionChangeCount = 0;
            var propertyChangeCount = 0;

            ((INotifyCollectionChanged)o).CollectionChanged += delegate { collectionChangeCount++; };
            ((INotifyPropertyChanged)o).PropertyChanged += delegate { propertyChangeCount++; };

            var item = new ClassWithPropertyChangedAspect();
            o.Items.Add(item); // <-- bubbles collection changed

            item.Name = "bubble property changed";// <-- bubbles property changed

            collectionChangeCount
                .Should().Be.EqualTo(1);

            propertyChangeCount
                .Should().Be.EqualTo(1);
        }
コード例 #4
0
        public void MultipleFieldBasedAspectsShouldUnsubscribeProperly()
        {
            var o = new ClassWithMultipleAspects();

            var collectionChangeCount = 0;
            var propertyChangeCount = 0;

            ((INotifyCollectionChanged) o).CollectionChanged += delegate { collectionChangeCount++; };
            ((INotifyPropertyChanged) o).PropertyChanged += delegate { propertyChangeCount++; };

            // replace collection should result in correct subscribe / unsubscribe in the aspecs
            var oldItems = o.Items;
            
            o.Items = new EventedList<ClassWithPropertyChangedAspect>();

            // first add item and change its property in the new list
            var item = new ClassWithPropertyChangedAspect();
            o.Items.Add(item); // <-- bubbles collection changed
            item.Name = "bubble property changed";// <-- bubbles property changed

            // then add item and change its property in the old list
            // ERROR IS HERE, adding items to oldItems should not fire events in "o"
            item = new ClassWithPropertyChangedAspect();
            oldItems.Add(item); // <-- bubbles collection changed
            item.Name = "bubble property changed";// <-- bubbles property changed

            collectionChangeCount
                .Should().Be.EqualTo(1);

            propertyChangeCount
                .Should().Be.EqualTo(2);
            
        }