Ejemplo n.º 1
0
        public async void ShouldKeepInCache()
        {
            string   key  = "key";
            IExample repo = MockRepository.GenerateMock <IExample>();

            repo.Stub(e => e.Example()).Return(Task <Example> .FromResult(new Example())).Repeat.Once();

            Func <Task <Example> > func = () =>
            {
                return(repo.Example());
            };

            CacheWrapper cache   = new CacheWrapper(MemoryCache.Default);
            Example      result1 = await cache.GetOrPut(key, func);

            Example result2 = await cache.GetOrPut(key, func);

            Assert.AreSame(result1, result2);
            repo.AssertWasCalled(x => x.Example(), x => x.Repeat.Once());
            repo.VerifyAllExpectations();
        }