예제 #1
0
        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);
        }
예제 #2
0
        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();
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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();
        }
예제 #6
0
        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);
        }