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)]));
                }
            }
        }
Пример #2
0
        public void RollForwardPastLastValue()
        {
            var objects = new Dictionary <HistoryId, MockHistoryObject>();
            Func <HistoryId, MockHistoryObject> lookupFunc = id => objects[id];
            var storage = new HistoryObjectDictionaryHistory <int, MockHistoryObject>(lookupFunc);

            int maximumValue = 10;

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

            storage.RollBackTo(new TimeMarker(5));
            storage.RollForwardTo(new TimeMarker((ulong)(maximumValue + 1)));

            Assert.AreEqual(maximumValue, storage.Count);

            int index = 0;

            foreach (var pair in storage)
            {
                Assert.AreEqual(index, pair.Key);
                Assert.AreSame(objects[new HistoryId(index)], pair.Value);

                index++;
            }
        }
        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]);
        }
Пример #4
0
        public void RollForwardThroughClear()
        {
            var objects = new Dictionary <HistoryId, MockHistoryObject>();
            Func <HistoryId, MockHistoryObject> lookupFunc = id => objects[id];
            var storage = new HistoryObjectDictionaryHistory <int, MockHistoryObject>(lookupFunc);

            int maximumValue = 10;

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

            storage.StoreCurrent(new TimeMarker(1));

            storage.Clear();

            var otherObj = new MockHistoryObject(maximumValue + 1);

            objects.Add(otherObj.HistoryId, otherObj);
            storage.Add(maximumValue + 1, otherObj);

            storage.StoreCurrent(new TimeMarker(2));

            storage.RollBackToStart();
            storage.RollForwardTo(new TimeMarker(2));

            Assert.AreEqual(1, storage.Count);
            Assert.IsTrue(storage.ContainsKey(maximumValue + 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]);
                }
            }
        }
Пример #6
0
        public void RollBackMultipleTimes()
        {
            var objects = new Dictionary <HistoryId, MockHistoryObject>();
            Func <HistoryId, MockHistoryObject> lookupFunc = id => objects[id];
            var storage = new HistoryObjectDictionaryHistory <int, MockHistoryObject>(lookupFunc);

            int maximumValue = 10;

            for (int i = 0; i < maximumValue; i++)
            {
                var obj = new MockHistoryObject(i);
                objects.Add(obj.HistoryId, obj);
                storage.Add(i, obj);
                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.ContainsKey(j - 1));
                }
            }
        }
        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]);
            }
        }
Пример #8
0
        public void RollBackToLastSnapshot()
        {
            var objects = new Dictionary <HistoryId, MockHistoryObject>();
            Func <HistoryId, MockHistoryObject> lookupFunc = id => objects[id];
            var storage = new HistoryObjectDictionaryHistory <int, MockHistoryObject>(lookupFunc);

            int maximumValue = 30;

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

            // The first snapshot is at 1, the next one is 20 further so it is at 21
            storage.RollBackTo(new TimeMarker(21));
            Assert.AreEqual(21, storage.Count);

            int index = 0;

            foreach (var pair in storage)
            {
                Assert.AreEqual(index, pair.Key);
                Assert.AreSame(objects[new HistoryId(index)], pair.Value);

                index++;
            }
        }
Пример #9
0
        public void AddVoidsForwardStack()
        {
            var objects = new Dictionary <HistoryId, MockHistoryObject>();
            Func <HistoryId, MockHistoryObject> lookupFunc = id => objects[id];
            var storage = new HistoryObjectDictionaryHistory <int, MockHistoryObject>(lookupFunc);

            int maximumValue = 10;

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

            storage.StoreCurrent(new TimeMarker(1));

            var otherObj = new MockHistoryObject(maximumValue);

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

            storage.RollBackTo(new TimeMarker(1));

            var yetAnotherObj = new MockHistoryObject(maximumValue + 1);

            objects.Add(yetAnotherObj.HistoryId, yetAnotherObj);
            storage.Add(11, yetAnotherObj);
            storage.StoreCurrent(new TimeMarker(3));

            storage.RollForwardTo(new TimeMarker(2));

            Assert.AreEqual(maximumValue + 1, storage.Count);

            int index = 0;

            foreach (var pair in storage)
            {
                if (index < maximumValue)
                {
                    Assert.AreEqual(index, pair.Key);
                    Assert.AreSame(objects[new HistoryId(index)], pair.Value);
                }
                else
                {
                    Assert.AreEqual(index + 1, pair.Key);
                    Assert.AreSame(objects[new HistoryId(index + 1)], pair.Value);
                }

                index++;
            }
        }
