mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 14:02:49 +08:00
74 lines
2.2 KiB
C#
74 lines
2.2 KiB
C#
namespace Ocelot.UnitTests.LoadBalancer
|
|
{
|
|
using Moq;
|
|
using Ocelot.Configuration;
|
|
using Ocelot.Configuration.Builder;
|
|
using Ocelot.LoadBalancer.LoadBalancers;
|
|
using Ocelot.Responses;
|
|
using Ocelot.ServiceDiscovery.Providers;
|
|
using Shouldly;
|
|
using TestStack.BDDfy;
|
|
using Xunit;
|
|
|
|
public class NoLoadBalancerCreatorTests
|
|
{
|
|
private readonly NoLoadBalancerCreator _creator;
|
|
private readonly Mock<IServiceDiscoveryProvider> _serviceProvider;
|
|
private DownstreamRoute _route;
|
|
private Response<ILoadBalancer> _loadBalancer;
|
|
private string _typeName;
|
|
|
|
public NoLoadBalancerCreatorTests()
|
|
{
|
|
_creator = new NoLoadBalancerCreator();
|
|
_serviceProvider = new Mock<IServiceDiscoveryProvider>();
|
|
}
|
|
|
|
[Fact]
|
|
public void should_return_instance_of_expected_load_balancer_type()
|
|
{
|
|
var route = new DownstreamRouteBuilder()
|
|
.Build();
|
|
|
|
this.Given(x => x.GivenARoute(route))
|
|
.When(x => x.WhenIGetTheLoadBalancer())
|
|
.Then(x => x.ThenTheLoadBalancerIsReturned<NoLoadBalancer>())
|
|
.BDDfy();
|
|
}
|
|
|
|
[Fact]
|
|
public void should_return_expected_name()
|
|
{
|
|
this.When(x => x.WhenIGetTheLoadBalancerTypeName())
|
|
.Then(x => x.ThenTheLoadBalancerTypeIs("NoLoadBalancer"))
|
|
.BDDfy();
|
|
}
|
|
|
|
private void GivenARoute(DownstreamRoute route)
|
|
{
|
|
_route = route;
|
|
}
|
|
|
|
private void WhenIGetTheLoadBalancer()
|
|
{
|
|
_loadBalancer = _creator.Create(_route, _serviceProvider.Object);
|
|
}
|
|
|
|
private void WhenIGetTheLoadBalancerTypeName()
|
|
{
|
|
_typeName = _creator.Type;
|
|
}
|
|
|
|
private void ThenTheLoadBalancerIsReturned<T>()
|
|
where T : ILoadBalancer
|
|
{
|
|
_loadBalancer.Data.ShouldBeOfType<T>();
|
|
}
|
|
|
|
private void ThenTheLoadBalancerTypeIs(string type)
|
|
{
|
|
_typeName.ShouldBe(type);
|
|
}
|
|
}
|
|
}
|