public async void GetAsync() { _store.Clear(); _store["FOOBAR.key1"] = 123; _store["FOOBAR.key1.TYPE"] = typeof(int).AssemblyQualifiedName; _store["FOOBAR.KEYS"] = new List <string> { "key1" }; var cache = new FoobarCache("Foobar"); Assert.True((await cache.GetAsync("key1")).Exists); Assert.Equal(123, (await cache.GetAsync("key1")).Value); await cache.ClearAsync(); Assert.False(_store.Any()); Assert.False((await cache.GetAsync("key2")).Exists); _store["FOOBAR.key2"] = Cache.NullValue.Instance; _store["FOOBAR.key2.TYPE"] = typeof(Cache.NullValue).AssemblyQualifiedName; _store["FOOBAR.KEYS"] = new List <string> { "key2" }; Assert.True((await cache.GetAsync("key2")).Exists); Assert.Null((await cache.GetAsync("key2")).Value); }
public async void ClearAsync() { _store.Clear(); _store.Add("Abc", new object()); var cache = new FoobarCache("Foobar"); await cache.SetAsync("123", new object()); await cache.SetAsync("456", new object()); await cache.SetAsync("789", new object()); Assert.True(_store.Count > 1); await cache.ClearAsync(); Assert.Equal("Abc", _store.Single().Key); }
public async void SetAsync() { _store.Clear(); var cache = new FoobarCache("Foobar"); var valule = DateTime.Now; await cache.SetAsync("123", valule); Assert.Equal(valule, _store["FOOBAR.123"]); Assert.Equal("123", ((List <string>)_store["FOOBAR.KEYS"]).Single()); Assert.Equal(typeof(DateTime).AssemblyQualifiedName, _store["FOOBAR.123.TYPE"]); await cache.ClearAsync(); await cache.SetAsync("456", null); Assert.Equal(Cache.NullValue.Instance, _store["FOOBAR.456"]); Assert.Equal("456", ((List <string>)_store["FOOBAR.KEYS"]).Single()); Assert.Equal(typeof(Cache.NullValue).AssemblyQualifiedName, _store["FOOBAR.456.TYPE"]); }