mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 03:18:15 +08:00
Feature/service discovery config key (#347)
* #346 make service discoery config key configurable * #346 missed this test * #346 updated docs
This commit is contained in:
@ -1,67 +1,70 @@
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Builder;
|
||||
using Ocelot.Configuration.Creator;
|
||||
using Ocelot.Configuration.File;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
public class ServiceProviderCreatorTests
|
||||
{
|
||||
private readonly ServiceProviderConfigurationCreator _creator;
|
||||
private FileGlobalConfiguration _globalConfig;
|
||||
private ServiceProviderConfiguration _result;
|
||||
|
||||
public ServiceProviderCreatorTests()
|
||||
{
|
||||
_creator = new ServiceProviderConfigurationCreator();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_create_service_provider_config()
|
||||
{
|
||||
var globalConfig = new FileGlobalConfiguration
|
||||
{
|
||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
||||
{
|
||||
Host = "127.0.0.1",
|
||||
Port = 1234,
|
||||
Type = "ServiceFabric",
|
||||
Token = "testtoken"
|
||||
}
|
||||
};
|
||||
|
||||
var expected = new ServiceProviderConfigurationBuilder()
|
||||
.WithHost("127.0.0.1")
|
||||
.WithPort(1234)
|
||||
.WithType("ServiceFabric")
|
||||
.WithToken("testtoken")
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenTheFollowingGlobalConfig(globalConfig))
|
||||
.When(x => x.WhenICreate())
|
||||
.Then(x => x.ThenTheConfigIs(expected))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void GivenTheFollowingGlobalConfig(FileGlobalConfiguration fileGlobalConfig)
|
||||
{
|
||||
_globalConfig = fileGlobalConfig;
|
||||
}
|
||||
|
||||
private void WhenICreate()
|
||||
{
|
||||
_result = _creator.Create(_globalConfig);
|
||||
}
|
||||
|
||||
private void ThenTheConfigIs(ServiceProviderConfiguration expected)
|
||||
{
|
||||
_result.Host.ShouldBe(expected.Host);
|
||||
_result.Port.ShouldBe(expected.Port);
|
||||
_result.Token.ShouldBe(expected.Token);
|
||||
_result.Type.ShouldBe(expected.Type);
|
||||
}
|
||||
}
|
||||
}
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Builder;
|
||||
using Ocelot.Configuration.Creator;
|
||||
using Ocelot.Configuration.File;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
public class ServiceProviderCreatorTests
|
||||
{
|
||||
private readonly ServiceProviderConfigurationCreator _creator;
|
||||
private FileGlobalConfiguration _globalConfig;
|
||||
private ServiceProviderConfiguration _result;
|
||||
|
||||
public ServiceProviderCreatorTests()
|
||||
{
|
||||
_creator = new ServiceProviderConfigurationCreator();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_create_service_provider_config()
|
||||
{
|
||||
var globalConfig = new FileGlobalConfiguration
|
||||
{
|
||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
||||
{
|
||||
Host = "127.0.0.1",
|
||||
Port = 1234,
|
||||
Type = "ServiceFabric",
|
||||
Token = "testtoken",
|
||||
ConfigurationKey = "woo"
|
||||
}
|
||||
};
|
||||
|
||||
var expected = new ServiceProviderConfigurationBuilder()
|
||||
.WithHost("127.0.0.1")
|
||||
.WithPort(1234)
|
||||
.WithType("ServiceFabric")
|
||||
.WithToken("testtoken")
|
||||
.WithConfigurationKey("woo")
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenTheFollowingGlobalConfig(globalConfig))
|
||||
.When(x => x.WhenICreate())
|
||||
.Then(x => x.ThenTheConfigIs(expected))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void GivenTheFollowingGlobalConfig(FileGlobalConfiguration fileGlobalConfig)
|
||||
{
|
||||
_globalConfig = fileGlobalConfig;
|
||||
}
|
||||
|
||||
private void WhenICreate()
|
||||
{
|
||||
_result = _creator.Create(_globalConfig);
|
||||
}
|
||||
|
||||
private void ThenTheConfigIs(ServiceProviderConfiguration expected)
|
||||
{
|
||||
_result.Host.ShouldBe(expected.Host);
|
||||
_result.Port.ShouldBe(expected.Port);
|
||||
_result.Token.ShouldBe(expected.Token);
|
||||
_result.Type.ShouldBe(expected.Type);
|
||||
_result.ConfigurationKey.ShouldBe(expected.ConfigurationKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user