public void SetUp()
        {
            _response = null;
            _lookupKey = "my lookupKey";
            _fixedUpCacheKey = "cache key for: " + _lookupKey;
            _flushMode = null;

            _cacheTimeout = RMM.GenerateMock<ICacheTimeout>();
            _configurationMock = RMM.GenerateMock<IBlendedCacheConfiguration>();
            RME.Stub(_configurationMock, x => x.GetCacheTimeoutForTypeOrDefault(typeof(TDataMock))).Return(_cacheTimeout);

            _cacheItemMetrics = new CachedItemMetrics(_lookupKey, _fixedUpCacheKey);

            _cacheKeyConverterMock = RMM.GenerateStrictMock<ICacheKeyConverter>();
            RME.Stub(_cacheKeyConverterMock, x => x.ConvertCacheKey<TDataMock, string>(null, _lookupKey)).Do(new Func<string, string, string>((a, b) => _fixedUpCacheKey));

            _contextCachedObject = null;
            _contextCacheLookupMock = RMM.GenerateStrictMock<IContextCacheLookup>();
            RME.Stub(_contextCacheLookupMock, x => x.GetDataFromContextCache<TDataMock>(_fixedUpCacheKey)).Do(new Func<string, TDataMock>((a) => _contextCachedObject));

            _volatileCachedObject = null;
            _volatileCacheLookupMock = RMM.GenerateStrictMock<IVolatileCacheLookup>();
            RME.Stub(_volatileCacheLookupMock, x=>x.GetDataFromVolatileCache<TDataMock>(_fixedUpCacheKey, _cacheItemMetrics)).Do(new Func<string, CachedItemMetrics, TDataMock>((a, b) => _volatileCachedObject));

            _longTermCachedObject = null;
            _longTermCacheLookupMock = RMM.GenerateStrictMock<ILongTermCacheLookup>();
            RME.Stub(_longTermCacheLookupMock, x => x.GetDataFromLongTermCache<TDataMock>(_fixedUpCacheKey, _cacheItemMetrics)).Do(new Func<string, CachedItemMetrics, TDataMock>((a, b) => _longTermCachedObject));

            _cacheSetterMock = RMM.GenerateMock<ICacheSetter>();

            _contextCacheMock = RMM.GenerateMock<IContextCache>();
            _volatileCacheMock = RMM.GenerateMock<IVolatileCache>();
            _longTermCacheMock = RMM.GenerateMock<ILongTermCache>();
        }
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 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;
                    }));
        }
        private void Execute()
        {
            var cache = new BlendedCache(_contextCacheMock, _volatileCacheMock, _longTermCacheMock, _configurationMock);

            cache.SetService<IContextCacheLookup>(_contextCacheLookupMock);
            cache.SetService<IVolatileCacheLookup>(_volatileCacheLookupMock);
            cache.SetService<ILongTermCacheLookup>(_longTermCacheLookupMock);
            cache.SetService<ICacheKeyConverter>(_cacheKeyConverterMock);

            var cacheItemMetricLookup = RMM.GenerateStrictMock<ICachedItemMetricsLookup>();
            RME.Stub(cacheItemMetricLookup, x => x.GetOrCreateCacheItemMetric<TDataMock, string>(_fixedUpCacheKey, _lookupKey)).Return(_cacheItemMetrics);
            cache.SetService<ICachedItemMetricsLookup>(cacheItemMetricLookup);
            cache.SetService<ICacheSetter>(_cacheSetterMock);

            if(_flushMode.HasValue)
                cache.SetFlushMode(_flushMode.Value);

            _response = cache.Get<TDataMock>(_lookupKey);
        }
        public void when_found_in_IVolatile_should_get_CacheTimeout_from_Configuration()
        {
            _volatileCachedObject = new TDataMock();

            Execute();

            RME.AssertWasCalled(_configurationMock, x => x.GetCacheTimeoutForTypeOrDefault(typeof(TDataMock)));
        }
        public void when_found_in_IVolatileCache_should_SetLocation_ContextCache()
        {
            _volatileCachedObject = new TDataMock();

            Execute();

            RME.AssertWasCalled(_cacheSetterMock, x => x.Set<TDataMock>(_fixedUpCacheKey, _volatileCachedObject, _cacheTimeout, SetCacheLocation.ContextCache, _contextCacheMock, _volatileCacheMock, _longTermCacheMock));
        }
        public void when_found_in_IVolatileCache_should_return_cachedItem()
        {
            _volatileCachedObject = new TDataMock();

            Execute();

            Assert.AreEqual(_volatileCachedObject, _response);
        }
        public void when_found_in_IVolatileCache_should_not_call_ILongTermCacheLook()
        {
            _volatileCachedObject = new TDataMock();

            Execute();

            RME.AssertWasNotCalled(_longTermCacheLookupMock, x => x.GetDataFromLongTermCache<TDataMock>(null,null), opt => opt.IgnoreArguments());
        }
        public void when_found_in_IContextCache_and_FlushMode_should_return_cachedItem()
        {
            _flushMode = true;
            _contextCachedObject = new TDataMock();

            Execute();

            Assert.AreEqual(_contextCachedObject, _response);
        }