public T GetValue <T>(string key) { ICacheManager cacheManager = _cacheManagerFactory.GetCacheProvider(_refreshTimerIntervalInMs, cacheProvider); IEnumerable <ConfigurationRecord> cacheRecordDto = cacheManager.Get <IEnumerable <ConfigurationRecord> >(_applicationName); var converter = new ConfigurationConverter <T>(); if (cacheRecordDto != null && cacheRecordDto.ToList() != null && cacheRecordDto.ToList().Count > 0) { var cacheRecord = cacheRecordDto.Where(p => p.Name == key).FirstOrDefault(); bool typeMatch = TypeHelper.HasTypeMatched <T>(cacheRecord.Type); if (typeMatch) { return(converter.GetValue(cacheRecord.Value)); } else { return(default(T)); } } else { ConfigurationRecord record = _storage.GetWithKey(key, _applicationName); if (record != null) { bool typeMatch = TypeHelper.HasTypeMatched <T>(record.Type); if (typeMatch) { AddToCache(cacheManager); return(converter.GetValue(record.Value)); } else { return(default(T)); } } else { return(default(T)); } } }
public void SetUp() { _configurationStorage = Substitute.For <IConfigurationStorage>(); _configurationStorageFactory = Substitute.For <ConfigurationStorageFactory>(); _cacheManager = Substitute.For <ICacheManager>(); _cacheManagerFactory = Substitute.For <CacheManagerFactory>(); ICacheManager cacheManager = _cacheManager; IConfigurationStorage storage = _configurationStorage; _configurationStorageFactory.CreateStorage("hede", "Mongo").ReturnsForAnyArgs(storage); _cacheManagerFactory.GetCacheProvider(10, "Redis").ReturnsForAnyArgs(cacheManager); }