示例#1
0
 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);
 }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
        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);
        }
示例#8
0
        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);
        }
示例#9
0
 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);
 }
示例#10
0
 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);
 }
示例#11
0
 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);
 }
示例#12
0
 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);
 }
示例#13
0
 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);
 }
示例#14
0
 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 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);
 }