public void If_server_is_down_and_cache_is_empty_a_config_access_exception_should_be_thrown() { _mockConfigServiceHttpClient = HttpClientTestHelper.CreateClientSimulatingABadAddress(); var testFactory = new ConfigProviderFactory(TestAssemblyName, _mockConfigServiceHttpClient, _mockFileSystem.Object); // This validator would cause an error, but the simulated connection issue above should prevent it from hitting that. var validators = new Dictionary <string, Func <string, bool> > { { "Taco", x => true } }; IConfigProvider configProvider = testFactory.Create(TestComponentName, validators); configProvider.GetAndValidateConfiguration(); }
public void Config_should_always_come_from_cache_if_server_is_down() { ConfigRoot configFromMockCache = MockHabitatServer.GetConfigRoot(TestComponentName); configFromMockCache.Data.Children[0].Value = "fromcache"; CreateMockDurableCacheEntry(configFromMockCache); _mockConfigServiceHttpClient = HttpClientTestHelper.CreateClientSimulatingABadAddress(); var testFactory = new ConfigProviderFactory(TestAssemblyName, _mockConfigServiceHttpClient, _mockFileSystem.Object); IConfigProvider configProvider = testFactory.Create(TestComponentName, new Dictionary <string, Func <string, bool> >()); ConfigRoot config = configProvider.GetAndValidateConfiguration(); Dictionary <string, string> dictionary = config.Data.ToDictionary(); Assert.AreEqual("fromcache", dictionary[string.Format("{0}.N1", TestComponentName)]); }
public void Test_provider_behavior_when_config_service_address_does_not_resolve() { var provider = new ConfigServiceProvider(ResourceUrlTemplate, HttpClientTestHelper.CreateClientSimulatingABadAddress()); ConfigServiceResponse response = provider.GetConfig(); Assert.IsNotNull(response); Assert.IsNotNull(response.Config); Assert.AreEqual(ResourceUrlTemplate, response.Config.ComponentName); Assert.AreEqual(default(DateTime), response.Config.LastModified); Assert.IsNull(response.Config.Data); Assert.AreEqual(default(HttpStatusCode), response.StatusCode); Assert.IsNotNull(response.Exception); Assert.AreEqual(typeof(UnableToAccessConfigurationException), response.Exception.GetType()); Assert.AreEqual(typeof(AggregateException), response.Exception.InnerException.GetType()); }
public void Config_data_in_cache_should_always_be_validated() { ConfigRoot configFromMockCache = MockHabitatServer.GetConfigRoot(TestComponentName); configFromMockCache.Data.Children[0].Value = "fromcache"; CreateMockDurableCacheEntry(configFromMockCache); // In this case, we have to bypass validation of the service data because the service is offline _mockConfigServiceHttpClient = HttpClientTestHelper.CreateClientSimulatingABadAddress(); var testFactory = new ConfigProviderFactory(TestAssemblyName, _mockConfigServiceHttpClient, _mockFileSystem.Object); var validators = new Dictionary <string, Func <string, bool> > { { "N1.N1", x => false }, { "N1.N2", x => false } }; IConfigProvider configProvider = testFactory.Create(TestComponentName, validators); configProvider.GetAndValidateConfiguration(); }