Exemple #1
0
        public void BlockReentrancy()
        {
            var collection = new ObservableCollectionSubclass <int>();

            Assert.NotNull(collection.BlockReentrancy());
            Assert.Same(collection.BlockReentrancy(), collection.BlockReentrancy());
        }
Exemple #2
0
        public void CheckReentrancy_MultipleListeners_MultipleBlocks()
        {
            var collection = new ObservableCollectionSubclass <int>();

            collection.CollectionChanged += (sender, e) => { };
            collection.CollectionChanged += (sender, e) => { };

            collection.CheckReentrancy();

            IDisposable block1 = collection.BlockReentrancy();

            Assert.Throws <InvalidOperationException>(() => collection.CheckReentrancy());

            IDisposable block2 = collection.BlockReentrancy();

            Assert.Throws <InvalidOperationException>(() => collection.CheckReentrancy());

            block1.Dispose();
            Assert.Throws <InvalidOperationException>(() => collection.CheckReentrancy());

            block2.Dispose();
            collection.CheckReentrancy();

            collection.CheckReentrancy();
        }
Exemple #3
0
        public void CheckReentrancy(int listenerCount, bool shouldThrow)
        {
            var collection = new ObservableCollectionSubclass <int>();

            for (int i = 0; i < listenerCount; i++)
            {
                collection.CollectionChanged += (sender, e) => { };
            }

            collection.CheckReentrancy();
            using (collection.BlockReentrancy())
            {
                if (shouldThrow)
                {
                    Assert.Throws <InvalidOperationException>(() => collection.CheckReentrancy());
                }
                else
                {
                    collection.CheckReentrancy();
                }
            }
            collection.CheckReentrancy();
        }