示例#1
0
        public void TimeIsResumedWhenSeededAfterFreeze()
        {
            var currentReferenceTime      = new DateTime(2016, 6, 16, 12, 40, 0);
            var referenceTimeProviderMock = new Mock <IDateTimeProvider>();

            referenceTimeProviderMock
            .Setup(x => x.Time())
            .Returns(() => currentReferenceTime);

            var seededTimeProvider = new SeededDateTimeProvider(referenceTimeProviderMock.Object);

            seededTimeProvider.FreezeTime();
            var firstTime = seededTimeProvider.Time();

            // fast-forward reference time one minute. This should not affect
            // the seeded time provider.
            currentReferenceTime = currentReferenceTime.AddMinutes(1);
            var secondTime = seededTimeProvider.Time();

            // Now, seed the timer with a new time (which is one minute later than the previous)
            seededTimeProvider.SetTimeSeed(currentReferenceTime);
            var thirdTime = seededTimeProvider.Time();

            firstTime.ShouldBe(secondTime);
            thirdTime.ShouldBe(secondTime.AddMinutes(1));
        }
示例#2
0
        public void FreezeTimeReturnsSameTimeOnSubsequentCalls()
        {
            var currentReferenceTime      = new DateTime(2016, 6, 16, 12, 40, 0);
            var referenceTimeProviderMock = new Mock <IDateTimeProvider>();

            referenceTimeProviderMock
            .Setup(x => x.Time())
            .Returns(() => currentReferenceTime);

            var seededTimeProvider = new SeededDateTimeProvider(referenceTimeProviderMock.Object);

            seededTimeProvider.FreezeTime();
            var firstTime = seededTimeProvider.Time();

            // fast-forward reference time one minute. This should not affect
            // the seeded time provider.
            currentReferenceTime = currentReferenceTime.AddMinutes(1);
            var secondTime = seededTimeProvider.Time();

            firstTime.ShouldBe(secondTime);
        }