Beispiel #1
0
        public void WhenAbsoluteShouldHandleAbsoluteTime()
        {
            var inOneSecond = _clock.UtcNow.AddSeconds(1);
            var cached      = 0;

            Func <int> retrieve = ()
                                  => _cacheManager.Get("testItem",
                                                       ctx =>
            {
                ctx.Monitor(_clock.WhenUtc(inOneSecond));
                return(++cached);
            });

            Assert.That(retrieve(), Is.EqualTo(1));

            for (var i = 0; i < 10; i++)
            {
                Assert.That(retrieve(), Is.EqualTo(1));
            }
            _clock.Advance(TimeSpan.FromSeconds(1));

            Assert.That(retrieve(), Is.EqualTo(2));
            Assert.That(retrieve(), Is.EqualTo(3));
            Assert.That(retrieve(), Is.EqualTo(4));
        }
        public void WhenAbsoluteShouldHandleAbsoluteTime()
        {
            var inOneSecond = _clock.UtcNow.AddSeconds(1);
            var cached      = 0;

            // each call after the specified datetime will be reevaluated
            Func <int> retrieve = ()
                                  => _cacheManager.Get("testItem",
                                                       ctx => {
                ctx.Monitor(_clock.WhenUtc(inOneSecond));
                return(++cached);
            });

            Assert.Equal(retrieve(), 1);

            for (var i = 0; i < 10; i++)
            {
                Assert.Equal(retrieve(), 1);
            }

            _clock.Advance(TimeSpan.FromSeconds(1));

            Assert.Equal(retrieve(), 2);
            Assert.Equal(retrieve(), 3);
            Assert.Equal(retrieve(), 4);
        }