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