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>();
        }
Beispiel #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;
            }));
        }
        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()
        {
            _contextCache = null;
            _volatileCache = null;

            _cacheKey = new DefaultCacheKeyConverter().ConvertCacheKey<CachedData, Guid>("", _lookupKey);
            _response = null;
            _cachedItem = new CachedData();
            _previousMetrics = BlendedCacheMetricsStore.GetCachedItemMetrics<CachedData, Guid>(_lookupKey) ?? new Metrics();
        }
Beispiel #5
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());
        }
        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();
        }
        public void SetUp()
        {
            _cacheKey = new DefaultCacheKeyConverter().ConvertCacheKey<CachedData, string>("", _lookupKey);
            _response = null;
            _contextCachedItem = new CachedData();
            _volatileCachedItem = new CachedData();
            _longTermCachedItem = new CachedData();

            _contextCache_Empty = new DictionaryContextCache();
            _contextCache_Full = new DictionaryContextCache(_cacheKey, _contextCachedItem);

            _volatileCache_Empty = new DictionaryVolatileCache();
            _volatileCache_Full = new DictionaryVolatileCache(_cacheKey, _volatileCachedItem);

            _longTermCache_Empty = new DictionaryLongTermCache();
            _longTermCache_Full = new DictionaryLongTermCache(_cacheKey, _longTermCachedItem);
        }
Beispiel #8
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 when_set_should_set_VolatileCache_WithExpiration()
        {
            _volatileCache = new DictionaryVolatileCache();

            Execute();

            Assert.AreEqual(_cachedItem, _volatileCache.Get<CachedData>(_cacheKey).CachedItem);
        }
        private void Execute(IContextCache contextCache = null, IVolatileCache volatileCache = null, ILongTermCache longTermCache = null)
        {
            var cache = TestHelpers.GetCache(contextCache, volatileCache, longTermCache, initialFlushMode: false);

            _response = cache.Get<CachedData>(_lookupKey);
        }
        private void Execute(IContextCache contextCache = null, IVolatileCache volatileCache = null, ILongTermCache longTermCache = null)
        {
            var cache = TestHelpers.GetCache(_contextCache_Full);

            _response = cache.Get<CachedData>(_lookupKey);
            _metrics = BlendedCacheMetricsStore.GetCachedItemMetrics<CachedData, string>(_lookupKey) ?? new Metrics();
        }
Beispiel #12
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.
        }
        private void Execute()
        {
            var longTermCache = new DictionaryLongTermCache(_cacheKey, _cachedItem);
            var cache = TestHelpers.GetCache(longTermCache: longTermCache);

            _contextCache = cache.GetContextCache();
            _volatileCache = cache.GetVolatileCache();

            _response = cache.Get<CachedData, Guid>(_lookupKey);

            _metrics = BlendedCacheMetricsStore.GetCachedItemMetrics<CachedData, Guid>(_lookupKey) ?? new Metrics();
        }