public void HistoryTracker_WhenMaxCountSet_MaxCountIsLimited() { HistoryTracker historyTracker = new HistoryTracker(); SimpleTrackedObject sto1 = new SimpleTrackedObject(); historyTracker.Track(sto1); historyTracker.MaximumOperationsCount = 5; sto1.ChangeValues(1, 2, 3); sto1.ChangeValues(2, 5, 6); sto1.ChangeValues(3, 8, 9); sto1.ChangeValues(4, 2, 3); sto1.ChangeValues(5, 5, 6); sto1.ChangeValues(6, 8, 9); sto1.ChangeValues(7, 2, 3); sto1.ChangeValues(8, 5, 6); sto1.ChangeValues(9, 8, 9); for (int i = 0; i < 9; i++) { historyTracker.Undo(); } Assert.AreEqual(4, sto1.P1); Assert.AreEqual(2, sto1.P2); Assert.AreEqual(3, sto1.P3); }
public void SimpleGlobalTrackerMixedWithLocalTrackerTest() { HistoryTracker historyTracker = new HistoryTracker(); SimpleTrackedObject sto1 = new SimpleTrackedObject(); SimpleTrackedObject sto2 = new SimpleTrackedObject(); historyTracker.Track(sto1).Track(sto2); sto1.ChangeValues(1, 2, 3); sto2.ChangeValues(2, 3, 4); ((ITrackedObject)sto1).Tracker.Undo(); Assert.AreEqual(0, sto1.P1); Assert.AreEqual(0, sto1.P2); Assert.AreEqual(0, sto1.P3); historyTracker.Undo(); Assert.AreEqual(1, sto1.P1); Assert.AreEqual(2, sto1.P2); Assert.AreEqual(3, sto1.P3); Assert.AreEqual(2, sto2.P1); Assert.AreEqual(3, sto2.P2); Assert.AreEqual(4, sto2.P3); historyTracker.Undo(); Assert.AreEqual(0, sto2.P1); Assert.AreEqual(0, sto2.P2); Assert.AreEqual(0, sto2.P3); }
public void HistoryTracker_WhenMaxCountSet_MaxCountIsLimited() { HistoryTracker historyTracker = new HistoryTracker(); SimpleTrackedObject sto1 = new SimpleTrackedObject(); historyTracker.Track(sto1); historyTracker.MaximumOperationsCount = 5; sto1.ChangeValues(1, 2, 3); sto1.ChangeValues(2, 5, 6); sto1.ChangeValues(3, 8, 9); sto1.ChangeValues(4, 2, 3); sto1.ChangeValues(5, 5, 6); sto1.ChangeValues(6, 8, 9); sto1.ChangeValues(7, 2, 3); sto1.ChangeValues(8, 5, 6); sto1.ChangeValues(9, 8, 9); for (int i = 0; i < 9; i++) historyTracker.Undo(); Assert.AreEqual(4, sto1.P1); Assert.AreEqual(2, sto1.P2); Assert.AreEqual(3, sto1.P3); }
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 SimpleMultiThreadTestTrackerTest() { // Assert.Fail("Need to write this test conforming to new API - TargetedDelegatedOperation should not be public (or even not exist)"); HistoryTracker globalTracker = new HistoryTracker(); SlowSimpleTrackedObject sto1 = new SlowSimpleTrackedObject(); SlowSimpleTrackedObject sto2 = new SlowSimpleTrackedObject(); globalTracker .Track((ITrackedObject)sto1) .Track((ITrackedObject)sto2); globalTracker.AddOperation(new DelegateOperation( () => { Thread.Sleep(100); Thread.Yield(); Thread.Sleep(100); }, () => { Thread.Sleep(100); Thread.Yield(); Thread.Sleep(100); })); Task.Factory.StartNew( () => { globalTracker.Undo(); globalTracker.Undo(); globalTracker.Undo(); }); sto1.ChangeValues(1, 2, 3); sto2.ChangeValues(2, 3, 4); }