Пример #1
0
        public void DeleteClearsForwardHistory()
        {
            var id       = new HistoryId();
            var timeline = new ObjectTimeline <MockHistoryObject>(id, BuildStorageOfType, BuildObject);

            timeline.AddToTimeline();
            timeline.Mark(new TimeMarker(2));

            timeline.Object.SomeValue = 1;
            timeline.Object.LotsOfValues.Add(2);
            timeline.Mark(new TimeMarker(3));

            timeline.DeleteFromTimeline();
            timeline.Mark(new TimeMarker(4));

            timeline.RollBackTo(new TimeMarker(2));
            timeline.DeleteFromTimeline();
            timeline.Mark(new TimeMarker(3));

            timeline.RollBackTo(new TimeMarker(2));
            Assert.IsTrue(timeline.IsAlive());
            Assert.AreEqual(new TimeMarker(2), timeline.CreationTime);
            Assert.AreEqual(new TimeMarker(3), timeline.DeletionTime);

            Assert.AreEqual(0, timeline.Object.SomeValue);
            Assert.AreEqual(0, timeline.Object.LotsOfValues.Count);
        }
Пример #2
0
        public void MarkClearsForwardHistory()
        {
            var id       = new HistoryId();
            var timeline = new ObjectTimeline <MockHistoryObject>(id, BuildStorageOfType, BuildObject);

            timeline.AddToTimeline();
            timeline.Mark(new TimeMarker(2));

            timeline.Object.SomeValue = 1;
            timeline.Object.LotsOfValues.Add(2);
            timeline.Mark(new TimeMarker(3));

            timeline.DeleteFromTimeline();
            timeline.Mark(new TimeMarker(4));

            timeline.RollBackTo(new TimeMarker(2));

            timeline.Object.SomeValue = 2;
            timeline.Object.LotsOfValues.Add(3);
            timeline.Mark(new TimeMarker(3));

            timeline.RollForwardTo(new TimeMarker(10));
            Assert.AreEqual(2, timeline.Object.SomeValue);
            Assert.That(
                timeline.Object.LotsOfValues,
                Is.EquivalentTo(new int[] { 3 }));
        }
Пример #3
0
        public void RollForwardWithLocalChange()
        {
            var id       = new HistoryId();
            var timeline = new ObjectTimeline <MockHistoryObject>(id, BuildStorageOfType, BuildObject);

            var creationTime = new TimeMarker(1);

            timeline.AddToTimeline();
            timeline.Mark(creationTime);

            timeline.Object.SomeValue = 1;
            timeline.Object.LotsOfValues.Add(2);
            timeline.Mark(new TimeMarker(2));

            timeline.Object.SomeValue = 2;
            timeline.Object.LotsOfValues.Add(4);
            timeline.Mark(new TimeMarker(3));

            timeline.RollBackTo(new TimeMarker(2));
            timeline.Object.SomeValue = 3;
            timeline.Object.LotsOfValues.Add(8);

            timeline.RollForwardTo(new TimeMarker(3));
            Assert.AreEqual(2, timeline.Object.SomeValue);
            Assert.That(
                timeline.Object.LotsOfValues,
                Is.EquivalentTo(new int[] { 2, 4 }));
        }
Пример #4
0
        public void RollForwardPastDeath()
        {
            var id       = new HistoryId();
            var timeline = new ObjectTimeline <MockHistoryObject>(id, BuildStorageOfType, BuildObject);

            var creationTime = new TimeMarker(1);

            timeline.AddToTimeline();
            timeline.Mark(creationTime);

            timeline.Object.SomeValue = 1;
            timeline.Object.LotsOfValues.Add(2);
            timeline.Mark(new TimeMarker(2));

            var deletionTime = new TimeMarker(3);

            timeline.DeleteFromTimeline();
            timeline.Mark(deletionTime);

            timeline.RollBackTo(new TimeMarker(1));
            Assert.IsTrue(timeline.IsAlive());

            timeline.RollForwardTo(new TimeMarker(4));
            Assert.IsFalse(timeline.IsAlive());
            Assert.IsNull(timeline.Object);
        }
