public void GetEvents_Caches_Results()
        {
            //Arrange
            var eventsRepo = new StubIRepository<Event>()
            {
                All = () => EventTestData.SingleEvent.AsQueryable()
            };
            var cacheService = new DefaultMemoryCache();
            var eventService = new EventsService(eventsRepo, cacheService);

            //Act
            eventService.GetEvents();
            //Assert
            Assert.IsTrue(cacheService.Exists("events:all"));
        }
Exemple #2
0
        public void cache_singleton()
        {
            var cache = new DefaultMemoryCache();

            var conf = new HttpConfiguration();

            conf.CacheOutputConfiguration().RegisterCacheOutputProvider(() => cache);

            object cache1;

            conf.Properties.TryGetValue(typeof(IApiOutputCache), out cache1);

            object cache2;

            conf.Properties.TryGetValue(typeof(IApiOutputCache), out cache2);

            Assert.Same(((Func <IApiOutputCache>)cache1)(), ((Func <IApiOutputCache>)cache2)());
        }
        public void GetEvents_Does_Not_Call_Repository_All_When_Cache_Available()
        {
            //arrange
            var cacheService = new DefaultMemoryCache();
            cacheService.Store("events:all", EventTestData.SingleEvent.AsQueryable());
            bool allWasCalled = false;
            var eventsRepo = new StubIRepository<Event>()
            {
                All = () =>
                {
                    allWasCalled = true;
                    return Enumerable.Empty<Event>().AsQueryable();
                }
            };
            var eventService = new EventsService(eventsRepo, cacheService);

            //Act
            var results = eventService.GetEvents();

            //Assert
            Assert.IsFalse(allWasCalled);
        }