public async void ReadEntry_EntryDoesNotExist_ReturnsNull() { const string cacheKey = "test-cache-key"; using (IMemoryCache memoryCache = GetMemoryCache()) { MemoryCacheAdapter memoryCacheAdapter = new MemoryCacheAdapter(memoryCache, slidingExpiration: TimeSpan.FromMinutes(1)); Assert.Null(await memoryCacheAdapter.ReadEntry <string>(cacheKey)); } }
public async void ReadEntry_EntryExists_ReturnsEntry() { const string cacheKey = "test-cache-key"; const string value = "test-value"; DateTime absoluteExpiration = new DateTime(year: 2018, month: 3, day: 17, hour: 8, minute: 0, second: 0); using (IMemoryCache memoryCache = GetMemoryCache()) using (CurrentTime.UseMockUtcNow(absoluteExpiration.AddHours(-1))) { memoryCache.Set(cacheKey, new CacheEntry <string>(value, absoluteExpiration)); MemoryCacheAdapter memoryCacheAdapter = new MemoryCacheAdapter(memoryCache, slidingExpiration: TimeSpan.FromMinutes(1)); CacheEntry <string>?cacheEntry = await memoryCacheAdapter.ReadEntry <string>(cacheKey); Assert.NotNull(cacheEntry); Assert.Equal(actual: cacheEntry !.Value, expected: value); Assert.Equal(actual: cacheEntry !.AbsoluteExpiration, expected: absoluteExpiration); } }