예제 #1
0
        public void AddItemToCacheNoExpiration()
        {
            thisCache.Insert("key", "thisValue", TimeSpan.Zero, false);
            Assert.AreEqual(1, thisCache.Count);
            Assert.AreEqual("thisValue", aspCache.Get(thisCache.GenerateKey("key")));

            otherCache.Insert("key", "otherValue", TimeSpan.Zero, false);
            Assert.AreEqual(1, otherCache.Count);
            Assert.AreEqual("otherValue", aspCache.Get(otherCache.GenerateKey("key")));
        }
예제 #2
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();
        }
        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();
        }
예제 #4
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();
        }
        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();
        }
예제 #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();
        }
예제 #8
0
 public void DoesNotAcceptNullKeysOnInsert()
 {
     Assert.Throws <ArgumentNullException>(() => thisCache.Insert(null, "value", TimeSpan.Zero, true));
 }
예제 #9
0
 public void DoesNotAcceptNullKeysOnInsert()
 {
     thisCache.Insert(null, "value", TimeSpan.Zero, true);
 }