public void Get()
 {
     // set expectations
     Expect.Call(mockedRuntimeCache.Get(mockedCache.GenerateKey("key"))).Return(null);
     mocks.ReplayAll();
     // verify
     mockedCache.Get("key");
     mocks.VerifyAll();
 }
Beispiel #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();
        }
Beispiel #3
0
        public void ReturnsOnlyKeysOwnedByCache()
        {
            DictionaryEntry[] mockedRuntimeCacheEntries =
            {
                new DictionaryEntry(mockedCache.GenerateKey("keyA"), null)
                ,                                                    new DictionaryEntry(mockedCache.GenerateKey("keyB"), null)
                ,                                                    new DictionaryEntry(thisCache.GenerateKey("keyC"), null)
                ,                                                    new DictionaryEntry(otherCache.GenerateKey("keyD"), null)
            };

            A.CallTo(() => mockedRuntimeCache.GetEnumerator()).Returns(mockedRuntimeCacheEntries.GetEnumerator());

            ICollection keys = mockedCache.Keys;

            CollectionAssert.AreEqual(new string[] { "keyA", "keyB" }, keys);
        }
        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();
        }
        public void ReturnsOnlyKeysOwnedByCache()
        {
            DictionaryEntry[] mockedRuntimeCacheEntries =
            {
                new DictionaryEntry(mockedCache.GenerateKey("keyA"), null)
                ,                                                    new DictionaryEntry(mockedCache.GenerateKey("keyB"), null)
                ,                                                    new DictionaryEntry(thisCache.GenerateKey("keyC"), null)
                ,                                                    new DictionaryEntry(otherCache.GenerateKey("keyD"), null)
            };

            // set expectations
            Expect.Call(mockedRuntimeCache.GetEnumerator()).Return(mockedRuntimeCacheEntries.GetEnumerator());
            mocks.ReplayAll();
            // verify
            ICollection keys = mockedCache.Keys;

            CollectionAssert.AreEqual(new string[] { "keyA", "keyB" }, keys);
            mocks.VerifyAll();
        }
Beispiel #6
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();
        }
        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();
        }
        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();
        }
Beispiel #10
0
        public void Get()
        {
            mockedCache.Get("key");

            A.CallTo(() => mockedRuntimeCache.Get(mockedCache.GenerateKey("key"))).MustHaveHappened();
        }