public void GetConfigServerUri_NoLabel() { // Arrange ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase() { Name = "myName", Environment = "Production" }; ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings); // Act and Assert string path = provider.GetConfigServerUri(null); Assert.Equal(settings.RawUri + settings.Name + "/" + settings.Environment, path); }
public async void RemoteLoadAsync_ConfigServerReturnsGood() { // Arrange var environment = @" { 'name': 'testname', 'profiles': ['Production'], 'label': 'testlabel', 'version': 'testversion', 'propertySources': [ { 'name': 'source', 'source': { 'key1': 'value1', 'key2': 10 } } ] }"; var startup = new TestConfigServerStartup(environment, 200); var server = TestServer.Create(startup.Configure); ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase(); settings.Uri ="http://localhost:8888"; settings.Name = "myName"; server.BaseAddress = new Uri(settings.Uri); ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings, server.CreateClient()); string path = provider.GetConfigServerUri(null); // Act and Assert Environment env = await provider.RemoteLoadAsync(path); Assert.NotNull(startup.LastRequest); Assert.Equal("/" + settings.Name + "/" + settings.Environment, startup.LastRequest.Path.Value); Assert.NotNull(env); Assert.Equal("testname", env.Name); Assert.NotNull(env.Profiles); Assert.Equal(1, env.Profiles.Count); Assert.Equal("testlabel", env.Label); Assert.Equal("testversion", env.Version); Assert.NotNull(env.PropertySources); Assert.Equal(1, env.PropertySources.Count); Assert.Equal("source", env.PropertySources[0].Name); Assert.NotNull(env.PropertySources[0].Source); Assert.Equal(2, env.PropertySources[0].Source.Count); Assert.Equal("value1", env.PropertySources[0].Source["key1"]); Assert.Equal((long)10, env.PropertySources[0].Source["key2"]); }
public void GetRequestMessage_AddsBasicAuthIfPassword() { ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase(); settings.Uri = "http://*****:*****@localhost:8888/"; settings.Name = "foo"; settings.Environment = "development"; ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings); string requestURI = provider.GetConfigServerUri(null); var request = provider.GetRequestMessage(requestURI); Assert.Equal(HttpMethod.Get, request.Method); Assert.Equal(requestURI, request.RequestUri.ToString()); Assert.NotNull(request.Headers.Authorization); Assert.Equal("Basic", request.Headers.Authorization.Scheme); Assert.Equal(provider.GetEncoded("user", "password"), request.Headers.Authorization.Parameter); }
public async void RemoteLoadAsync_ConfigServerReturnsLessThanBadRequest() { // Arrange var startup = new TestConfigServerStartup("", 204); var server = TestServer.Create(startup.Configure); ConfigServerClientSettingsBase settings = new ConfigServerClientSettingsBase(); settings.Uri = "http://localhost:8888"; settings.Name = "myName"; server.BaseAddress = new Uri(settings.Uri); ConfigServerConfigurationProviderBase provider = new ConfigServerConfigurationProviderBase(settings, server.CreateClient()); string path = provider.GetConfigServerUri(null); // Act and Assert Environment result = await provider.RemoteLoadAsync(path); Assert.NotNull(startup.LastRequest); Assert.Equal("/" + settings.Name + "/" + settings.Environment, startup.LastRequest.Path.Value); Assert.Null(result); }