Ejemplo n.º 1
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 }));
        }
Ejemplo n.º 2
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 }));
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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 }));
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public void RollBackWhileNotExisting()
        {
            var id       = new HistoryId();
            var timeline = new ObjectTimeline <MockHistoryObject>(id, BuildStorageOfType, BuildObject);

            Assert.DoesNotThrow(() => timeline.RollBackTo(new TimeMarker(0)));
        }
Ejemplo n.º 8
0
        public void DeleteFromTimelineWhileNotCreated()
        {
            var id       = new HistoryId();
            var timeline = new ObjectTimeline <MockHistoryObject>(id, BuildStorageOfType, BuildObject);

            Assert.DoesNotThrow(() => timeline.DeleteFromTimeline());
        }
Ejemplo n.º 9
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));
                }
            }
        }
Ejemplo n.º 10
0
        public void DeleteFromTimeline()
        {
            var id       = new HistoryId();
            var timeline = new ObjectTimeline <MockHistoryObject>(id, BuildStorageOfType, BuildObject);

            timeline.AddToTimeline();
            var creationTime = new TimeMarker(1);

            timeline.Mark(creationTime);

            Assert.IsTrue(timeline.IsAlive());
            Assert.AreEqual(creationTime, timeline.CreationTime);
            Assert.IsNull(timeline.DeletionTime);
            Assert.IsNotNull(timeline.Object);

            timeline.DeleteFromTimeline();
            var deletionTime = new TimeMarker(2);

            timeline.Mark(deletionTime);

            Assert.IsFalse(timeline.IsAlive());
            Assert.AreEqual(creationTime, timeline.CreationTime);
            Assert.AreEqual(deletionTime, timeline.DeletionTime);
            Assert.IsNull(timeline.Object);
        }
Ejemplo n.º 11
0
        public void AddToTimelineWithExistingObject()
        {
            var id       = new HistoryId();
            var timeline = new ObjectTimeline <MockHistoryObject>(id, BuildStorageOfType, BuildObject);

            timeline.AddToTimeline();
            var marker = new TimeMarker(1);

            timeline.Mark(marker);

            Assert.Throws <ObjectHasAlreadyBeenAddedToTheTimelineException>(() => timeline.AddToTimeline());
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Adds a new object to the timeline.
        /// </summary>
        /// <typeparam name="T">The type of object that should be added to the timeline.</typeparam>
        /// <param name="objectBuilder">
        /// The function that is used to create a new object of type <typeparamref name="T"/> with the given
        /// collection of member field objects.
        /// </param>
        /// <param name="constructorArguments">The arguments that are passed to the constructor.</param>
        /// <returns>The newly created object of type <typeparamref name="T"/>.</returns>
        public T AddToTimeline <T>(
            Func <HistoryId, IEnumerable <Tuple <byte, IStoreTimelineValues> >, object[], T> objectBuilder,
            params object[] constructorArguments)
            where T : class, IAmHistoryEnabled
        {
            var history = new ObjectTimeline <T>(
                new HistoryId(),
                m_StorageBuilder,
                objectBuilder,
                constructorArguments);

            m_NonMarkedObjectTimelines.Add(history.Id, history);
            history.AddToTimeline();

            return(history.Object);
        }
Ejemplo n.º 13
0
        public void DeleteFromTimelineWhileDeleted()
        {
            var id       = new HistoryId();
            var timeline = new ObjectTimeline <MockHistoryObject>(id, BuildStorageOfType, BuildObject);

            timeline.AddToTimeline();
            var creationTime = new TimeMarker(1);

            timeline.Mark(creationTime);

            timeline.DeleteFromTimeline();
            var deletionTime = new TimeMarker(2);

            timeline.Mark(deletionTime);

            Assert.DoesNotThrow(() => timeline.DeleteFromTimeline());
        }
Ejemplo n.º 14
0
        public void RollForwardWhileDead()
        {
            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.RollForwardTo(new TimeMarker(3)));
            Assert.IsFalse(timeline.IsAlive());
            Assert.IsNull(timeline.Object);
        }
Ejemplo n.º 15
0
        public void AddToTimeline()
        {
            var id       = new HistoryId();
            var timeline = new ObjectTimeline <MockHistoryObject>(id, BuildStorageOfType, BuildObject);

            Assert.IsFalse(timeline.IsAlive());

            timeline.AddToTimeline();
            var marker = new TimeMarker(1);

            timeline.Mark(marker);

            Assert.IsTrue(timeline.IsAlive());
            Assert.AreEqual(marker, timeline.CreationTime);
            Assert.IsNull(timeline.DeletionTime);

            var obj = timeline.Object;

            Assert.AreEqual(0, obj.SomeValue);
            Assert.AreEqual(0, obj.LotsOfValues.Count);
        }
Ejemplo n.º 16
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 }));
        }