コード例 #1
0
        public void LargeOperationTest()
        {
            AggregateTrackedObject root = new AggregateTrackedObject();

            root.DependentTrackedObject = new SimpleTrackedObject();

            var to = (ITrackedObject)root;

            using (ObjectTracker.StartAtomicOperation(to, "name"))
            {
                root.ChangeValuesWithDependent(1, 2, 3);
                root.ChangeValues(3, 4, 5);
                root.DependentTrackedObject.ChangeValues(6, 7, 8);
            }

            to.Tracker.Undo();

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

            Assert.AreEqual(0, root.DependentTrackedObject.P1);
            Assert.AreEqual(0, root.DependentTrackedObject.P2);
            Assert.AreEqual(0, root.DependentTrackedObject.P3);
        }
コード例 #2
0
        public void SimpleAggregateTrackerTest()
        {
            AggregateTrackedObject root = new AggregateTrackedObject();

            root.DependentTrackedObject = new SimpleTrackedObject();

            var to = (ITrackedObject)root;

            root.ChangeValues(1, 2, 3);

            to.Tracker.Undo();

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

            root.DependentTrackedObject.ChangeValues(1, 2, 3);

            to.Tracker.Undo();

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

            Assert.AreEqual(0, root.DependentTrackedObject.P1);
            Assert.AreEqual(0, root.DependentTrackedObject.P2);
            Assert.AreEqual(0, root.DependentTrackedObject.P3);
        }
コード例 #3
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);
        }
コード例 #4
0
        public void AggregateMethodChangingDependentTest()
        {
            AggregateTrackedObject root = new AggregateTrackedObject();

            root.DependentTrackedObject = new SimpleTrackedObject();

            var to = (ITrackedObject)root;

            root.ChangeValuesWithDependent(1, 2, 3);

            to.Tracker.Undo();

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

            Assert.AreEqual(0, root.DependentTrackedObject.P1);
            Assert.AreEqual(0, root.DependentTrackedObject.P2);
            Assert.AreEqual(0, root.DependentTrackedObject.P3);
        }
コード例 #5
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);
        }
コード例 #6
0
        public void LargeOperationTest()
        {
            AggregateTrackedObject root = new AggregateTrackedObject();

            root.DependentTrackedObject = new SimpleTrackedObject();

            var to = (ITrackedObject)root;

            using (ObjectTracker.StartAtomicOperation(to, "name"))
            {
                root.ChangeValuesWithDependent(1, 2, 3);
                root.ChangeValues(3, 4, 5);
                root.DependentTrackedObject.ChangeValues(6, 7, 8);
            }

            to.Tracker.Undo();

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

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