public void Load_ConfigServerReturnsBadStatus_FailFastEnabled_RetryEnabled() { // Arrange IHostingEnvironment envir = new HostingEnvironment(); TestConfigServerStartup.Reset(); TestConfigServerStartup.ReturnStatus = new int[] { 500, 500, 500, 500, 500, 500 }; var builder = new WebHostBuilder().UseStartup <TestConfigServerStartup>().UseEnvironment(envir.EnvironmentName); var server = new TestServer(builder); ConfigServerClientSettings settings = new ConfigServerClientSettings { Uri = "http://localhost:8888", Name = "myName", FailFast = true, RetryEnabled = true }; server.BaseAddress = new Uri(settings.Uri); ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, server.CreateClient()); // Act and Assert var ex = Assert.Throws <ConfigServerException>(() => provider.LoadInternal()); Assert.Equal(6, TestConfigServerStartup.RequestCount); }
public void Load_MultipleConfigServers_ReturnsNotFoundStatus__DoesNotContinueChecking_FailFastEnabled() { // Arrange IHostingEnvironment envir = new HostingEnvironment(); TestConfigServerStartup.Reset(); TestConfigServerStartup.ReturnStatus = new int[] { 404, 200 }; var builder = new WebHostBuilder().UseStartup <TestConfigServerStartup>().UseEnvironment(envir.EnvironmentName); var server = new TestServer(builder); ConfigServerClientSettings settings = new ConfigServerClientSettings { Uri = "http://localhost:8888, http://localhost:8888 ", Name = "myName", FailFast = true }; server.BaseAddress = new Uri("http://localhost:8888"); ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, server.CreateClient()); // Act and Assert var ex = Assert.Throws <ConfigServerException>(() => provider.LoadInternal()); Assert.Equal(1, TestConfigServerStartup.RequestCount); }
public void Load_ConfigServerReturnsNotFoundStatus() { // Arrange IHostingEnvironment envir = new HostingEnvironment(); TestConfigServerStartup.Reset(); TestConfigServerStartup.ReturnStatus = new int[] { 404 }; var builder = new WebHostBuilder().UseStartup <TestConfigServerStartup>().UseEnvironment(envir.EnvironmentName); var server = new TestServer(builder); ConfigServerClientSettings settings = new ConfigServerClientSettings { Uri = "http://localhost:8888", Name = "myName" }; server.BaseAddress = new Uri(settings.Uri); ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, server.CreateClient()); // Act and Assert provider.LoadInternal(); Assert.NotNull(TestConfigServerStartup.LastRequest); Assert.Equal("/" + settings.Name + "/" + settings.Environment, TestConfigServerStartup.LastRequest.Path.Value); Assert.Equal(26, provider.Properties.Count); }
public void Load_MultipleConfigServers_ReturnsGreaterThanEqualBadRequest_StopsChecking() { // Arrange IHostingEnvironment envir = new HostingEnvironment(); TestConfigServerStartup.Reset(); TestConfigServerStartup.ReturnStatus = new int[] { 500, 200 }; var builder = new WebHostBuilder().UseStartup <TestConfigServerStartup>().UseEnvironment(envir.EnvironmentName); var server = new TestServer(builder); ConfigServerClientSettings settings = new ConfigServerClientSettings { Uri = "http://localhost:8888, http://localhost:8888", Name = "myName" }; server.BaseAddress = new Uri("http://localhost:8888"); ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, server.CreateClient()); // Act and Assert provider.LoadInternal(); Assert.NotNull(TestConfigServerStartup.LastRequest); Assert.Equal("/" + settings.Name + "/" + settings.Environment, TestConfigServerStartup.LastRequest.Path.Value); Assert.Equal(1, TestConfigServerStartup.RequestCount); }
public void Load_ChangesDataDictionary() { // Arrange var environment = @" { 'name': 'testname', 'profiles': ['Production'], 'label': 'testlabel', 'version': 'testversion', 'propertySources': [ { 'name': 'source', 'source': { 'key1': 'value1', 'key2': 10 } } ] }"; IHostingEnvironment envir = new HostingEnvironment(); TestConfigServerStartup.Reset(); TestConfigServerStartup.Response = environment; var builder = new WebHostBuilder().UseStartup <TestConfigServerStartup>().UseEnvironment(envir.EnvironmentName); var server = new TestServer(builder); ConfigServerClientSettings settings = new ConfigServerClientSettings { Uri = "http://localhost:8888", Name = "myName" }; server.BaseAddress = new Uri(settings.Uri); ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, server.CreateClient()); // Act and Assert provider.LoadInternal(); Assert.NotNull(TestConfigServerStartup.LastRequest); Assert.Equal("/" + settings.Name + "/" + settings.Environment, TestConfigServerStartup.LastRequest.Path.Value); Assert.True(provider.TryGet("key1", out string value)); Assert.Equal("value1", value); Assert.True(provider.TryGet("key2", out value)); Assert.Equal("10", value); }
public void Load_ChangesDataDictionary() { // Arrange var environment = @" { ""name"": ""testname"", ""profiles"": [""Production""], ""label"": ""testlabel"", ""version"": ""testversion"", ""propertySources"": [ { ""name"": ""source"", ""source"": { ""key1"": ""value1"", ""key2"": 10 } } ] }"; var envir = HostingHelpers.GetHostingEnvironment(); TestConfigServerStartup.Reset(); TestConfigServerStartup.Response = environment; var builder = new WebHostBuilder().UseStartup <TestConfigServerStartup>().UseEnvironment(envir.EnvironmentName); var server = new TestServer(builder); var settings = new ConfigServerClientSettings { Uri = "http://localhost:8888", Name = "myName" }; server.BaseAddress = new Uri(settings.Uri); var provider = new ConfigServerConfigurationProvider(settings, server.CreateClient()); // Act and Assert provider.LoadInternal(); Assert.NotNull(TestConfigServerStartup.LastRequest); Assert.Equal("/" + settings.Name + "/" + settings.Environment, TestConfigServerStartup.LastRequest.Path.Value); Assert.True(provider.TryGet("key1", out var value)); Assert.Equal("value1", value); Assert.True(provider.TryGet("key2", out value)); Assert.Equal("10", value); }