示例#1
0
        public void Remove_InvokeWithCollectionChanging_CallsHandler()
        {
            var collection = new BindingsCollection();
            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.Remove(binding);
            Assert.Equal(1, changingCallCount);
            Assert.Equal(1, changedCallCount);
            Assert.Empty(collection);

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

            collection.Remove(binding);
            Assert.Equal(2, changingCallCount);
            Assert.Equal(2, changedCallCount);
            Assert.Empty(collection);

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

            collection.Remove(binding);
            Assert.Equal(2, changingCallCount);
            Assert.Equal(2, changedCallCount);
            Assert.Empty(collection);
        }
示例#2
0
        public void Remove_NullDataBinding_Nop()
        {
            var collection = new BindingsCollection();
            var binding    = new Binding(null, new object(), "member");

            collection.Add(binding);

            collection.Remove(null);
            Assert.Same(binding, Assert.Single(collection));
        }
        public void Bindings_RemoveNullDataBinding_ThrowsArgumentNullException()
        {
            var manager = new PropertyManager();
            BindingsCollection collection = manager.Bindings;
            var binding = new Binding(null, new object(), "member");

            collection.Add(binding);

            Assert.Throws <ArgumentNullException>("dataBinding", () => collection.Remove(null));
            Assert.Same(binding, Assert.Single(collection));
        }
        public void Bindings_Remove_Success()
        {
            var manager = new PropertyManager();
            BindingsCollection collection = manager.Bindings;
            var binding = new Binding(null, new object(), "member");

            collection.Add(binding);
            Assert.Same(binding, Assert.Single(collection));
            Assert.Same(manager, binding.BindingManagerBase);

            collection.Remove(binding);
            Assert.Empty(collection);
            Assert.Null(binding.BindingManagerBase);
        }
示例#5
0
        public void Remove_DataBindingFromOtherCollection_Nop()
        {
            var collection1 = new BindingsCollection();
            var collection2 = new BindingsCollection();
            var binding1    = new Binding(null, new object(), "member");
            var binding2    = new Binding(null, new object(), "member");

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

            collection2.Remove(binding1);
            Assert.Same(binding1, Assert.Single(collection1));
            Assert.Same(binding2, Assert.Single(collection2));
        }
        public void Bindings_RemoveDataBindingFromOtherCollection_ThrowsArgumentException()
        {
            var manager1 = new PropertyManager();
            var manager2 = new PropertyManager();
            BindingsCollection collection1 = manager1.Bindings;
            BindingsCollection collection2 = manager2.Bindings;
            var binding1 = new Binding(null, new object(), "member");
            var binding2 = new Binding(null, new object(), "member");

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

            Assert.Throws <ArgumentException>("dataBinding", () => collection2.Remove(binding1));
            Assert.Same(binding1, Assert.Single(collection1));
            Assert.Same(binding2, Assert.Single(collection2));
        }