示例#1
0
        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);
        }
示例#2
0
        public void NamedRestorePointTest()
        {
            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.Undo();

            Assert.AreEqual(1, to.P1);
            Assert.AreEqual(2, to.P2);
            Assert.AreEqual(3, to.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);
        }
示例#5
0
        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);
        }
示例#6
0
        public void SimpleUndoTest()
        {
            SimpleTrackedObject to = new SimpleTrackedObject();

            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);
        }
示例#7
0
        public void MultipleUndoRedoTest()
        {
            SimpleTrackedObject to = new SimpleTrackedObject();
            var sot = (ITrackedObject)to;


            to.ChangeValues(1, 2, 3);

            sot.Tracker.Undo();

            Assert.AreEqual(0, to.P1);
            Assert.AreEqual(0, to.P2);
            Assert.AreEqual(0, to.P3);

            sot.Tracker.Redo();

            Assert.AreEqual(1, to.P1);
            Assert.AreEqual(2, to.P2);
            Assert.AreEqual(3, to.P3);

            to.P1 = 2;
            to.P1 = 3;
            to.P1 = 4;

            sot.Tracker.Undo(); Assert.AreEqual(3, to.P1);

            sot.Tracker.Undo(); Assert.AreEqual(2, to.P1);

            sot.Tracker.Undo(); Assert.AreEqual(1, to.P1);

            sot.Tracker.Undo(); Assert.AreEqual(0, to.P1);

            sot.Tracker.Undo(); Assert.AreEqual(0, to.P1); // empty undo collection

            sot.Tracker.Redo(); Assert.AreEqual(1, to.P1);

            sot.Tracker.Redo(); Assert.AreEqual(2, to.P1);

            sot.Tracker.Redo(); Assert.AreEqual(3, to.P1);

            sot.Tracker.Redo(); Assert.AreEqual(4, to.P1);

            sot.Tracker.Redo(); Assert.AreEqual(4, to.P1); // empty redo collection

            sot.Tracker.Undo(); Assert.AreEqual(3, to.P1);

            sot.Tracker.Redo(); Assert.AreEqual(4, to.P1);
        }
示例#8
0
        public void SimpleUndoRedoTest()
        {
            SimpleTrackedObject to = new SimpleTrackedObject();
            var sot = (ITrackedObject)to;

            to.ChangeValues(1, 2, 3);

            sot.Tracker.Undo();

            Assert.AreEqual(0, to.P1);
            Assert.AreEqual(0, to.P2);
            Assert.AreEqual(0, to.P3);

            sot.Tracker.Redo();

            Assert.AreEqual(1, to.P1);
            Assert.AreEqual(2, to.P2);
            Assert.AreEqual(3, to.P3);
        }
示例#9
0
        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);
        }
示例#10
0
        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 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);
        }
示例#12
0
        public void ReattachDependentObject_IfObjectIsUnchanged_RestoresAggregateTracker()
        {
            AggregateTrackedObject root = new AggregateTrackedObject();

            var dependentObject = new SimpleTrackedObject();

            root.DependentTrackedObject = dependentObject;

            dependentObject.ChangeValues(1, 2, 3);

            root.DependentTrackedObject = null;

            dependentObject.ChangeValues(4, 5, 6);

            ((ITrackedObject)dependentObject).Tracker.Undo();

            ((ITrackedObject)root).Tracker.Undo();
            ((ITrackedObject)root).Tracker.Undo();

            Assert.AreEqual(0, root.DependentTrackedObject.P1);
            Assert.AreEqual(0, root.DependentTrackedObject.P2);
            Assert.AreEqual(0, root.DependentTrackedObject.P3);
        }
