public void ClearVoidsForwardStack() { var storage = new ListHistory<int>(); int maximumValue = 10; for (int i = 0; i < maximumValue; i++) { storage.Add(i); } storage.StoreCurrent(new TimeMarker(1)); storage[5] = maximumValue; storage.StoreCurrent(new TimeMarker(2)); storage.RollBackTo(new TimeMarker(1)); storage.Clear(); storage.Add(maximumValue + 1); storage.StoreCurrent(new TimeMarker(3)); storage.RollForwardTo(new TimeMarker(2)); Assert.That( storage, Is.EquivalentTo(new int[] { maximumValue + 1 })); }
public TimeSpan TimeInList(string listName) { var result = TimeSpan.Zero; foreach (var item in ListHistory.Where(x => x.ListName == listName)) { result += item.Time; } return(result); }
public void RollForwardThroughRemove() { var storage = new ListHistory<int>(); int maximumValue = 10; for (int i = 0; i < maximumValue; i++) { storage.Add(i); } storage.StoreCurrent(new TimeMarker(1)); storage.Remove(5); storage.StoreCurrent(new TimeMarker(2)); storage.RollBackToStart(); storage.RollForwardTo(new TimeMarker(2)); Assert.That( storage, Is.EquivalentTo(new int[] { 0, 1, 2, 3, 4, 6, 7, 8, 9 })); }
public void RollBackWithNoValues() { var storage = new ListHistory<int>(); Assert.DoesNotThrow(() => storage.RollBackTo(new TimeMarker(0))); }
public void RollBackToStartWithNoValues() { var storage = new ListHistory<int>(); Assert.DoesNotThrow(() => storage.RollBackToStart()); }
private bool RecordExists(IEnumerable <DuplicateSubscriber> list, ListHistory item) { return(list.Any(s => s.Subscriber == item.subscriber_id && s.Action == item.action && s.Timestamp == item.timestamp)); }
public void IndexerGetItemsAtInvalidIndex() { var list = new ListHistory<string> { "a", "b", "c", "d", "e", "f", }; Assert.Throws<ArgumentOutOfRangeException>( () => { var result = list[-1]; // We're not expecting to get this far but code analysis says that // we shouldn't have unused locals, unfortunately the compiler doesn't // like it when we remove the local, so .. Assert.IsNull(result); Assert.Fail(); }); Assert.Throws<ArgumentOutOfRangeException>( () => { var result = list[list.Count]; // We're not expecting to get this far but code analysis says that // we shouldn't have unused locals, unfortunately the compiler doesn't // like it when we remove the local, so .. Assert.IsNull(result); Assert.Fail(); }); }
public void RollForwardWithLocalChange() { var storage = new ListHistory<int>(); int maximumValue = 10; for (int i = 1; i < maximumValue; i++) { storage.Add(i); storage.StoreCurrent(new TimeMarker((ulong)i)); } storage.RollBackToStart(); storage.Add(maximumValue + 1); for (int i = 1; i < maximumValue; i++) { storage.RollForwardTo(new TimeMarker((ulong)i)); Assert.AreEqual(i, storage.Count); for (int j = 1; j <= i; j++) { Assert.IsTrue(storage.Contains(j)); } } }
public void RollBackMultipleTimes() { var storage = new ListHistory<int>(); int maximumValue = 10; for (int i = 0; i < maximumValue; i++) { storage.Add(i); storage.StoreCurrent(new TimeMarker((ulong)(i + 1))); } for (int i = maximumValue; i > 0; i--) { storage.RollBackTo(new TimeMarker((ulong)i)); Assert.AreEqual(i, storage.Count); for (int j = 1; j <= i; j++) { Assert.IsTrue(storage.Contains(j - 1)); } } }
public void RemoveItemsAtInvalidIndex() { var list = new ListHistory<string> { "a", "b", "c", "d", "e", "f", }; Assert.Throws<ArgumentOutOfRangeException>(() => list.RemoveAt(-1)); Assert.Throws<ArgumentOutOfRangeException>(() => list.RemoveAt(list.Count)); }
public void RemoveItemsAt() { var list = new ListHistory<string> { "a", "b", "c", "d", "e", "f", }; list.RemoveAt(3); Assert.IsFalse(list.Contains("d")); list.RemoveAt(3); Assert.IsFalse(list.Contains("e")); list.RemoveAt(3); Assert.IsFalse(list.Contains("f")); list.RemoveAt(2); Assert.IsFalse(list.Contains("c")); list.RemoveAt(1); Assert.IsFalse(list.Contains("b")); list.RemoveAt(0); Assert.IsFalse(list.Contains("a")); }
public void InsertItemsAtInvalidIndex() { var list = new ListHistory<string> { "a", "b", "c", "d", "e", "f", }; Assert.Throws<ArgumentOutOfRangeException>(() => list.Insert(-1, "aa")); Assert.Throws<ArgumentOutOfRangeException>(() => list.Insert(list.Count + 1, "bb")); }
public void IndexOfItems() { var list = new ListHistory<string> { "a", "b", "c", "d", "e", "f", }; Assert.AreEqual(0, list.IndexOf("a")); Assert.AreEqual(1, list.IndexOf("b")); Assert.AreEqual(2, list.IndexOf("c")); Assert.AreEqual(3, list.IndexOf("d")); Assert.AreEqual(4, list.IndexOf("e")); Assert.AreEqual(5, list.IndexOf("f")); }
public void IndexerGetSetItems() { var list = new ListHistory<string> { "a", "b", "c", "d", "e", "f", }; Assert.AreEqual("a", list[0]); list[0] = "aa"; Assert.AreEqual("aa", list[0]); Assert.AreEqual("c", list[2]); list[2] = "cc"; Assert.AreEqual("cc", list[2]); Assert.AreEqual("f", list[5]); list[5] = "ff"; Assert.AreEqual("ff", list[5]); }
public void RollForwardToLastValue() { var storage = new ListHistory<int>(); int maximumValue = 10; for (int i = 0; i < maximumValue; i++) { storage.Add(i); storage.StoreCurrent(new TimeMarker((ulong)(i + 1))); } storage.RollBackTo(new TimeMarker(6)); storage.RollForwardTo(new TimeMarker((ulong)maximumValue)); Assert.That( storage, Is.EquivalentTo(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 })); }
public void RollForwardToPriorToNextSnapshot() { var storage = new ListHistory<int>(); int maximumValue = 30; for (int i = 0; i < maximumValue; i++) { storage.Add(i); storage.StoreCurrent(new TimeMarker((ulong)(i + 1))); } // The snapshot is at 21 storage.RollBackTo(new TimeMarker(16)); storage.RollForwardTo(new TimeMarker(20)); Assert.That( storage, Is.EquivalentTo(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 })); }
public void RollBackToBeforeLastSnapshot() { var storage = new ListHistory<int>(); int maximumValue = 30; for (int i = 0; i < maximumValue; i++) { storage.Add(i); storage.StoreCurrent(new TimeMarker((ulong)(i + 1))); } // The snapshot is at 20 storage.RollBackTo(new TimeMarker(26)); Assert.That( storage, Is.EquivalentTo( new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 })); }
public void UpdateClearsForwardStack() { var storage = new ListHistory<int>(); int maximumValue = 10; for (int i = 0; i < maximumValue; i++) { storage.Add(i); } storage.StoreCurrent(new TimeMarker(1)); storage[5] = maximumValue; storage.StoreCurrent(new TimeMarker(2)); storage.RollBackTo(new TimeMarker(1)); storage[9] = maximumValue; storage.StoreCurrent(new TimeMarker(3)); storage.RollForwardTo(new TimeMarker(2)); Assert.That( storage, Is.EquivalentTo(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, maximumValue })); }
public void RollBackToLastSnapshot() { var storage = new ListHistory<int>(); int maximumValue = 30; for (int i = 0; i < maximumValue; i++) { storage.Add(i); storage.StoreCurrent(new TimeMarker((ulong)(i + 1))); } // The first snapshot is at 1, the next one is 20 further so it is at 20 storage.RollBackTo(new TimeMarker(21)); Assert.That( storage, Is.EquivalentTo( new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 })); }
static bool RecordExists(EntityCollection list, ListHistory item) { return(list.Entities.Any(i => (i.Contains("nmc_subscriberid") && (string)i["nmc_subscriberid"] == item.subscriber_id) && (i.Contains("nmc_action") && (string)i["nmc_action"] == item.action) && (i.Contains("nmc_timestamp") && (string)i["nmc_timestamp"] == item.timestamp))); }
public void RollBackToStart() { var storage = new ListHistory<int>(); int maximumValue = 10; for (int i = 0; i < maximumValue; i++) { storage.Add(i); storage.StoreCurrent(new TimeMarker((ulong)(i + 1))); } storage.RollBackToStart(); Assert.That( storage, Is.EquivalentTo(new int[0])); }