public void RollForwardThroughClear()
        {
            var objects = new Dictionary <HistoryId, MockHistoryObject>();
            Func <HistoryId, MockHistoryObject> lookupFunc = id => objects[id];
            var storage = new HistoryObjectListHistory <MockHistoryObject>(lookupFunc);

            int maximumValue = 10;

            for (int i = 0; i < maximumValue; i++)
            {
                var obj = new MockHistoryObject(i);
                objects.Add(obj.HistoryId, obj);
                storage.Add(obj);
            }

            storage.StoreCurrent(new TimeMarker(1));

            storage.Clear();
            var newObj = new MockHistoryObject(maximumValue);

            objects.Add(newObj.HistoryId, newObj);
            storage.Add(newObj);

            storage.StoreCurrent(new TimeMarker(2));

            storage.RollBackToStart();
            storage.RollForwardTo(new TimeMarker(2));
            Assert.AreEqual(1, storage.Count);
            Assert.AreSame(objects[new HistoryId(maximumValue)], storage[0]);
        }
        public void RollForwardWithLocalChange()
        {
            var objects = new Dictionary <HistoryId, MockHistoryObject>();
            Func <HistoryId, MockHistoryObject> lookupFunc = id => objects[id];
            var storage = new HistoryObjectListHistory <MockHistoryObject>(lookupFunc);

            int maximumValue = 10;

            for (int i = 0; i < maximumValue; i++)
            {
                var obj = new MockHistoryObject(i);
                objects.Add(obj.HistoryId, obj);
                storage.Add(obj);
                storage.StoreCurrent(new TimeMarker((ulong)(i + 1)));
            }

            storage.RollBackToStart();

            var newObj = new MockHistoryObject(maximumValue + 1);

            objects.Add(newObj.HistoryId, newObj);
            storage.Add(newObj);

            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(objects[new HistoryId(j - 1)]));
                }
            }
        }
        public void RollForwardThroughRemove()
        {
            var objects = new Dictionary <HistoryId, MockHistoryObject>();
            Func <HistoryId, MockHistoryObject> lookupFunc = id => objects[id];
            var storage = new HistoryObjectListHistory <MockHistoryObject>(lookupFunc);

            int maximumValue = 10;

            for (int i = 0; i < maximumValue; i++)
            {
                var obj = new MockHistoryObject(i);
                objects.Add(obj.HistoryId, obj);
                storage.Add(obj);
            }

            storage.StoreCurrent(new TimeMarker(1));

            storage.RemoveAt(5);
            storage.StoreCurrent(new TimeMarker(2));

            storage.RollBackToStart();
            storage.RollForwardTo(new TimeMarker(2));
            Assert.AreEqual(maximumValue - 1, storage.Count);
            for (int i = 0; i < storage.Count; i++)
            {
                if (i < 5)
                {
                    Assert.AreSame(objects[new HistoryId(i)], storage[i]);
                }
                else
                {
                    Assert.AreSame(objects[new HistoryId(i + 1)], storage[i]);
                }
            }
        }
        public void RollForwardToPastNextSnapshot()
        {
            var objects = new Dictionary <HistoryId, MockHistoryObject>();
            Func <HistoryId, MockHistoryObject> lookupFunc = id => objects[id];
            var storage = new HistoryObjectListHistory <MockHistoryObject>(lookupFunc);

            int maximumValue = 30;

            for (int i = 0; i < maximumValue; i++)
            {
                var obj = new MockHistoryObject(i);
                objects.Add(obj.HistoryId, obj);
                storage.Add(obj);
                storage.StoreCurrent(new TimeMarker((ulong)(i + 1)));
            }

            // The snapshot is at 21
            storage.RollBackTo(new TimeMarker(15));
            storage.RollForwardTo(new TimeMarker(25));
            Assert.AreEqual(25, storage.Count);
            for (int i = 0; i < storage.Count; i++)
            {
                Assert.AreSame(objects[new HistoryId(i)], storage[i]);
            }
        }
        public void AddVoidsForwardStack()
        {
            var objects = new Dictionary <HistoryId, MockHistoryObject>();
            Func <HistoryId, MockHistoryObject> lookupFunc = id => objects[id];
            var storage = new HistoryObjectListHistory <MockHistoryObject>(lookupFunc);

            int maximumValue = 10;

            for (int i = 0; i < maximumValue; i++)
            {
                var obj = new MockHistoryObject(i);
                objects.Add(obj.HistoryId, obj);
                storage.Add(obj);
            }

            storage.StoreCurrent(new TimeMarker(1));

            var newObj = new MockHistoryObject(maximumValue);

            objects.Add(newObj.HistoryId, newObj);
            storage[5] = newObj;
            storage.StoreCurrent(new TimeMarker(2));

            storage.Add(newObj);
            storage.StoreCurrent(new TimeMarker(3));

            storage.RollBackTo(new TimeMarker(1));
            storage.RollForwardTo(new TimeMarker(2));
            Assert.AreEqual(maximumValue, storage.Count);
            for (int i = 0; i < storage.Count; i++)
            {
                if (i != 5)
                {
                    Assert.AreSame(objects[new HistoryId(i)], storage[i]);
                }
                else
                {
                    Assert.AreSame(objects[new HistoryId(maximumValue)], storage[i]);
                }
            }
        }
        public void RollBackToStart()
        {
            var objects = new Dictionary <HistoryId, MockHistoryObject>();
            Func <HistoryId, MockHistoryObject> lookupFunc = id => objects[id];
            var storage = new HistoryObjectListHistory <MockHistoryObject>(lookupFunc);

            int maximumValue = 10;

            for (int i = 0; i < maximumValue; i++)
            {
                var obj = new MockHistoryObject(i);
                objects.Add(obj.HistoryId, obj);
                storage.Add(obj);
                storage.StoreCurrent(new TimeMarker((ulong)(i + 1)));
            }

            storage.RollBackToStart();
            Assert.AreEqual(0, storage.Count);
        }