public void DumpedDataCanBeReloaded() { var cache = new CacheWithFail <string, Data>(); cache.Add("Foo", new Data { String = "Foo", Int = 1 }); cache.Add("Bar", new Data { String = "Bar", Int = 2 }); var json = cache.DumpCacheAsJson(); var newCache = new CacheWithFail <string, Data>(); newCache.LoadCacheFromJson(json); Data data; newCache.TryGetValue("Foo", out data).Should().Be(CacheState.Found); data.String.Should().Be("Foo"); data.Int.Should().Be(1); newCache.TryGetValue("Bar", out data).Should().Be(CacheState.Found); data.String.Should().Be("Bar"); data.Int.Should().Be(2); }
public async Task ClearClearsTheCacheButNotFailedItems() { var cache = new CacheWithFail <string, Data>(); cache.Add("Foo", new Data { String = "Foo", Int = 1 }); await cache.GetOrAddAsync("Bar", async s => await Task.Run(() => (Data)null)); cache.Clear(); Data data; cache.TryGetValue("Foo", out data).Should().Be(CacheState.NotFound); var called = false; await cache.GetOrAddAsync("Bar", async s => await Task.Run(() => { called = true; return((Data)null); })); called.Should().BeFalse(); }
public void DumpedDataCanBeReloaded() { var cache = new CacheWithFail<string, Data>(); cache.Add("Foo", new Data { String = "Foo", Int = 1 }); cache.Add("Bar", new Data { String = "Bar", Int = 2 }); var json = cache.DumpCacheAsJson(); var newCache = new CacheWithFail<string, Data>(); newCache.LoadCacheFromJson(json); Data data; newCache.TryGetValue("Foo", out data).Should().Be(CacheState.Found); data.String.Should().Be("Foo"); data.Int.Should().Be(1); newCache.TryGetValue("Bar", out data).Should().Be(CacheState.Found); data.String.Should().Be("Bar"); data.Int.Should().Be(2); }
public async Task ClearClearsTheCache() { var cache = new CacheWithFail <string, Data>(); cache.Add("Foo", new Data { String = "Foo", Int = 1 }); await cache.GetOrAddAsync("Bar", async s => await Task.Run(() => (Data)null)); cache.Clear(); Data data; cache.TryGetValue("Foo", out data).Should().Be(CacheState.NotFound); }
public async Task ClearClearsTheCacheButNotFailedItems() { var cache = new CacheWithFail<string, Data>(); cache.Add("Foo", new Data { String = "Foo", Int = 1 }); await cache.GetOrAddAsync("Bar", async s => await Task.Run(() => (Data)null)); cache.Clear(); Data data; cache.TryGetValue("Foo", out data).Should().Be(CacheState.NotFound); var called = false; await cache.GetOrAddAsync("Bar", async s => await Task.Run(() => { called = true; return (Data)null; })); called.Should().BeFalse(); }
public async Task ClearClearsTheCache() { var cache = new CacheWithFail<string, Data>(); cache.Add("Foo", new Data { String = "Foo", Int = 1 }); await cache.GetOrAddAsync("Bar", async s => await Task.Run(() => (Data)null)); cache.Clear(); Data data; cache.TryGetValue("Foo", out data).Should().Be(CacheState.NotFound); }