Exemplo 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;
                    }));
        }
        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>();
        }
        public void SetUp()
        {
            _cachedItem = new CachedData();
            var existingCachedItem = new CachedData();

            _cacheKeyProvider = new DefaultCacheKeyConverter();
            _cacheKey = _cacheKeyProvider.ConvertCacheKey<CachedData, string>("", _lookupKey);
            _contextCache = new DictionaryContextCache(_cacheKey, existingCachedItem);
            _volatileCache = new DictionaryVolatileCache(_cacheKey, existingCachedItem);
            _longTermCache = new DictionaryLongTermCache(_cacheKey, existingCachedItem);

            _configuration = new BlendedCacheConfiguration();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Will get a blended cache under the default conditions.
        /// </summary>
        /// <returns></returns>
        public static BlendedCache GetCache(IContextCache contextCache = null, IVolatileCache volatileCache = null, ILongTermCache longTermCache = null, IBlendedCacheConfiguration configuration = null, bool initialFlushMode = false)
        {
            if(contextCache == null)
                contextCache = new DictionaryContextCache();
            if(volatileCache == null)
                volatileCache = new DictionaryVolatileCache();
            if(longTermCache == null)
                longTermCache = new DictionaryLongTermCache();
            if(configuration == null)
                configuration = new BlendedCacheConfiguration();

            var cache = new BlendedCache(contextCache, volatileCache, longTermCache, configuration);

            if (initialFlushMode)
                cache.GetType().GetField("_flushMode", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(cache, true);

            return cache;
        }
        public void should_always_pass_CacheKeyRoot_to_FixUpCacheKey()
        {
            var cacheKeyRoot = "root";
            _configurationMock = RMM.GenerateStrictMock<IBlendedCacheConfiguration>();
            RME.Stub(_configurationMock, x => x.CacheKeyRoot).Return(cacheKeyRoot);
            RME.Stub(_configurationMock, x => x.GetCacheTimeoutForTypeOrDefault(typeof(TDataMock))).Return(_cacheTimeout);
            RME.Stub(_cacheKeyConverterMock, x => x.ConvertCacheKey<TDataMock, string>(cacheKeyRoot, _lookupKey)).Return(_fixedUpCacheKey);

            Execute();

            RME.AssertWasCalled(_cacheKeyConverterMock, x => x.ConvertCacheKey<TDataMock, string>(cacheKeyRoot, _lookupKey), opt => opt.Repeat.Once());
        }