public void CacheWithBlobYieldsCachedBlob() { MockCache cache = new MockCache(); var cache_span = new TimeSpan(1, 0, 0); cache.Insert(blob_uri.ToString(), cached_blob_contents, null, Cache.NoAbsoluteExpiration, cache_span, CacheItemPriority.Normal, null); var indirect_fetch = CacheUtils.RetrieveBlobAndEtagFromServerCacheOrUri(cache, blob_uri); Assert.AreEqual(indirect_fetch["response_body"], cached_blob_contents); }
public void RetrieveUncachedBlobYieldsBlob() { MockCache cache = new MockCache(); var direct_fetch = HttpUtils.FetchUrl(blob_uri).bytes; var indirect_fetch = CacheUtils.RetrieveBlobAndEtagFromServerCacheOrUri(cache, blob_uri)["response_body"]; Assert.AreEqual(indirect_fetch, direct_fetch); }
public void OkToRemoveNonExistingObject() { var cache = new MockCache(); var cache_span = new TimeSpan(0, 0, 2); var key = blob_uri.ToString(); cache.Remove(key); Assert.That(cache[key] == null); }
public void ItemInCacheIfWithinSlidingExpiration() { var cache = new MockCache(); var sliding_expiration = new TimeSpan(0, 0, 5); var key = view_uri.ToString(); cache.Insert(key, view_contents, null, Cache.NoAbsoluteExpiration, sliding_expiration, CacheItemPriority.Normal, null); Assert.AreEqual(cache[key], view_contents); }
public void RemovedObjectIsGone() { var cache = new MockCache(); var cache_span = new TimeSpan(0, 0, 2); var key = blob_uri.ToString(); cache.Insert(key, view_contents, null, Cache.NoAbsoluteExpiration, cache_span, CacheItemPriority.Normal, null); cache.Remove(key); Assert.That(cache[key] == null); }
public void ItemGoneFromCacheIfBeyondSlidingExpiration() { var cache = new MockCache(); var sliding_expiration = new TimeSpan(0, 0, 1); var key = view_uri.ToString(); cache.Insert(key, view_contents, null, Cache.NoAbsoluteExpiration, sliding_expiration, CacheItemPriority.Normal, null); HttpUtils.Wait(2); Assert.AreNotEqual(cache[key], view_contents); }
public void PurgeIsSuccessful() { var cache = new MockCache(); var cache_span = new TimeSpan(1, 0, 0); var key = blob_uri.ToString(); cache.Insert(key, view_contents, null, Cache.NoAbsoluteExpiration, cache_span, CacheItemPriority.Normal, null); CacheUtils.MarkBaseCacheEntryForRemoval(key, 2); var purgeable_dicts = CacheUtils.FetchPurgeableCacheDicts(); var test_dict = purgeable_dicts.Find(d => (string)d["cached_uri"] == key); Assert.That((int)test_dict["count"] == 2); CacheUtils.MaybePurgeCache(cache); Assert.That(cache[key] == null); purgeable_dicts = CacheUtils.FetchPurgeableCacheDicts(); test_dict = purgeable_dicts.Find(d => (string)d["cached_uri"] == key); Assert.That((int)test_dict["count"] == 1); }
public void ExpiredObjectIsGone() { var cache = new MockCache(); var cache_span = new TimeSpan(0, 0, 2); var key = blob_uri.ToString(); cache.Insert(key, view_contents, null, Cache.NoAbsoluteExpiration, cache_span, CacheItemPriority.Normal, null); HttpUtils.Wait(5); Assert.That(cache[blob_uri.ToString()] == null); }
public void ResponseBodySuppressedForViewIfRequestIfNoneMatchEqualsResponseEtagAndItemIsCached() { var headers = new System.Net.WebHeaderCollection() { { "If-None-Match", view_etag } }; var mock_controller_context = CacheUtilsTest.SetupMockControllerHeaders(headers); var cache = new MockCache(); cache[view_uri.ToString()] = view_contents; var response = CacheUtils.MaybeSuppressResponseBodyForView(mock_controller_context, view_contents); Assert.AreEqual(new byte[0], response); }