示例#13
0
        public void NamedChunkTest()
        {
            SimpleTrackedObject to = new SimpleTrackedObject();
            var sot = (ITrackedObject)to;

            using (ObjectTracker.StartAtomicOperation(sot, "name"))
            {
                to.ChangeValues(4, 5, 6);
                to.ChangeValues(7, 8, 9);
                to.ChangeValues(10, 11, 12);
            }

            sot.Tracker.Undo();
            Assert.AreEqual(0, to.P1);
            Assert.AreEqual(0, to.P2);
            Assert.AreEqual(0, to.P3);

            sot.Tracker.Redo();

            Assert.AreEqual(10, to.P1);
            Assert.AreEqual(11, to.P2);
            Assert.AreEqual(12, to.P3);

            to.ChangeValues(1, 2, 3);

            sot.Tracker.Undo();

            Assert.AreEqual(10, to.P1);
            Assert.AreEqual(11, to.P2);
            Assert.AreEqual(12, to.P3);

            sot.Tracker.Redo();

            Assert.AreEqual(1, to.P1);
            Assert.AreEqual(2, to.P2);
            Assert.AreEqual(3, to.P3);
        }
        public void MultipleNamedRestorePointsTest()
        {
            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);

            ObjectTracker.SetRestorePoint(sot, "s2");

            to.ChangeValues(10, 11, 12);

            to.ChangeValues(1, 2, 3);

            ObjectTracker.UndoTo(sot, "s2");

            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);

            sot.Tracker.Undo();

            Assert.AreEqual(0, to.P1);
            Assert.AreEqual(0, to.P2);
            Assert.AreEqual(0, to.P3);
        }
        public void NamedChunkTest()
        {
            SimpleTrackedObject to = new SimpleTrackedObject();
            var sot = (ITrackedObject)to;

            using (ObjectTracker.StartAtomicOperation(sot, "name"))
            {
                to.ChangeValues(4, 5, 6);
                to.ChangeValues(7, 8, 9);
                to.ChangeValues(10, 11, 12);
            }

            sot.Tracker.Undo();
            Assert.AreEqual(0, to.P1);
            Assert.AreEqual(0, to.P2);
            Assert.AreEqual(0, to.P3);

            sot.Tracker.Redo();

            Assert.AreEqual(10, to.P1);
            Assert.AreEqual(11, to.P2);
            Assert.AreEqual(12, to.P3);

            to.ChangeValues(1, 2, 3);

            sot.Tracker.Undo();

            Assert.AreEqual(10, to.P1);
            Assert.AreEqual(11, to.P2);
            Assert.AreEqual(12, to.P3);

            sot.Tracker.Redo();

            Assert.AreEqual(1, to.P1);
            Assert.AreEqual(2, to.P2);
            Assert.AreEqual(3, to.P3);
        }
        public void SimpleUndoRedoTest()
        {
            SimpleTrackedObject to = new SimpleTrackedObject();
            var sot = (ITrackedObject)to;

            to.ChangeValues(1, 2, 3);

            sot.Tracker.Undo();

            Assert.AreEqual(0, to.P1);
            Assert.AreEqual(0, to.P2);
            Assert.AreEqual(0, to.P3);

            sot.Tracker.Redo();

            Assert.AreEqual(1, to.P1);
            Assert.AreEqual(2, to.P2);
            Assert.AreEqual(3, to.P3);
        }
        public void SimpleUndoTest()
        {
            SimpleTrackedObject to = new SimpleTrackedObject();

            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 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 MultipleUndoRedoTest()
        {
            SimpleTrackedObject to = new SimpleTrackedObject();
            var sot = (ITrackedObject)to;

            to.ChangeValues(1, 2, 3);

            sot.Tracker.Undo();

            Assert.AreEqual(0, to.P1);
            Assert.AreEqual(0, to.P2);
            Assert.AreEqual(0, to.P3);

            sot.Tracker.Redo();

            Assert.AreEqual(1, to.P1);
            Assert.AreEqual(2, to.P2);
            Assert.AreEqual(3, to.P3);

            to.P1 = 2;
            to.P1 = 3;
            to.P1 = 4;

            sot.Tracker.Undo(); Assert.AreEqual(3, to.P1);

            sot.Tracker.Undo(); Assert.AreEqual(2, to.P1);

            sot.Tracker.Undo(); Assert.AreEqual(1, to.P1);

            sot.Tracker.Undo(); Assert.AreEqual(0, to.P1);

            sot.Tracker.Undo(); Assert.AreEqual(0, to.P1); // empty undo collection

            sot.Tracker.Redo(); Assert.AreEqual(1, to.P1);

            sot.Tracker.Redo(); Assert.AreEqual(2, to.P1);

            sot.Tracker.Redo(); Assert.AreEqual(3, to.P1);

            sot.Tracker.Redo(); Assert.AreEqual(4, to.P1);

            sot.Tracker.Redo(); Assert.AreEqual(4, to.P1); // empty redo collection

            sot.Tracker.Undo(); Assert.AreEqual(3, to.P1);

            sot.Tracker.Redo(); Assert.AreEqual(4, to.P1);
        }
        public void ReattachDependentObject_IfObjectIsUnchanged_RestoresAggregateTracker()
        {
            AggregateTrackedObject root = new AggregateTrackedObject();

            var dependentObject = new SimpleTrackedObject();
            root.DependentTrackedObject = dependentObject;

            dependentObject.ChangeValues(1, 2, 3);

            root.DependentTrackedObject = null;

            dependentObject.ChangeValues(4, 5, 6);

            ((ITrackedObject)dependentObject).Tracker.Undo();

            ((ITrackedObject)root).Tracker.Undo();
            ((ITrackedObject)root).Tracker.Undo();

            Assert.AreEqual(0, root.DependentTrackedObject.P1);
            Assert.AreEqual(0, root.DependentTrackedObject.P2);
            Assert.AreEqual(0, root.DependentTrackedObject.P3);
        }