Exemplo n.º 1
0
        public void Get_ForFirstTime_ShouldAskFooOnce()
        {
            var foo = MockRepository.GenerateStub <IFoo>();
            var dateTimeNowProvider = MockRepository.GenerateStub <IDateTimeNowProvider>();

            var currentDateTime = DateTime.Now;

            dateTimeNowProvider
            .Stub(x => x.Now)
            .Do((Func <DateTime>)(() => currentDateTime));

            var underTest = new ExpiringCachedContentTest(dateTimeNowProvider, foo);

            underTest.GetValue();

            foo.AssertWasCalled(x => x.GetValue(), options => options.Repeat.Once());
        }
Exemplo n.º 2
0
        public void Get_ForSecondTimeAfterMaxAge_ShouldAskFooTwice()
        {
            var foo = MockRepository.GenerateStub <IFoo>();
            var dateTimeNowProvider = MockRepository.GenerateStub <IDateTimeNowProvider>();

            var currentDateTime = DateTime.Now;

            dateTimeNowProvider
            .Stub(x => x.Now)
            .Do((Func <DateTime>)(() => currentDateTime));

            var underTest = new ExpiringCachedContentTest(dateTimeNowProvider, foo);

            underTest.GetValue();

            currentDateTime = currentDateTime.AddMilliseconds(MaxAgeInMilliseconds + 1);

            underTest.GetValue();

            foo.AssertWasCalled(x => x.GetValue(), options => options.Repeat.Twice());
        }