Ocelot/test/Ocelot.UnitTests/Configuration/ServiceProviderCreatorTests.cs
geffzhang 44dccf1fce kubernetes provider (#772)
* feat: Kubernetes ServiceDiscoveryProvider

* 编写k8s测试例子

* feat:fix kube config

* feat: remove port

* feat : complete the k8s test

* feat :  add kubeserviceDiscovery test

* feat : add kube provider unittest

* feat :add kubetnetes docs

how to use ocelot with kubetnetes docs

* keep the configuration as simple as possible, no qos, no cache

* fix: use http

* add PollingKubeServiceDiscovery

* feat : refactor logger

* feat : add  pollkube docs

* feat:Remove unnecessary code

* feat : code-block json
2019-01-31 07:19:32 -03:00

74 lines
2.3 KiB
C#

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",
Namespace ="default"
}
};
var expected = new ServiceProviderConfigurationBuilder()
.WithHost("127.0.0.1")
.WithPort(1234)
.WithType("ServiceFabric")
.WithToken("testtoken")
.WithConfigurationKey("woo")
.WithNamesapce("default")
.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.Namesapce.ShouldBe(expected.Namesapce);
_result.ConfigurationKey.ShouldBe(expected.ConfigurationKey);
}
}
}