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() { _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 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; })); }
protected LongTermCachedDatastore( ILogger <CrmDatastoreBase <T> > logger, ISyncPolicyFactory policy, IConfiguration config, ILongTermCache cache) : base(logger, policy, config, cache) { }
public CapabilityStandardDatastore( GifInt.ICapabilityStandardDatastore crmDatastore, ILogger <CapabilityStandardDatastore> logger, ISyncPolicyFactory policy, IConfiguration config, ILongTermCache cache) : base(logger, policy, config, cache) { _crmDatastore = crmDatastore; }
public OrganisationsDatastore( GifInt.IOrganisationsDatastore crmDatastore, ILogger <OrganisationsDatastore> logger, ISyncPolicyFactory policy, IConfiguration config, ILongTermCache cache) : base(logger, policy, config, cache) { _crmDatastore = crmDatastore; }
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); }
/// <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_LongTermCache_RefreshDateTimeUtc() { _longTermCache = new DictionaryLongTermCache(); Execute(); Assert.Less(DateTime.UtcNow, _longTermCache.Get<CachedData>(_cacheKey).RefreshDateTimeUtc); }
public void when_set_should_set_LongTermCache_CachedItem() { _longTermCache = new DictionaryLongTermCache(); Execute(); Assert.AreEqual(_cachedItem, _longTermCache.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(); }
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. }