Beispiel #1
0
        public void UnfreezingImbalanceThrows()
        {
            //Arrange.
            ObservableCollectionEx <object> collection = new ObservableCollectionEx <object>();
            Random r             = new Random();
            int    freezeCount   = r.Next(5, 30);
            int    unfreezeCount = 0;

            //Act.
            for (int i = 0; i < freezeCount; ++i)
            {
                collection.FreezeCollectionNotifications();
            }

            //Assert.
            Assert.Throws <InvalidOperationException>(() =>
            {
                for (int i = 0; i <= freezeCount; ++i)
                {
                    ++unfreezeCount;
                    collection.UnfreezeCollectionNotifications();
                }
            });
            Assert.That(unfreezeCount - freezeCount == 1, $"Unfreezing did throw as expected, but did not do it at the expected iteration ({unfreezeCount}).");
        }
Beispiel #2
0
        public void CollectionChangedFlagNotResetWithoutAutoRaiseEvent()
        {
            //Arrange.
            ObservableCollectionEx <object> collection = new ObservableCollectionEx <object>(false);

            //Act.
            collection.FreezeCollectionNotifications();
            collection.Add(new object());
            collection.UnfreezeCollectionNotifications();

            //Assert.
            Assert.That(collection.CollectionChangedWhileFrozen, $"The property {nameof(ObservableCollectionEx<object>.CollectionChangedWhileFrozen)} did not properly report true after unfreezing.");
        }
Beispiel #3
0
        public void CollectionChangedFlagResetWithAutoRaiseEvent()
        {
            //Arrange.
            ObservableCollectionEx <object> collection = new ObservableCollectionEx <object>();

            //Act.
            collection.FreezeCollectionNotifications();
            collection.Add(new object());
            collection.UnfreezeCollectionNotifications();

            //Assert.
            Assert.That(!collection.CollectionChangedWhileFrozen, $"The collection did not reset the {nameof(ObservableCollectionEx<object>.CollectionChangedWhileFrozen)} property to false automatically after unfreezing.");
        }
Beispiel #4
0
        public void CollectionChangedFlagResetOnReFreeze()
        {
            //Arrange.
            ObservableCollectionEx <object> collection = new ObservableCollectionEx <object>(false);

            //Act.
            collection.FreezeCollectionNotifications();
            collection.Add(new object());
            collection.UnfreezeCollectionNotifications();
            collection.FreezeCollectionNotifications();

            //Assert.
            Assert.That(!collection.CollectionChangedWhileFrozen, $"The property {nameof(ObservableCollectionEx<object>.CollectionChangedWhileFrozen)} was not reset to False on re-freeze.");
        }
Beispiel #5
0
        public void AutoFireCollectionChangedOnUnfreeze()
        {
            //Arrange.
            ObservableCollectionEx <object> collection = new ObservableCollectionEx <object>();
            CollectionChangedHandler        handler    = SetupNotifyCollectionChangedHandler(collection);

            //Act.
            collection.FreezeCollectionNotifications();
            collection.Add(new object());
            collection.UnfreezeCollectionNotifications();

            //Assert.
            Assert.That(handler.EventCount == 1, $"CollectionChanged event was raised {handler.EventCount} time(s) when the count was expected to be 1.");
        }