Ejemplo n.º 1
0
        /// <summary>
        /// Returns the current value of <typeparamref name="T"/> stored by the <see cref="ValueHistory{T}"/> object.
        /// </summary>
        /// <param name="storage">The storage object that holds the value of <typeparamref name="T"/>.</param>
        /// <returns>The value of <typeparamref name="T"/> stored by the <paramref name="storage"/> object.</returns>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="storage"/> is <see langword="null" />.
        /// </exception>
        public static T FromStorage(ValueHistory <T> storage)
        {
            {
                Lokad.Enforce.Argument(() => storage);
            }

            return(storage.Current);
        }
Ejemplo n.º 2
0
        public void RollBackPastFirstValue()
        {
            var storage = new ValueHistory <int>();

            int maximumValue = 10;

            for (int i = 1; i < maximumValue; i++)
            {
                storage.Current = i;
                storage.StoreCurrent(new TimeMarker((ulong)(i + 1)));
            }

            storage.RollBackTo(new TimeMarker(0));
            int storedValue = storage;

            Assert.AreEqual(0, storedValue);
        }
Ejemplo n.º 3
0
        public void RollForwardPastLastValue()
        {
            var storage = new ValueHistory <int>();

            int maximumValue = 10;

            for (int i = 0; i < maximumValue; i++)
            {
                storage.Current = i;
                storage.StoreCurrent(new TimeMarker((ulong)(i + 1)));
            }

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

            int storedValue = storage;

            Assert.AreEqual(maximumValue - 1, storedValue);
        }
Ejemplo n.º 4
0
        public void RollBackToPreviousValue()
        {
            var storage = new ValueHistory <int>();

            int maximumValue = 10;

            for (int i = 0; i < maximumValue; i++)
            {
                storage.Current = i;
                storage.StoreCurrent(new TimeMarker((ulong)(i + 1)));
            }

            for (int i = maximumValue; i > 0; i--)
            {
                storage.RollBackTo(new TimeMarker((ulong)i));
                int storedValue = storage;
                Assert.AreEqual(i - 1, storedValue);
            }
        }
Ejemplo n.º 5
0
        public void RollBackToStartWithNoValues()
        {
            var storage = new ValueHistory <int>();

            Assert.DoesNotThrow(() => storage.RollBackToStart());
        }