Пример #1
0
        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 }));
        }
Пример #2
0
        public TimeSpan TimeInList(string listName)
        {
            var result = TimeSpan.Zero;

            foreach (var item in ListHistory.Where(x => x.ListName == listName))
            {
                result += item.Time;
            }
            return(result);
        }
Пример #3
0
        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 }));
        }
Пример #4
0
 public void RollBackWithNoValues()
 {
     var storage = new ListHistory<int>();
     Assert.DoesNotThrow(() => storage.RollBackTo(new TimeMarker(0)));
 }
Пример #5
0
 public void RollBackToStartWithNoValues()
 {
     var storage = new ListHistory<int>();
     Assert.DoesNotThrow(() => storage.RollBackToStart());
 }
Пример #6
0
 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));
 }
Пример #7
0
        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();
                });
        }
Пример #8
0
        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));
                }
            }
        }
Пример #9
0
        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));
                }
            }
        }
Пример #10
0
        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));
        }
Пример #11
0
        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"));
        }
Пример #12
0
        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"));
        }
Пример #13
0
        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"));
        }
Пример #14
0
        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]);
        }
Пример #15
0
        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 }));
        }
Пример #16
0
        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 }));
        }
Пример #17
0
        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 }));
        }
Пример #18
0
        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 }));
        }
Пример #19
0
        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 }));
        }
Пример #20
0
 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)));
 }
Пример #21
0
        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]));
        }