Example #1
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.");
        }
Example #2
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}).");
        }
Example #3
0
        public void Freeze()
        {
            //Arrange.
            ObservableCollectionEx <object> collection = new ObservableCollectionEx <object>();
            CollectionChangedHandler        handler    = SetupNotifyCollectionChangedHandler(collection);

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

            //Assert.
            Assert.That(handler.EventCount == 0, $"CollectionChanged event was raised {handler.EventCount} time(s) when it was allegedly frozen.");
        }
Example #4
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.");
        }
Example #5
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.");
        }
Example #6
0
        public void CollectionChangedDetectionWhileFrozen()
        {
            //Arrange.
            ObservableCollectionEx <object> collection = new ObservableCollectionEx <object>();
            CollectionChangedHandler        handler    = SetupNotifyCollectionChangedHandler(collection);

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

            //Assert.
            Assert.That(collection.CollectionChangedWhileFrozen, $"The collection changed while frozen but the change was not reported in the {nameof(ObservableCollectionEx<object>.CollectionChangedWhileFrozen)} property.");
        }
Example #7
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.");
        }