示例#1
0
        public void Clear_Invoke_Success()
        {
            var collection = new BindingsCollection();
            var binding    = new Binding(null, new object(), "member");

            collection.Add(binding);

            collection.Clear();
            Assert.Empty(collection);

            // Clear again.
            collection.Clear();
            Assert.Empty(collection);
        }
示例#2
0
        public void Clear_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.Refresh, e.Action);
                Assert.Null(e.Element);
                changingCallCount++;
                Assert.True(changingCallCount > changedCallCount);
            };
            CollectionChangeEventHandler changedHandler = (sender, e) =>
            {
                Assert.Same(collection, sender);
                Assert.Equal(CollectionChangeAction.Refresh, e.Action);
                Assert.Null(e.Element);
                changedCallCount++;
                Assert.Equal(changingCallCount, changedCallCount);
            };

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

            collection.Clear();
            Assert.Equal(1, changingCallCount);
            Assert.Equal(1, changedCallCount);
            Assert.Empty(collection);

            // Add again.
            collection.Clear();
            Assert.Equal(2, changingCallCount);
            Assert.Equal(2, changedCallCount);
            Assert.Empty(collection);

            // Remove handler.
            collection.CollectionChanging -= changingHandler;
            collection.CollectionChanged  -= changedHandler;

            collection.Clear();
            Assert.Equal(2, changingCallCount);
            Assert.Equal(2, changedCallCount);
            Assert.Empty(collection);
        }
        public void Bindings_Clear_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.Clear();
            Assert.Empty(collection);
            Assert.Null(binding.BindingManagerBase);

            // Clear again.
            collection.Clear();
            Assert.Empty(collection);
        }