Пример #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 string DumpCacheAsJson()
        {
            var caches = new Dictionary <string, string>
            {
                { "_seriesCache", _seriesCache.DumpCacheAsJson() }
            };

            return(JsonConvert.SerializeObject(caches));
        }
Пример #3
0
        public string DumpCacheAsJson()
        {
            var caches = new Dictionary <string, string>
            {
                { "_movieCache", _movieCache.DumpCacheAsJson() },
                { "_movieCacheByTitle", _movieCacheByTitle.DumpCacheAsJson() },
                { "_peopleCache", _peopleCache.DumpCacheAsJson() },
                { "_tvShowCache", _tvShowCache.DumpCacheAsJson() },
                { "_tvShowCacheByTitle", _tvShowCacheByTitle.DumpCacheAsJson() }
            };

            return(JsonConvert.SerializeObject(caches));
        }
Пример #4
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);
        }