コード例 #1
0
        public void ZeroTTLCausesNoExpiration()
        {
            AspNetCache.IRuntimeCache runtimeCache = A.Fake <AspNetCache.IRuntimeCache>();
            AspNetCache cache = new AspNetCache(runtimeCache);

            CacheItemPriority expectedPriority = CacheItemPriority.Low;

            cache.Insert("key", "value", TimeSpan.Zero, true, expectedPriority);
            A.CallTo(() => runtimeCache.Insert(cache.GenerateKey("key"), "value", null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, expectedPriority, null)).MustHaveHappened();

            cache.Insert("key", "value", TimeSpan.Zero, false, expectedPriority);
            A.CallTo(() => runtimeCache.Insert(cache.GenerateKey("key"), "value", null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, expectedPriority, null)).MustHaveHappened();
        }
コード例 #2
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();

            mockedRuntimeCache = A.Fake <AspNetCache.IRuntimeCache>();
            mockedCache        = new AspNetCache(mockedRuntimeCache);
        }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
0
        public void PassesParametersToRuntimeCache()
        {
            AspNetCache.IRuntimeCache runtimeCache = A.Fake <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);

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

            A.CallTo(() => runtimeCache.Insert(cache.GenerateKey("key"), "value", null, Cache.NoAbsoluteExpiration, ttl10Seconds, expectedPriority, null)).MustHaveHappened();
        }
コード例 #6
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();
        }
コード例 #7
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();
        }