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."); }
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})."); }
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."); }
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."); }
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."); }
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."); }
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."); }