public void GetValue_WhenTheCacheIsFull_ShouldPushTheLeastRecentlyUsedOff() { var service = MockRepository.GenerateMock<IService>(); var cache = new RefreshingCache(service, 2, 1); service.Expect(x => x.GetValue("key1")) .Return(string.Empty) .Repeat.Times(2); service.Expect(x => x.GetValue("key2")) .Return(string.Empty) .Repeat.Times(1); service.Expect(x => x.GetValue("key3")) .Return(string.Empty) .Repeat.Times(1); cache.GetValue("key1"); cache.GetValue("key2"); cache.GetValue("key3"); cache.GetValue("key1"); service.VerifyAllExpectations(); }
public void RefreshingCacheIndexer_SimpleIntegerValue_ShouldPass() { var systemTime = new Time(); var cache = new RefreshingCache <int, string>(CacheSize, ExpirationTime, new DataStorage(), systemTime); var actual = cache[0]; Assert.Equal("0", actual); }
public void WhenGetValueTheFirstTime_ShouldCallTheRemoteService() { var service = MockRepository.GenerateMock<IService>(); var cache = new RefreshingCache(service, 5, 5); cache.GetValue("Test"); service.AssertWasCalled(x => x.GetValue("Test")); }
public void WhenGetValueMoreThanOneTime_ShouldOnCallTheProxyOnce() { var service = MockRepository.GenerateMock<IService>(); var cache = new RefreshingCache(service, 5, 5); service.Expect(x => x.GetValue("Test")) .Return(string.Empty) .Repeat.Once(); cache.GetValue("Test"); service.VerifyAllExpectations(); }
public void RefreshingCacheIndexer_WhenCacheSizeMoreThanMaxSize_ShouldPass() { var systemTime = new Time(); var cache = new RefreshingCache <int, string>(CacheSize, ExpirationTime, new DataStorage(), systemTime); for (int i = 0; i < 20; ++i) { ++systemTime.CurrentTime; var temp = cache[i]; } Assert.Equal(CacheSize, cache.Count); }
public void GetValue_WhenTheCacheIsStale_ShouldCallTheRemoteProxy() { var service = MockRepository.GenerateMock<IService>(); var cache = new RefreshingCache(service, 5, 1); service.Expect(x => x.GetValue("Test")) .Return(string.Empty) .Repeat.Twice(); cache.GetValue("Test"); Thread.Sleep(1000); cache.GetValue("Test"); service.VerifyAllExpectations(); }
public void RefreshingCacheIndexer_WhenTimeIsUp_ShouldPass() { var systemTime = new Time(); var dataStorage = new DataStorage(); string temp; var cache = new RefreshingCache <int, string>(CacheSize, ExpirationTime, dataStorage, systemTime); for (int i = 0; i < 16; ++i) { ++systemTime.CurrentTime; temp = cache[i]; } systemTime.CurrentTime = TimeMoreThanMax; //we add new data with key "17". It replaces data with key "0" because our time expired. temp = cache[17]; //And when we try get data with key "0", cache gets it from dataStorage, because it was deleted early. temp = cache[0]; Assert.Equal("0", dataStorage.LastData); }