Add ability to register custom load balancers

This commit is contained in:
David Lievrouw 2019-07-10 20:59:04 +02:00
parent 80ab5f6a91
commit fd35ad0514

View File

@ -154,6 +154,42 @@ namespace Ocelot.UnitTests.DependencyInjection
.BDDfy(); .BDDfy();
} }
[Fact]
public void should_add_custom_load_balancer_creators_by_default_ctor()
{
this.Given(x => WhenISetUpOcelotServices())
.When(x => _ocelotBuilder.AddCustomLoadBalancer<FakeCustomLoadBalancer>())
.Then(x => ThenTheProviderIsRegisteredAndReturnsBothBuiltInAndCustomLoadBalancerCreators())
.BDDfy();
}
[Fact]
public void should_add_custom_load_balancer_creators_by_factory_method()
{
this.Given(x => WhenISetUpOcelotServices())
.When(x => _ocelotBuilder.AddCustomLoadBalancer(() => new FakeCustomLoadBalancer()))
.Then(x => ThenTheProviderIsRegisteredAndReturnsBothBuiltInAndCustomLoadBalancerCreators())
.BDDfy();
}
[Fact]
public void should_add_custom_load_balancer_creators_by_di_factory_method()
{
this.Given(x => WhenISetUpOcelotServices())
.When(x => _ocelotBuilder.AddCustomLoadBalancer(provider => new FakeCustomLoadBalancer()))
.Then(x => ThenTheProviderIsRegisteredAndReturnsBothBuiltInAndCustomLoadBalancerCreators())
.BDDfy();
}
[Fact]
public void should_add_custom_load_balancer_creators_by_factory_method_with_arguments()
{
this.Given(x => WhenISetUpOcelotServices())
.When(x => _ocelotBuilder.AddCustomLoadBalancer((reroute, discoveryProvider) => new FakeCustomLoadBalancer()))
.Then(x => ThenTheProviderIsRegisteredAndReturnsBothBuiltInAndCustomLoadBalancerCreators())
.BDDfy();
}
[Fact] [Fact]
public void should_replace_iplaceholder() public void should_replace_iplaceholder()
{ {
@ -168,7 +204,7 @@ namespace Ocelot.UnitTests.DependencyInjection
public void should_add_custom_load_balancer_creators() public void should_add_custom_load_balancer_creators()
{ {
this.Given(x => WhenISetUpOcelotServices()) this.Given(x => WhenISetUpOcelotServices())
.When(x => AddCustomLoadBalancer<FakeCustomLoadBalancer>()) .When(x => _ocelotBuilder.AddCustomLoadBalancer((provider, reroute, discoveryProvider) => new FakeCustomLoadBalancer()))
.Then(x => ThenTheProviderIsRegisteredAndReturnsBothBuiltInAndCustomLoadBalancerCreators()) .Then(x => ThenTheProviderIsRegisteredAndReturnsBothBuiltInAndCustomLoadBalancerCreators())
.BDDfy(); .BDDfy();
} }
@ -179,12 +215,6 @@ namespace Ocelot.UnitTests.DependencyInjection
_ocelotBuilder.AddSingletonDefinedAggregator<T>(); _ocelotBuilder.AddSingletonDefinedAggregator<T>();
} }
private void AddCustomLoadBalancer<T>()
where T : ILoadBalancer, new()
{
_ocelotBuilder.AddCustomLoadBalancer<T>();
}
private void AddTransientDefinedAggregator<T>() private void AddTransientDefinedAggregator<T>()
where T : class, IDefinedAggregator where T : class, IDefinedAggregator
{ {