Пример #5
0
        public void RollBackFromDeathToLife()
        {
            var id       = new HistoryId();
            var timeline = new ObjectTimeline <MockHistoryObject>(id, BuildStorageOfType, BuildObject);

            var creationTime = new TimeMarker(1);

            timeline.AddToTimeline();
            timeline.Mark(creationTime);

            timeline.Object.SomeValue = 1;
            timeline.Object.LotsOfValues.Add(2);
            timeline.Mark(new TimeMarker(2));

            var deletionTime = new TimeMarker(3);

            timeline.DeleteFromTimeline();
            timeline.Mark(deletionTime);

            Assert.DoesNotThrow(() => timeline.RollBackTo(new TimeMarker(2)));
            Assert.IsTrue(timeline.IsAlive());
            Assert.IsNotNull(timeline.Object);
            Assert.AreEqual(1, timeline.Object.SomeValue);
            Assert.That(
                timeline.Object.LotsOfValues,
                Is.EquivalentTo(new int[] { 2 }));
        }
Пример #6
0
        public void RollBackWhileNotExisting()
        {
            var id       = new HistoryId();
            var timeline = new ObjectTimeline <MockHistoryObject>(id, BuildStorageOfType, BuildObject);

            Assert.DoesNotThrow(() => timeline.RollBackTo(new TimeMarker(0)));
        }
Пример #7
0
        public void RollBackToBeginning()
        {
            var id       = new HistoryId();
            var timeline = new ObjectTimeline <MockHistoryObject>(id, BuildStorageOfType, BuildObject);

            var creationTime = new TimeMarker(1);

            timeline.AddToTimeline();
            timeline.Mark(creationTime);

            int maximumValue = 10;

            for (int i = 0; i < maximumValue; i++)
            {
                timeline.Object.SomeValue = i;
                timeline.Object.LotsOfValues.Add(i);
                timeline.Mark(new TimeMarker((ulong)(i + 2)));
            }

            timeline.RollBackTo(new TimeMarker(1));
            Assert.IsTrue(timeline.IsAlive());
            Assert.IsNotNull(timeline.Object);
            Assert.AreEqual(0, timeline.Object.SomeValue);
            Assert.AreEqual(0, timeline.Object.LotsOfValues.Count);
        }
Пример #8
0
        public void RollBackToPreviousValue()
        {
            var id       = new HistoryId();
            var timeline = new ObjectTimeline <MockHistoryObject>(id, BuildStorageOfType, BuildObject);

            var creationTime = new TimeMarker(1);

            timeline.AddToTimeline();
            timeline.Mark(creationTime);

            int maximumValue = 10;

            for (int i = 1; i < maximumValue; i++)
            {
                timeline.Object.SomeValue = i;
                timeline.Object.LotsOfValues.Add(i);
                timeline.Mark(new TimeMarker((ulong)(i + 1)));
            }

            for (int i = maximumValue - 1; i > 0; i--)
            {
                timeline.RollBackTo(new TimeMarker((ulong)(i + 1)));
                Assert.AreEqual(i, timeline.Object.SomeValue);

                Assert.AreEqual(i, timeline.Object.LotsOfValues.Count);
                for (int j = 1; j <= i; j++)
                {
                    Assert.IsTrue(timeline.Object.LotsOfValues.Contains(j));
                }
            }
        }
Пример #9
0
        public void RollBackFromDeathPastCreation()
        {
            var id       = new HistoryId();
            var timeline = new ObjectTimeline <MockHistoryObject>(id, BuildStorageOfType, BuildObject);

            var creationTime = new TimeMarker(1);

            timeline.AddToTimeline();
            timeline.Mark(creationTime);

            var deletionTime = new TimeMarker(2);

            timeline.DeleteFromTimeline();
            timeline.Mark(deletionTime);

            Assert.DoesNotThrow(() => timeline.RollBackTo(new TimeMarker(0)));
            Assert.IsFalse(timeline.IsAlive());
            Assert.IsNull(timeline.Object);
        }
Пример #10
0
        public void RollForwardToAfterCreation()
        {
            var id       = new HistoryId();
            var timeline = new ObjectTimeline <MockHistoryObject>(id, BuildStorageOfType, BuildObject);

            var creationTime = new TimeMarker(2);

            timeline.AddToTimeline();
            timeline.Mark(creationTime);

            timeline.Object.SomeValue = 1;
            timeline.Object.LotsOfValues.Add(2);
            timeline.Mark(new TimeMarker(3));

            timeline.RollBackTo(new TimeMarker(1));
            Assert.IsFalse(timeline.IsAlive());

            timeline.RollForwardTo(new TimeMarker(3));
            Assert.AreEqual(1, timeline.Object.SomeValue);
            Assert.That(
                timeline.Object.LotsOfValues,
                Is.EquivalentTo(new int[] { 2 }));
        }