mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-08-04 14:38:30 +08:00
Feature/base url in config (#234)
* started moving baseurl to config issue 233 * fixed test
This commit is contained in:
@ -152,7 +152,6 @@ namespace Ocelot.AcceptanceTests
|
||||
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
|
||||
config.AddJsonFile("configuration.json");
|
||||
config.AddOcelotBaseUrl(_baseUrl);
|
||||
config.AddEnvironmentVariables();
|
||||
})
|
||||
.ConfigureServices(s =>
|
||||
@ -189,7 +188,6 @@ namespace Ocelot.AcceptanceTests
|
||||
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
|
||||
config.AddJsonFile("configuration.json");
|
||||
config.AddOcelotBaseUrl(_baseUrl);
|
||||
config.AddEnvironmentVariables();
|
||||
})
|
||||
.ConfigureServices(s =>
|
||||
@ -227,7 +225,6 @@ namespace Ocelot.AcceptanceTests
|
||||
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
|
||||
config.AddJsonFile("configuration.json");
|
||||
config.AddOcelotBaseUrl(_baseUrl);
|
||||
config.AddEnvironmentVariables();
|
||||
})
|
||||
.ConfigureServices(s =>
|
||||
@ -256,7 +253,6 @@ namespace Ocelot.AcceptanceTests
|
||||
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
|
||||
config.AddJsonFile("configuration.json");
|
||||
config.AddOcelotBaseUrl(_baseUrl);
|
||||
config.AddEnvironmentVariables();
|
||||
})
|
||||
.ConfigureServices(s =>
|
||||
|
@ -74,13 +74,19 @@ namespace Ocelot.IntegrationTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_response_200_with_call_re_routes_controller_using_base_url_added_in_memory_with_no_webhostbuilder_registered()
|
||||
public void should_return_response_200_with_call_re_routes_controller_using_base_url_added_in_file_config()
|
||||
{
|
||||
_httpClient = new HttpClient();
|
||||
_ocelotBaseUrl = "http://localhost:5011";
|
||||
_httpClient.BaseAddress = new Uri(_ocelotBaseUrl);
|
||||
|
||||
var configuration = new FileConfiguration();
|
||||
var configuration = new FileConfiguration
|
||||
{
|
||||
GlobalConfiguration = new FileGlobalConfiguration
|
||||
{
|
||||
BaseUrl = _ocelotBaseUrl
|
||||
}
|
||||
};
|
||||
|
||||
this.Given(x => GivenThereIsAConfiguration(configuration))
|
||||
.And(x => GivenOcelotIsRunningWithNoWebHostBuilder(_ocelotBaseUrl))
|
||||
@ -457,7 +463,6 @@ namespace Ocelot.IntegrationTests
|
||||
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
|
||||
config.AddJsonFile("configuration.json");
|
||||
config.AddOcelotBaseUrl(baseUrl);
|
||||
config.AddEnvironmentVariables();
|
||||
})
|
||||
.ConfigureServices(x =>
|
||||
@ -610,7 +615,6 @@ namespace Ocelot.IntegrationTests
|
||||
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
|
||||
config.AddJsonFile("configuration.json");
|
||||
config.AddOcelotBaseUrl(_ocelotBaseUrl);
|
||||
config.AddEnvironmentVariables();
|
||||
})
|
||||
.ConfigureServices(x =>
|
||||
@ -651,7 +655,6 @@ namespace Ocelot.IntegrationTests
|
||||
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
|
||||
config.AddJsonFile("configuration.json");
|
||||
config.AddOcelotBaseUrl(baseUrl);
|
||||
config.AddEnvironmentVariables();
|
||||
})
|
||||
.ConfigureServices(x => {
|
||||
|
@ -109,7 +109,6 @@ namespace Ocelot.IntegrationTests
|
||||
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
|
||||
config.AddJsonFile("configuration.json");
|
||||
config.AddOcelotBaseUrl(_ocelotBaseUrl);
|
||||
config.AddEnvironmentVariables();
|
||||
})
|
||||
.ConfigureServices(x =>
|
||||
|
@ -22,8 +22,7 @@ namespace Ocelot.ManualTest
|
||||
.AddJsonFile("appsettings.json", true, true)
|
||||
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
|
||||
.AddJsonFile("configuration.json")
|
||||
.AddEnvironmentVariables()
|
||||
.AddOcelotBaseUrl("http://localhost:5000");
|
||||
.AddEnvironmentVariables();
|
||||
})
|
||||
.ConfigureServices(s => {
|
||||
|
||||
|
@ -15,46 +15,62 @@ namespace Ocelot.UnitTests.Middleware
|
||||
{
|
||||
public class BaseUrlFinderTests
|
||||
{
|
||||
private readonly BaseUrlFinder _baseUrlFinder;
|
||||
private readonly Mock<IConfiguration> _config;
|
||||
|
||||
private BaseUrlFinder _baseUrlFinder;
|
||||
private IConfiguration _config;
|
||||
private List<KeyValuePair<string, string>> _data;
|
||||
private string _result;
|
||||
|
||||
public BaseUrlFinderTests()
|
||||
{
|
||||
_config = new Mock<IConfiguration>();
|
||||
_baseUrlFinder = new BaseUrlFinder(_config.Object);
|
||||
_data = new List<KeyValuePair<string,string>>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_use_default_base_url()
|
||||
{
|
||||
this.Given(x => GivenTheConfigBaseUrlIs(""))
|
||||
.And(x => GivenTheConfigBaseUrlIs(""))
|
||||
.When(x => WhenIFindTheUrl())
|
||||
.Then(x => ThenTheUrlIs("http://localhost:5000"))
|
||||
.BDDfy();
|
||||
this.When(x => WhenIFindTheUrl())
|
||||
.Then(x => ThenTheUrlIs("http://localhost:5000"))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_use_file_config_base_url()
|
||||
public void should_use_memory_config_base_url()
|
||||
{
|
||||
this.Given(x => GivenTheConfigBaseUrlIs("http://localhost:7000"))
|
||||
.And(x => GivenTheConfigBaseUrlIs("http://baseurlfromconfig.com:5181"))
|
||||
this.Given(x => GivenTheMemoryBaseUrlIs("http://baseurlfromconfig.com:5181"))
|
||||
.When(x => WhenIFindTheUrl())
|
||||
.Then(x => ThenTheUrlIs("http://baseurlfromconfig.com:5181"))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void GivenTheConfigBaseUrlIs(string configValue)
|
||||
[Fact]
|
||||
public void should_use_file_config_base_url()
|
||||
{
|
||||
var configSection = new ConfigurationSection(new ConfigurationRoot(new List<IConfigurationProvider>{new MemoryConfigurationProvider(new MemoryConfigurationSource())}), "");
|
||||
configSection.Value = configValue;
|
||||
_config.Setup(x => x.GetSection(It.IsAny<string>())).Returns(configSection);
|
||||
this.Given(x => GivenTheMemoryBaseUrlIs("http://localhost:7000"))
|
||||
.And(x => GivenTheFileBaseUrlIs("http://baseurlfromconfig.com:5181"))
|
||||
.When(x => WhenIFindTheUrl())
|
||||
.Then(x => ThenTheUrlIs("http://baseurlfromconfig.com:5181"))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void GivenTheMemoryBaseUrlIs(string configValue)
|
||||
{
|
||||
_data.Add(new KeyValuePair<string, string>("BaseUrl", configValue));
|
||||
}
|
||||
|
||||
private void GivenTheFileBaseUrlIs(string configValue)
|
||||
{
|
||||
_data.Add(new KeyValuePair<string, string>("GlobalConfiguration:BaseUrl", configValue));
|
||||
}
|
||||
|
||||
private void WhenIFindTheUrl()
|
||||
{
|
||||
var source = new MemoryConfigurationSource();
|
||||
source.InitialData = _data;
|
||||
var provider = new MemoryConfigurationProvider(source);
|
||||
_config = new ConfigurationRoot(new List<IConfigurationProvider>() {
|
||||
provider
|
||||
});
|
||||
_baseUrlFinder = new BaseUrlFinder(_config);
|
||||
_result = _baseUrlFinder.Find();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user