mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-05-03 04:32:50 +08:00
74 lines
2.2 KiB
C#
74 lines
2.2 KiB
C#
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 CookieStickySessionsCreatorTests
|
|
{
|
|
private readonly CookieStickySessionsCreator _creator;
|
|
private readonly Mock<IServiceDiscoveryProvider> _serviceProvider;
|
|
private DownstreamReRoute _reRoute;
|
|
private ILoadBalancer _loadBalancer;
|
|
private string _typeName;
|
|
|
|
public CookieStickySessionsCreatorTests()
|
|
{
|
|
_creator = new CookieStickySessionsCreator();
|
|
_serviceProvider = new Mock<IServiceDiscoveryProvider>();
|
|
}
|
|
|
|
[Fact]
|
|
public void should_return_instance_of_expected_load_balancer_type()
|
|
{
|
|
var reRoute = new DownstreamReRouteBuilder()
|
|
.WithLoadBalancerOptions(new LoadBalancerOptions("myType", "myKey", 1000))
|
|
.Build();
|
|
|
|
this.Given(x => x.GivenAReRoute(reRoute))
|
|
.When(x => x.WhenIGetTheLoadBalancer())
|
|
.Then(x => x.ThenTheLoadBalancerIsReturned<CookieStickySessions>())
|
|
.BDDfy();
|
|
}
|
|
|
|
[Fact]
|
|
public void should_return_expected_name()
|
|
{
|
|
this.When(x => x.WhenIGetTheLoadBalancerTypeName())
|
|
.Then(x => x.ThenTheLoadBalancerTypeIs("CookieStickySessions"))
|
|
.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);
|
|
}
|
|
}
|
|
}
|