public void ShouldGetItem_Correctly()
        {
            var cachingService = new HttpRuntimeCacheService();
            const string key = "TEST_CACHEKEY_3";
            ClearCache(key);
            var cacheObject = new CacheObject(key);

            HttpRuntime.Cache.Add(key, cacheObject, null, DateTime.Now.Add(TimeSpan.FromMinutes(1)), Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null);

            var cachedItem = cachingService.Get<CacheObject>(key);
            Assert.AreEqual(cachedItem, cacheObject);
        }
Esempio n. 2
0
        public void ShouldGetItem_Correctly()
        {
            var          cachingService = new HttpRuntimeCacheService();
            const string key            = "TEST_CACHEKEY_3";

            ClearCache(key);
            var cacheObject = new CacheObject(key);

            HttpRuntime.Cache.Add(key, cacheObject, null, DateTime.Now.Add(TimeSpan.FromMinutes(1)), Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null);

            var cachedItem = cachingService.Get <CacheObject>(key);

            Assert.AreEqual(cachedItem, cacheObject);
        }
        public void ShouldGetItem_WithDelegate_WithExpiration_Correctly()
        {
            var timespan = TimeSpan.FromSeconds(3);
            var cachingService = new HttpRuntimeCacheService();
            const string key = "TEST_CACHEKEY_5";
            ClearCache(key);
            var cacheObject = new CacheObject(key);

            Assert.IsNull(HttpRuntime.Cache[key]);
            var cachedItem = cachingService.Get(key, timespan, () => cacheObject);
            Assert.AreEqual(cachedItem, cacheObject);
            Assert.AreEqual(HttpRuntime.Cache[key], cacheObject);

            System.Threading.Thread.Sleep(timespan);
            Assert.IsNull(HttpRuntime.Cache[key]);
        }
Esempio n. 4
0
        public void ShouldGetItem_WithDelegate_WithExpiration_Correctly()
        {
            var          timespan       = TimeSpan.FromSeconds(3);
            var          cachingService = new HttpRuntimeCacheService();
            const string key            = "TEST_CACHEKEY_5";

            ClearCache(key);
            var cacheObject = new CacheObject(key);

            Assert.IsNull(HttpRuntime.Cache[key]);
            var cachedItem = cachingService.Get(key, timespan, () => cacheObject);

            Assert.AreEqual(cachedItem, cacheObject);
            Assert.AreEqual(HttpRuntime.Cache[key], cacheObject);

            System.Threading.Thread.Sleep(timespan);
            Assert.IsNull(HttpRuntime.Cache[key]);
        }