Esempio n. 1
0
        public void SetUp()
        {
            _cachedItem = new TDataMock();
            _cacheKey = new DefaultCacheKeyConverter().ConvertCacheKey<TDataMock, int>("", _lookupKey);

            _cacheTimeout = RMM.GenerateStrictMock<ICacheTimeout>();

            _contextCacheMock = RMM.GenerateStrictMock<IContextCache>();
            _volatileCacheMock = RMM.GenerateStrictMock<IVolatileCache>();
            _longTermCacheMock = RMM.GenerateStrictMock<ILongTermCache>();

            _configurationMock = RMM.GenerateStub<IBlendedCacheConfiguration>();
            RME.Stub(_configurationMock, x => x.GetCacheTimeoutForTypeOrDefault(_cachedItem.GetType())).Return(_cacheTimeout);

            _setterMock = RMM.GenerateStrictMock<ICacheSetter>();
            RME.Stub(_setterMock, x => x.Set<TDataMock>(null, null, null, SetCacheLocation.NotSet, null, null, null)).IgnoreArguments()
                .Do(new Action<string, TDataMock, ICacheTimeout, SetCacheLocation, IContextCache, IVolatileCache, ILongTermCache>(
                    (passedCacheKey, passedCachedItem, passedTimeout, passedLocation, passedContext, passedVolatile, passedLongTerm) =>
                    {
                        _passedCacheKey = passedCacheKey;
                        _passedCachedItem = passedCachedItem;
                        _passedCacheTimeout = passedTimeout;
                        _passedCacheLocation = passedLocation;
                        _passedContextCache = passedContext;
                        _passedVolatileCache = passedVolatile;
                        _passedLongTermCache = passedLongTerm;
                    }));
        }
Esempio n. 2
0
        public void SetUp()
        {
            _passedVolatileCacheEntry = null;
            _passedVolatileCacheEntry = null;
            _passedLongTermCacheEntry = null;
            _passedLongTermCacheEntry = null;
            _location = SetCacheLocation.NotSet;
            _cacheKey = "my cacheKey";
            _cachedItem = new TDataMock();
            _cacheTimeout = new DefaultCacheTimeout();

            _contextCacheMock = RMM.GenerateStrictMock<IContextCache>();
            RME.Stub(_contextCacheMock, x => x.Set<TDataMock>(_cacheKey, _cachedItem));

            _volatileCacheMock = RMM.GenerateStrictMock<IVolatileCache>();
            RME.Stub(_volatileCacheMock, x => x.Set<TDataMock>(_cacheKey, null)).IgnoreArguments().Do(new Action<string, IVolatileCacheEntry<TDataMock>>((cacheKey, cacheEntry) =>
                {
                    _passedVolatileCacheEntry = cacheEntry;
                    _passedVolatileCacheKey = cacheKey;
                }));

            _longTermCacheMock = RMM.GenerateStrictMock<ILongTermCache>();
            RME.Stub(_longTermCacheMock, x => x.Set<TDataMock>(_cacheKey, null)).IgnoreArguments().Do(new Action<string, ILongTermCacheEntry<TDataMock>>((cacheKey, cacheEntry) =>
            {
                _passedLongTermCacheEntry = cacheEntry;
                _passedLongTermCacheKey = cacheKey;
            }));
        }
Esempio n. 3
0
        public void when_CacheLocation_is_LongTerm_should_set_ContextCache()
        {
            _location = SetCacheLocation.LongTermCache;

            Execute();

            RME.AssertWasCalled(_contextCacheMock, x => x.Set<TDataMock>(_cacheKey, _cachedItem), opt => opt.Repeat.Once());
        }
Esempio n. 4
0
        public void when_CacheLocation_is_Context_should_set_ContextCache()
        {
            _volatileCacheMock = RMM.GenerateStrictMock<IVolatileCache>();
            _longTermCacheMock = RMM.GenerateStrictMock<ILongTermCache>();

            _location = SetCacheLocation.ContextCache;

            Execute();

            RME.AssertWasCalled(_contextCacheMock, x => x.Set<TDataMock>(_cacheKey, _cachedItem), opt => opt.Repeat.Once());
        }
Esempio n. 5
0
        public void when_CacheLocation_is_LongTerm_should_set_LongTermCache()
        {
            _location = SetCacheLocation.LongTermCache;

            Execute();

            RME.AssertWasCalled(_longTermCacheMock, x => x.Set<TDataMock>(null, null), opt => opt.IgnoreArguments().Repeat.Once());
        }
Esempio n. 6
0
        public void when_CacheLocation_is_Volatile_should_set_VolatileCache_with_correct_ExpirationDateTimeUtc()
        {
            _location = SetCacheLocation.VolatileCache;

            Execute();

            Assert.NotNull(_passedVolatileCacheEntry);
            Assert.Less(DateTime.UtcNow, _passedVolatileCacheEntry.ExpirationDateTimeUtc);
        }
Esempio n. 7
0
        public void when_CacheLocation_is_Volatile_should_set_VolatileCache_with_correct_CacheKey()
        {
            _location = SetCacheLocation.VolatileCache;

            Execute();

            Assert.NotNull(_passedVolatileCacheKey);
            Assert.AreEqual(_cacheKey, _passedVolatileCacheKey);
        }
Esempio n. 8
0
        public void when_CacheLocation_is_Volatile_should_set_VolatileCache()
        {
            _location = SetCacheLocation.VolatileCache;

            Execute();

            RME.AssertWasCalled(_volatileCacheMock, x => x.Set<TDataMock>(_cacheKey, null), opt => opt.IgnoreArguments().Repeat.Once());
        }
Esempio n. 9
0
        public void when_CacheLocation_is_NotSet_should_not_call_anything()
        {
            _contextCacheMock = RMM.GenerateStrictMock<IContextCache>();
            _volatileCacheMock = RMM.GenerateStrictMock<IVolatileCache>();
            _longTermCacheMock = RMM.GenerateStrictMock<ILongTermCache>();

            _location = SetCacheLocation.NotSet;

            Execute();

            //the fact it doesn't thrown an exception means it wasn't called.
        }
Esempio n. 10
0
        public void when_CacheLocation_is_LongTerm_should_set_VolatileCache_With_correct_CacheEntry()
        {
            _location = SetCacheLocation.LongTermCache;

            Execute();

            Assert.NotNull(_passedVolatileCacheEntry);
            Assert.AreEqual(_cachedItem, _passedVolatileCacheEntry.CachedItem);
        }
Esempio n. 11
0
        public void when_CacheLocation_is_LongTerm_should_set_LongTermCache_with_correct_RefreshDateTimeUtc()
        {
            _location = SetCacheLocation.LongTermCache;

            Execute();

            Assert.NotNull(_passedLongTermCacheEntry);
            Assert.GreaterOrEqual(DateTime.UtcNow.AddSeconds(_cacheTimeout.LongTermRefreshInSeconds), _passedLongTermCacheEntry.RefreshDateTimeUtc);
        }
Esempio n. 12
0
        public void when_CacheLocation_is_LongTerm_should_set_LongTermCache_With_correct_CacheKey()
        {
            _location = SetCacheLocation.LongTermCache;

            Execute();

            Assert.NotNull(_passedLongTermCacheKey);
            Assert.AreEqual(_cacheKey, _passedLongTermCacheKey);
        }