public void GetCache_ReturnCurrentCache() { IConfigCache configCache = MockRepository.GenerateStub <IConfigCache>(); configCache.Stub(x => x.GetCachedValue("MyCachedConfigKey")).Return("MyCachedConfigValue"); CacheableConfigController sut = new CacheableConfigController(); sut.Cache = configCache; Queue <string> priority = new Queue <string>(); priority.Enqueue("FirstPlane"); sut.Priority = priority; sut.UpsertDefaultConfigValue("FirstPlane", "ConfigKey", "ConfigValue"); Dictionary <string, string> context = new Dictionary <string, string>(); context.Add("FirstPlane", "MyConfigContext"); sut.SearchContext = context; sut.GetConfigValue("ConfigKey"); string result = sut.GetConfigValue("MyCachedConfigKey"); IConfigCache cache = sut.Cache; Assert.IsNotNull(cache); }
public void IfCacheSpecified_WillUseCachedValueIfPresent() { IConfigCache configCache = MockRepository.GenerateStub <IConfigCache>(); configCache.Stub(x => x.GetCachedValue("MyCachedConfigKey")).Return("MyCachedConfigValue"); CacheableConfigController sut = new CacheableConfigController(); sut.Cache = configCache; Queue <string> priority = new Queue <string>(); priority.Enqueue("FirstPlane"); sut.Priority = priority; sut.UpsertDefaultConfigValue("FirstPlane", "ConfigKey", "ConfigValue"); Dictionary <string, string> context = new Dictionary <string, string>(); context.Add("FirstPlane", "MyConfigContext"); sut.SearchContext = context; sut.GetConfigValue("ConfigKey"); string result = sut.GetConfigValue("MyCachedConfigKey"); Assert.That(result.Equals("MyCachedConfigValue", StringComparison.InvariantCulture)); }
public void IfCacheSpecified_UpsertingConfigValueClearsCache() { IConfigCache configCache = MockRepository.GenerateStub <IConfigCache>(); CacheableConfigController sut = new CacheableConfigController(); sut.Cache = configCache; Queue <string> priority = new Queue <string>(); priority.Enqueue("FirstPlane"); configCache.AssertWasNotCalled(x => x.ClearCache()); sut.UpsertDefaultConfigValue("FirstPlane", "ConfigKey", "ConfigValue"); configCache.AssertWasCalled(x => x.ClearCache()); }
public void IfCacheSpecifiedInProperty_CanWriteAndGetConfigValue() { CacheableConfigController sut = new CacheableConfigController(); sut.Cache = new ConfigCache(); Queue <string> priority = new Queue <string>(); priority.Enqueue("FirstPlane"); sut.Priority = priority; sut.UpsertDefaultConfigValue("FirstPlane", "ConfigKey", "ConfigValue"); Dictionary <string, string> context = new Dictionary <string, string>(); context.Add("FirstPlane", "MyConfigContext"); sut.SearchContext = context; string result = sut.GetConfigValue("ConfigKey"); Assert.NotNull(result); Assert.That(result.Equals("ConfigValue")); }
public void IfCacheSpecified_AReadResultsInKeyValueWrittenToCache() { IConfigCache configCache = MockRepository.GenerateStub <IConfigCache>(); CacheableConfigController sut = new CacheableConfigController(); sut.Cache = configCache; Queue <string> priority = new Queue <string>(); priority.Enqueue("FirstPlane"); sut.Priority = priority; sut.UpsertDefaultConfigValue("FirstPlane", "ConfigKey", "ConfigValue"); Dictionary <string, string> context = new Dictionary <string, string>(); context.Add("FirstPlane", "MyConfigContext"); sut.SearchContext = context; sut.GetConfigValue("ConfigKey"); configCache.AssertWasCalled(x => x.CacheInsert(Arg <string> .Is.Equal("ConfigKey"), Arg <string> .Is.Equal("ConfigValue"))); }