Example #1
0
        public void ClearCore_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.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.ClearCore();
            Assert.Equal(0, changingCallCount);
            Assert.Equal(0, changedCallCount);
            Assert.Empty(collection);

            // Add again.
            collection.ClearCore();
            Assert.Equal(0, changingCallCount);
            Assert.Equal(0, changedCallCount);
            Assert.Empty(collection);

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

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

            collection.Add(binding);

            collection.ClearCore();
            Assert.Empty(collection);
        }