Example #1
0
        public void RemoveCore_InvokeWithCollectionChanging_DoesNotCallHandler()
        {
            var collection = new SubBindingsCollection();
            var binding    = new Binding(null, new object(), "member");

            int changingCallCount = 0;
            int changedCallCount  = 0;
            CollectionChangeEventHandler changingHandler = (sender, e) =>
            {
                Assert.Same(collection, sender);
                Assert.Equal(CollectionChangeAction.Remove, e.Action);
                Assert.Same(binding, e.Element);
                changingCallCount++;
                Assert.True(changingCallCount > changedCallCount);
            };
            CollectionChangeEventHandler changedHandler = (sender, e) =>
            {
                Assert.Same(collection, sender);
                Assert.Equal(CollectionChangeAction.Remove, e.Action);
                Assert.Same(binding, e.Element);
                changedCallCount++;
                Assert.Equal(changingCallCount, changedCallCount);
            };

            collection.Add(binding);
            collection.CollectionChanging += changingHandler;
            collection.CollectionChanged  += changedHandler;

            collection.RemoveCore(binding);
            Assert.Equal(0, changingCallCount);
            Assert.Equal(0, changedCallCount);
            Assert.Empty(collection);

            // Add again.
            collection.CollectionChanging -= changingHandler;
            collection.CollectionChanged  -= changedHandler;
            collection.Add(binding);
            collection.CollectionChanging += changingHandler;
            collection.CollectionChanged  += changedHandler;

            collection.RemoveCore(binding);
            Assert.Equal(0, changingCallCount);
            Assert.Equal(0, changedCallCount);
            Assert.Empty(collection);

            // Remove handler.
            collection.CollectionChanging -= changingHandler;
            collection.CollectionChanged  -= changedHandler;
            collection.Add(binding);

            collection.RemoveCore(binding);
            Assert.Equal(0, changingCallCount);
            Assert.Equal(0, changedCallCount);
            Assert.Empty(collection);
        }
Example #2
0
        public void RemoveCore_NullDataBinding_Nop()
        {
            var collection = new SubBindingsCollection();
            var binding    = new Binding(null, new object(), "member");

            collection.Add(binding);

            collection.RemoveCore(null);
            Assert.Same(binding, Assert.Single(collection));
        }
Example #3
0
        public void RemoveCore_Invoke_Success()
        {
            var collection = new SubBindingsCollection();
            var binding    = new Binding(null, new object(), "member");

            collection.Add(binding);

            collection.RemoveCore(binding);
            Assert.Empty(collection);
        }
Example #4
0
        public void RemoveCore_DataBindingFromOtherCollection_Nop()
        {
            var collection1 = new SubBindingsCollection();
            var collection2 = new SubBindingsCollection();
            var binding1    = new Binding(null, new object(), "member");
            var binding2    = new Binding(null, new object(), "member");

            collection1.Add(binding1);
            collection2.Add(binding2);

            collection2.RemoveCore(binding1);
            Assert.Same(binding1, Assert.Single(collection1));
            Assert.Same(binding2, Assert.Single(collection2));
        }