void MoveTestHelper() { ObservableCollectionEx <GenericParameterHelper> target = CreateTargetHelper <GenericParameterHelper>(); GenericParameterHelper item0 = new GenericParameterHelper(0); GenericParameterHelper item1 = new GenericParameterHelper(1); GenericParameterHelper item2 = new GenericParameterHelper(2); GenericParameterHelper item3 = new GenericParameterHelper(3); GenericParameterHelper item4 = new GenericParameterHelper(4); target.Add(item0); target.Add(item1); target.Add(item2); target.Add(item3); target.Add(item4); this._firedCollectionEvents.Clear(); this._firedPropertyEvents.Clear(); Assert.IsTrue(1 == target.IndexOf(item1)); target.Move(1, 3); Assert.IsTrue(3 == target.IndexOf(item1)); this._firedCollectionEvents.Clear(); this._firedPropertyEvents.Clear(); using (var iDisabled = target.DisableNotifications()) { iDisabled.Move(3, 1); iDisabled.Move(1, 3); iDisabled.Move(3, 1); iDisabled.Move(1, 3); iDisabled.Move(3, 1); } Assert.IsTrue(0 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications"); Assert.IsTrue(0 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications"); this._firedCollectionEvents.Clear(); this._firedPropertyEvents.Clear(); using (var iDelayed = target.DelayNotifications()) { iDelayed.Move(1, 3); try { iDelayed.Move(3, 1); Assert.Fail("Only one move allowed"); } catch (Exception e) { Assert.IsInstanceOfType(e, typeof(InvalidOperationException)); } } Assert.IsTrue(1 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications"); Assert.IsTrue(1 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications"); }
/// <summary> ///A test for GetDelayedNotifier ///</summary> public void DelayedNotificationTestHelper <T>() where T : new() { ObservableCollectionEx <T> target = CreateTargetHelper <T>(); T item0 = new T(); T item1 = new T(); T item2 = new T(); T item3 = new T(); T item4 = new T(); // Testing Add this._firedCollectionEvents.Clear(); this._firedPropertyEvents.Clear(); using (ObservableCollectionEx <T> iTarget = target.DelayNotifications()) { iTarget.Add(item0); iTarget.Add(item1); iTarget.Add(item2); iTarget.Add(item3); iTarget.Add(item4); Assert.IsTrue(5 == target.Count, "Count is incorrect"); Assert.IsTrue(0 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications"); Assert.IsTrue(0 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications"); } Assert.IsTrue(5 == target.Count, "Count is incorrect"); Assert.IsTrue(2 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications"); Assert.IsTrue(1 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications"); // Testing Replace this._firedCollectionEvents.Clear(); this._firedPropertyEvents.Clear(); using (ObservableCollectionEx <T> iTarget = target.DelayNotifications()) { iTarget[1] = item0; iTarget[2] = item1; iTarget[3] = item2; iTarget[4] = item3; iTarget[0] = item4; using (ObservableCollectionEx <T> iNested = iTarget.DelayNotifications()) { iNested.Add(item4); iNested.Add(item4); Assert.IsTrue(0 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications"); Assert.IsTrue(0 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications"); } Assert.IsTrue(7 == target.Count, "Count is incorrect"); Assert.IsTrue(2 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications"); Assert.IsTrue(1 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications"); } Assert.IsTrue(7 == target.Count, "Count is incorrect"); Assert.IsTrue(3 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications"); Assert.IsTrue(2 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications"); // Testing Remove this._firedCollectionEvents.Clear(); this._firedPropertyEvents.Clear(); using (ObservableCollectionEx <T> iTarget = target.DelayNotifications()) { iTarget.Remove(item0); iTarget.Remove(item1); iTarget.Remove(item2); iTarget.Remove(item3); iTarget.Remove(item4); Assert.IsTrue(2 == target.Count, "Count is incorrect"); Assert.IsTrue(0 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications"); Assert.IsTrue(0 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications"); try { iTarget.Add(item0); Assert.Fail("Mixed operation is not handled"); } catch (Exception e) { Assert.IsInstanceOfType(e, typeof(InvalidOperationException)); } } Assert.IsTrue(3 == target.Count, "Count is incorrect"); Assert.IsTrue(2 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications"); Assert.IsTrue(1 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications"); this._firedCollectionEvents.Clear(); this._firedPropertyEvents.Clear(); using (ObservableCollectionEx <T> iTarget = target.DelayNotifications()) { iTarget.Clear(); } Assert.IsTrue(0 == target.Count, "Count is incorrect"); Assert.IsTrue(2 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications"); Assert.IsTrue(1 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications"); }