Skip to content

Commit

Permalink
Add ability to register custom load balancers
Browse files Browse the repository at this point in the history
  • Loading branch information
David Lievrouw committed Mar 15, 2020
1 parent 80ab5f6 commit fd35ad0
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions test/Ocelot.UnitTests/DependencyInjection/OcelotBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,42 @@ public void should_add_transient_defined_aggregators()
.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]
public void should_replace_iplaceholder()
{
Expand All @@ -168,7 +204,7 @@ public void should_replace_iplaceholder()
public void should_add_custom_load_balancer_creators()
{
this.Given(x => WhenISetUpOcelotServices())
.When(x => AddCustomLoadBalancer<FakeCustomLoadBalancer>())
.When(x => _ocelotBuilder.AddCustomLoadBalancer((provider, reroute, discoveryProvider) => new FakeCustomLoadBalancer()))
.Then(x => ThenTheProviderIsRegisteredAndReturnsBothBuiltInAndCustomLoadBalancerCreators())
.BDDfy();
}
Expand All @@ -179,12 +215,6 @@ private void AddSingletonDefinedAggregator<T>()
_ocelotBuilder.AddSingletonDefinedAggregator<T>();
}

private void AddCustomLoadBalancer<T>()
where T : ILoadBalancer, new()
{
_ocelotBuilder.AddCustomLoadBalancer<T>();
}

private void AddTransientDefinedAggregator<T>()
where T : class, IDefinedAggregator
{
Expand Down

0 comments on commit fd35ad0

Please sign in to comment.