public void SimpleTrackedDictionaryAddTest() { TrackedDictionary <int, string> tc = new TrackedDictionary <int, string>(CollectionTrackingStrategy.TrackOnlyCollectionOperations); tc.Tracker.Track(); tc.Add(0, "0"); tc.Add(1, "1"); tc.Add(2, "2"); tc.Add(3, "3"); tc.Add(4, "4"); tc.Add(5, "5"); ObjectTracker.SetRestorePoint(tc, "After 5"); tc.Add(6, "6"); tc.Add(7, "7"); tc.Add(8, "8"); tc.Add(9, "9"); tc.Add(10, "10"); ObjectTracker.UndoTo(tc, "After 5"); Assert.AreEqual(5, tc.Last().Key); tc.Tracker.Redo(); Assert.AreEqual(6, tc.Last().Key); tc.Tracker.Undo(); Assert.AreEqual(5, tc.Last().Key); tc.Tracker.Undo(); Assert.AreEqual(4, tc.Last().Key); tc.Remove(1); Assert.IsFalse(tc.ContainsKey(1)); tc.Tracker.Undo(); Assert.AreEqual("1", tc[1]); }
public void GlobalTrackerUndo_RestoresLocalTrackerHistory() { HistoryTracker historyTracker = new HistoryTracker(); SimpleTrackedObject sto1 = new SimpleTrackedObject(); SimpleTrackedObject sto2 = new SimpleTrackedObject(); historyTracker.Track(sto1).Track(sto2); sto1.ChangeValues(1, 2, 3); ObjectTracker.SetRestorePoint(sto1, "r1"); sto1.ChangeValues(4, 5, 6); sto1.ChangeValues(7, 8, 9); sto2.ChangeValues(2, 3, 4); ObjectTracker.UndoTo(sto1, "r1"); Assert.AreEqual(1, sto1.P1); Assert.AreEqual(2, sto1.P2); Assert.AreEqual(3, sto1.P3); historyTracker.Undo(); Assert.AreEqual(7, sto1.P1); Assert.AreEqual(8, sto1.P2); Assert.AreEqual(9, sto1.P3); Assert.AreEqual(2, sto2.P1); Assert.AreEqual(3, sto2.P2); Assert.AreEqual(4, sto2.P3); ((ITrackedObject)sto1).Tracker.Undo(); Assert.AreEqual(4, sto1.P1); Assert.AreEqual(5, sto1.P2); Assert.AreEqual(6, sto1.P3); }
public void ChangeTrackingAnInpc_WhenPropertiesChangedAndUndoRequested_UndoExecutesAndEventsAreRaised() { InpcAndChangeTrackingEnabled sut = new InpcAndChangeTrackingEnabled(); sut.PropertyChanged += UniversalPropertyChangedHandler; ObjectTracker.Track(sut); var restorePoint = ObjectTracker.SetRestorePoint(sut); sut.StringProperty = "string"; sut.IntProperty = 1; ObjectTracker.UndoTo(sut, restorePoint); Assert.AreEqual(null, sut.StringProperty); Assert.AreEqual(0, sut.IntProperty); Assert.AreEqual(2, this.GetEventCount(sut, s => s.StringProperty)); Assert.AreEqual(2, this.GetEventCount(sut, s => s.IntProperty)); }
public void WhenTrackerTrackTurnedOff_IsNotTracking() { SimpleTrackedObject to = new SimpleTrackedObject(); var sot = (ITrackedObject)to; sot.Tracker.StopTracking(); to.ChangeValues(1, 2, 3); to.ChangeValues(1, 2, 3); var token = ObjectTracker.SetRestorePoint(to); to.ChangeValues(1, 2, 3); ObjectTracker.UndoTo(to, token); Assert.AreEqual(0, to.P1); Assert.AreEqual(0, to.P2); Assert.AreEqual(0, to.P3); }
public void RedoAfterNamedRestorePointTest_RestoresPoint() { SimpleTrackedObject to = new SimpleTrackedObject(); var sot = (ITrackedObject)to; to.ChangeValues(1, 2, 3); ObjectTracker.SetRestorePoint(sot, "s1"); to.ChangeValues(4, 5, 6); to.ChangeValues(7, 8, 9); to.ChangeValues(10, 11, 12); ObjectTracker.UndoTo(sot, "s1"); Assert.AreEqual(1, to.P1); Assert.AreEqual(2, to.P2); Assert.AreEqual(3, to.P3); sot.Tracker.Redo(); Assert.AreEqual(4, to.P1); Assert.AreEqual(5, to.P2); Assert.AreEqual(6, to.P3); sot.Tracker.Redo(); Assert.AreEqual(7, to.P1); Assert.AreEqual(8, to.P2); Assert.AreEqual(9, to.P3); ObjectTracker.UndoTo(sot, "s1"); Assert.AreEqual(1, to.P1); Assert.AreEqual(2, to.P2); Assert.AreEqual(3, to.P3); }
[Ignore] // TODO resolve interaction between ReaderWriterSynchronized and TrackedObject public void OnReaderWriterSynchronizedObject_WhenUndoPerformed_LocksAreRespected() { var testObject = new ReaderWriterSynchronizedTrackedObject(); testObject.S1 = "123"; var restorePoint = ObjectTracker.SetRestorePoint(testObject); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Task writerLockAcquiredTask = Task.Factory.StartNew(() => testObject.S1 = "sad"); ObjectTracker.UndoTo(testObject, restorePoint); stopwatch.Stop(); writerLockAcquiredTask.Wait(); Assert.IsTrue(stopwatch.ElapsedMilliseconds >= 200); }
public void Add_WhenCalledAndReverted_AddsAndReverts() { TrackedCollection <int> tc = new TrackedCollection <int>(CollectionTrackingStrategy.TrackOnlyCollectionOperations); tc.Tracker.Track(); tc.Add(0); tc.Add(1); tc.Add(2); tc.Add(3); tc.Add(4); tc.Add(5); ObjectTracker.SetRestorePoint(tc, "After 5"); tc.Add(6); tc.Add(7); tc.Add(8); tc.Add(9); tc.Add(10); ObjectTracker.UndoTo(tc, "After 5"); Assert.AreEqual(5, tc.Last()); tc.Tracker.Redo(); Assert.AreEqual(6, tc.Last()); tc.Tracker.Undo(); Assert.AreEqual(5, tc.Last()); tc.Tracker.Undo(); Assert.AreEqual(4, tc.Last()); }