Пример #10
0
        public void RemoveWithUnknownKey()
        {
            var objects = new Dictionary <HistoryId, MockHistoryObject>();
            Func <HistoryId, MockHistoryObject> lookupFunc = id => objects[id];
            var storage = new HistoryObjectDictionaryHistory <int, MockHistoryObject>(lookupFunc);

            int key   = 5;
            var value = new MockHistoryObject(10);

            objects.Add(value.HistoryId, value);
            storage.Add(key, value);

            Assert.IsFalse(storage.Remove(6));
        }
Пример #11
0
        public void AddWithDuplicateKey()
        {
            var objects = new Dictionary <HistoryId, MockHistoryObject>();
            Func <HistoryId, MockHistoryObject> lookupFunc = id => objects[id];
            var storage = new HistoryObjectDictionaryHistory <int, MockHistoryObject>(lookupFunc);

            int key   = 5;
            var value = new MockHistoryObject(10);

            objects.Add(value.HistoryId, value);
            storage.Add(key, value);

            Assert.Throws <ArgumentException>(() => storage.Add(key, value));
        }
Пример #12
0
        public void Add()
        {
            var objects = new Dictionary <HistoryId, MockHistoryObject>();
            Func <HistoryId, MockHistoryObject> lookupFunc = id => objects[id];
            var storage = new HistoryObjectDictionaryHistory <int, MockHistoryObject>(lookupFunc);

            int key   = 5;
            var value = new MockHistoryObject(10);

            objects.Add(value.HistoryId, value);
            storage.Add(key, value);

            Assert.IsTrue(storage.ContainsKey(key));
            Assert.AreEqual(1, storage.Count);
            Assert.AreSame(value, storage[key]);
        }
Пример #13
0
        public void TryGetValueWithUnknownValue()
        {
            var objects = new Dictionary <HistoryId, MockHistoryObject>();
            Func <HistoryId, MockHistoryObject> lookupFunc = id => objects[id];
            var storage = new HistoryObjectDictionaryHistory <int, MockHistoryObject>(lookupFunc);

            int key   = 5;
            var value = new MockHistoryObject(10);

            objects.Add(value.HistoryId, value);
            storage.Add(key, value);

            MockHistoryObject result;
            var success = storage.TryGetValue(6, out result);

            Assert.IsFalse(success);
            Assert.AreEqual(null, result);
        }
Пример #14
0
        public void Remove()
        {
            var objects = new Dictionary <HistoryId, MockHistoryObject>();
            Func <HistoryId, MockHistoryObject> lookupFunc = id => objects[id];
            var storage = new HistoryObjectDictionaryHistory <int, MockHistoryObject>(lookupFunc);

            int key   = 5;
            var value = new MockHistoryObject(10);

            objects.Add(value.HistoryId, value);
            storage.Add(key, value);

            var result = storage.Remove(key);

            Assert.IsTrue(result);
            Assert.AreEqual(0, storage.Count);
            Assert.IsFalse(storage.ContainsKey(key));
        }
