public void Remove_does_clear_cache() { var context = new TestableCacheService(); context.SutInMemoryObject.Set(new InMemoryObject("stays")); context.SutInMemoryObject.Clear(); Assert.Null(context.SutInMemoryObject.Get()); }
public void Get_does_call_func_if_provided_and_cache_empty() { var context = new TestableCacheService(); var called = false; var cache = context.SutInMemoryObject.Get(() => { called = true; return(new InMemoryObject("is.called")); }); Assert.True(called); Assert.NotNull(cache); Assert.Equal("is.called", cache.Value); }
public void Get_does_not_call_func_if_cache_present() { var context = new TestableCacheService(); context.SutInMemoryObject.Set(new InMemoryObject("stays")); var called = false; var cache = context.SutInMemoryObject.Get(() => { called = true; return(new InMemoryObject("never.reached")); }); Assert.False(called); Assert.NotNull(cache); Assert.Equal("stays", cache.Value); }
public void ClearAll_does_clear_everything() { var context = new TestableCacheService(); context.Sut.Set(typeof(InMemoryObject), new InMemoryObject("stays")); context.Sut.Set(typeof(string), "hello"); var internalCache = context.Sut.MemoryCache; context.Sut.ClearAll(); context.Sut.MemoryCache.TryGetValue(typeof(string), out object stringValue); context.Sut.MemoryCache.TryGetValue(typeof(InMemoryObject), out object testObject); Assert.Null(stringValue); Assert.Null(testObject); Assert.NotEqual(internalCache, context.Sut.MemoryCache); }
public void Get_does_return_null_if_nothing_set() { var context = new TestableCacheService(); Assert.Null(context.SutInMemoryObject.Get()); }