public async Task GetNonExistingFromEmpty()
        {
            var store     = new ImmutableInMemoryCacheStore();
            var cacheKey  = new CacheKey("key", null);
            var fromCache = await store.GetAsync(cacheKey);

            // check
            Assert.AreEqual(default(CacheEntry), fromCache);
        }
        public async Task GetNonExisting()
        {
            var store = new ImmutableInMemoryCacheStore();

            var resp     = new HttpResponseMessage();
            var cacheKey = new CacheKey("key", null);

            await store.SetAsync(cacheKey, new CacheEntry(resp));

            var fromCache = await store.GetAsync("key2");

            // check
            Assert.AreEqual(default(CacheEntry), fromCache);
        }
        public async Task SetAndGetMultiple()
        {
            var store = new ImmutableInMemoryCacheStore();

            var resp  = new HttpResponseMessage();
            var resp2 = new HttpResponseMessage();

            var cacheKey  = new CacheKey("key", null);
            var cacheKey2 = new CacheKey("key2", null);

            await store.SetAsync(cacheKey, new CacheEntry(resp));

            await store.SetAsync(cacheKey2, new CacheEntry(resp2));

            var fromCache = await store.GetAsync(cacheKey);

            var fromCache2 = await store.GetAsync(cacheKey2);

            // check
            Assert.AreEqual(resp, fromCache.HttpResponse);
            // check
            Assert.AreEqual(resp2, fromCache2.HttpResponse);
        }
        public async Task SetAndGetTestCacheKeyEquality()
        {
            var store = new ImmutableInMemoryCacheStore();

            var resp = new HttpResponseMessage();

            var cacheKey = new CacheKey("key", null);
            await store.SetAsync(cacheKey, new CacheEntry(resp));

            var fromCache = await store.GetAsync(new CacheKey("key", null));

            // check
            Assert.AreEqual(resp, fromCache.HttpResponse);
        }
        public async Task SetAndGetExisting()
        {
            var store = new ImmutableInMemoryCacheStore();

            var resp     = new HttpResponseMessage();
            var cacheKey = new CacheKey("key", null);
            await store.SetAsync(cacheKey, new CacheEntry(resp));

            var respNew = new HttpResponseMessage();

            // overwrite
            await store.SetAsync(cacheKey, new CacheEntry(respNew));

            var fromCache = await store.GetAsync(cacheKey);

            // check
            Assert.AreEqual(respNew, fromCache.HttpResponse);
        }
Example #6
0
        public void GetShouldInsertInCacheStore()
        {
            var req        = new HttpRequestMessage(HttpMethod.Get, _testUri);
            var resp       = GetResponseMessage(false);
            var httpClient = InitClient();

            _mockHandler.Response = resp;

            var result = httpClient.SendAsync(req).Result;

            // result should be in cache
            var fromCache = _store.GetAsync(new CacheKey(_testUri)).Result;

            Assert.AreEqual(result, fromCache.HttpResponse);

            // result should be the same as response
            Assert.AreEqual(resp, result);
        }