mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 06:48:16 +08:00
Rewire LoadBalancerFactory to allow injecting custom load balancers, by introducing LoadBalancerCreators
This commit is contained in:
72
test/Ocelot.UnitTests/LoadBalancer/RoundRobinCreatorTests.cs
Normal file
72
test/Ocelot.UnitTests/LoadBalancer/RoundRobinCreatorTests.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using Moq;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Builder;
|
||||
using Ocelot.LoadBalancer.LoadBalancers;
|
||||
using Ocelot.ServiceDiscovery.Providers;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.LoadBalancer
|
||||
{
|
||||
public class RoundRobinCreatorTests
|
||||
{
|
||||
private readonly RoundRobinCreator _creator;
|
||||
private readonly Mock<IServiceDiscoveryProvider> _serviceProvider;
|
||||
private DownstreamReRoute _reRoute;
|
||||
private ILoadBalancer _loadBalancer;
|
||||
private string _typeName;
|
||||
|
||||
public RoundRobinCreatorTests()
|
||||
{
|
||||
_creator = new RoundRobinCreator();
|
||||
_serviceProvider = new Mock<IServiceDiscoveryProvider>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_expected_name()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenAReRoute(reRoute))
|
||||
.When(x => x.WhenIGetTheLoadBalancer())
|
||||
.Then(x => x.ThenTheLoadBalancerIsReturned<RoundRobin>())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_instance_of_expected_load_balancer_type()
|
||||
{
|
||||
this.When(x => x.WhenIGetTheLoadBalancerTypeName())
|
||||
.Then(x => x.ThenTheLoadBalancerTypeIs("RoundRobin"))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void GivenAReRoute(DownstreamReRoute reRoute)
|
||||
{
|
||||
_reRoute = reRoute;
|
||||
}
|
||||
|
||||
private void WhenIGetTheLoadBalancer()
|
||||
{
|
||||
_loadBalancer = _creator.Create(_reRoute, _serviceProvider.Object);
|
||||
}
|
||||
|
||||
private void WhenIGetTheLoadBalancerTypeName()
|
||||
{
|
||||
_typeName = _creator.Type;
|
||||
}
|
||||
|
||||
private void ThenTheLoadBalancerIsReturned<T>()
|
||||
where T : ILoadBalancer
|
||||
{
|
||||
_loadBalancer.ShouldBeOfType<T>();
|
||||
}
|
||||
|
||||
private void ThenTheLoadBalancerTypeIs(string type)
|
||||
{
|
||||
_typeName.ShouldBe(type);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user