Пример #15
0
        public void RollForwardThroughRemove()
        {
            var objects = new Dictionary <HistoryId, MockHistoryObject>();
            Func <HistoryId, MockHistoryObject> lookupFunc = id => objects[id];
            var storage = new HistoryObjectDictionaryHistory <int, MockHistoryObject>(lookupFunc);

            int maximumValue = 10;

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

            storage.StoreCurrent(new TimeMarker(1));

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

            storage.RollBackToStart();
            storage.RollForwardTo(new TimeMarker(2));

            Assert.AreEqual(maximumValue - 1, storage.Count);

            int index = 0;

            foreach (var pair in storage)
            {
                if (index < 5)
                {
                    Assert.AreEqual(index, pair.Key);
                    Assert.AreSame(objects[new HistoryId(index)], pair.Value);
                }
                else
                {
                    Assert.AreEqual(index + 1, pair.Key);
                    Assert.AreSame(objects[new HistoryId(index + 1)], pair.Value);
                }

                index++;
            }
        }
        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);
        }
        public void UpdateClearsForwardStack()
        {
            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.RollBackTo(new TimeMarker(1));

            storage[9] = newObj;
            storage.StoreCurrent(new TimeMarker(3));

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

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

            storage.RollBackTo(new TimeMarker(1));
            MockHistoryObject storedValue = storage;
            Assert.AreSame(objects[new HistoryId(0)], storedValue);
        }
Пример #19
0
        public void RollBackToFirstValue()
        {
            var objects = new Dictionary <HistoryId, MockHistoryObject>();
            Func <HistoryId, MockHistoryObject> lookupFunc = id => objects[id];
            var storage = new HistoryObjectDictionaryHistory <int, MockHistoryObject>(lookupFunc);

            int maximumValue = 10;

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

            storage.RollBackTo(new TimeMarker(1));
            Assert.AreEqual(1, storage.Count);
            Assert.IsTrue(storage.ContainsKey(0));
        }
        public void RollBackToStart()
        {
            var objects = new Dictionary <HistoryId, MockHistoryObject>();
            Func <HistoryId, MockHistoryObject> lookupFunc =
                id => (id != null) ? objects[id] : null;
            var storage = new HistoryObjectValueHistory <MockHistoryObject>(lookupFunc);

            int maximumValue = 10;

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

            storage.RollBackToStart();
            MockHistoryObject storedValue = storage;

            Assert.AreEqual(null, storedValue);
        }
        public void RollBackToFirstValue()
        {
            var objects = new Dictionary <HistoryId, MockHistoryObject>();
            Func <HistoryId, MockHistoryObject> lookupFunc =
                id => objects[id];
            var storage = new HistoryObjectValueHistory <MockHistoryObject>(lookupFunc);

            int maximumValue = 10;

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

            storage.RollBackTo(new TimeMarker(1));
            MockHistoryObject storedValue = storage;

            Assert.AreSame(objects[new HistoryId(0)], storedValue);
        }
        public void IndexerGetSetItems()
        {
            var list = new HistoryObjectListHistory <MockHistoryObject>(FromId)
            {
                new MockHistoryObject(0),
                new MockHistoryObject(1),
                new MockHistoryObject(2),
                new MockHistoryObject(3),
                new MockHistoryObject(4),
                new MockHistoryObject(5),
            };

            Assert.AreEqual(new MockHistoryObject(0), list[0]);
            list[0] = new MockHistoryObject(10);
            Assert.AreEqual(new MockHistoryObject(10), list[0]);

            Assert.AreEqual(new MockHistoryObject(2), list[2]);
            list[2] = new MockHistoryObject(20);
            Assert.AreEqual(new MockHistoryObject(20), list[2]);

            Assert.AreEqual(new MockHistoryObject(5), list[5]);
            list[5] = new MockHistoryObject(50);
            Assert.AreEqual(new MockHistoryObject(50), list[5]);
        }
        public void RollBackToStart()
        {
            var objects = new Dictionary<HistoryId, MockHistoryObject>();
            Func<HistoryId, MockHistoryObject> lookupFunc =
                id => (id != null) ? objects[id] : null;
            var storage = new HistoryObjectValueHistory<MockHistoryObject>(lookupFunc);

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

            storage.RollBackToStart();
            MockHistoryObject storedValue = storage;
            Assert.AreEqual(null, storedValue);
        }