Пример #1
0
        public void SetUp()
        {
            // cleanup underlying static asp.net cache
            foreach (DictionaryEntry entry in HttpRuntime.Cache)
            {
                aspCache.Remove((string)entry.Key);
            }

            thisCache = new AspNetCache();
            otherCache = new AspNetCache();

            mocks = new MockRepository();
            mockedRuntimeCache = (AspNetCache.IRuntimeCache)mocks.CreateMock(typeof(AspNetCache.IRuntimeCache));
            mockedCache = new AspNetCache(mockedRuntimeCache);
        }
Пример #2
0
        public void ZeroTTLCausesNoExpiration()
        {
            MockRepository mocks = new MockRepository();
            AspNetCache.IRuntimeCache runtimeCache = (AspNetCache.IRuntimeCache)mocks.CreateMock(typeof(AspNetCache.IRuntimeCache));
            AspNetCache cache = new AspNetCache(runtimeCache);

            CacheItemPriority expectedPriority = CacheItemPriority.Low;

            runtimeCache.Insert(cache.GenerateKey("key"), "value", null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, expectedPriority, null);
            runtimeCache.Insert(cache.GenerateKey("key"), "value", null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, expectedPriority, null);

            mocks.ReplayAll();

            cache.Insert("key", "value", TimeSpan.Zero, true, expectedPriority);
            cache.Insert("key", "value", TimeSpan.Zero, false, expectedPriority);

            mocks.VerifyAll();
        }
Пример #3
0
        public void PassesParametersToRuntimeCache()
        {
            MockRepository mocks = new MockRepository();
            AspNetCache.IRuntimeCache runtimeCache = (AspNetCache.IRuntimeCache) mocks.CreateMock(typeof(AspNetCache.IRuntimeCache));            
            AspNetCache cache = new AspNetCache(runtimeCache);

            DateTime expectedAbsoluteExpiration = DateTime.Now;
            TimeSpan expectedSlidingExpiration = ttl10Seconds;
            CacheItemPriority expectedPriority = CacheItemPriority.Low;

//          TODO: find way to test non-sliding expiration case
//            runtimeCache.Insert(cache.GenerateKey("key"), "value", null, DateTime.Now.Add(ttl10Seconds), Cache.NoSlidingExpiration, expectedPriority, null);
            runtimeCache.Insert(cache.GenerateKey("key"), "value", null, Cache.NoAbsoluteExpiration, ttl10Seconds, expectedPriority, null);

            mocks.ReplayAll();

//            cache.Insert( "key", "value", ttl10Seconds, false, expectedPriority );
            cache.Insert("key", "value", ttl10Seconds, true, expectedPriority);

            mocks.VerifyAll();
        }