mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 06:22:50 +08:00
fixed failing tests after service discovery changes
This commit is contained in:
parent
f2c6d1c799
commit
aef6507da3
@ -27,6 +27,7 @@ namespace Ocelot.UnitTests.Configuration
|
|||||||
private readonly FileOcelotConfigurationCreator _ocelotConfigurationCreator;
|
private readonly FileOcelotConfigurationCreator _ocelotConfigurationCreator;
|
||||||
private readonly Mock<ILoadBalancerFactory> _loadBalancerFactory;
|
private readonly Mock<ILoadBalancerFactory> _loadBalancerFactory;
|
||||||
private readonly Mock<ILoadBalancerHouse> _loadBalancerHouse;
|
private readonly Mock<ILoadBalancerHouse> _loadBalancerHouse;
|
||||||
|
private readonly Mock<ILoadBalancer> _loadBalancer;
|
||||||
|
|
||||||
public FileConfigurationCreatorTests()
|
public FileConfigurationCreatorTests()
|
||||||
{
|
{
|
||||||
@ -34,11 +35,39 @@ namespace Ocelot.UnitTests.Configuration
|
|||||||
_configParser = new Mock<IClaimToThingConfigurationParser>();
|
_configParser = new Mock<IClaimToThingConfigurationParser>();
|
||||||
_validator = new Mock<IConfigurationValidator>();
|
_validator = new Mock<IConfigurationValidator>();
|
||||||
_fileConfig = new Mock<IOptions<FileConfiguration>>();
|
_fileConfig = new Mock<IOptions<FileConfiguration>>();
|
||||||
|
_loadBalancerFactory = new Mock<ILoadBalancerFactory>();
|
||||||
|
_loadBalancerHouse = new Mock<ILoadBalancerHouse>();
|
||||||
|
_loadBalancer = new Mock<ILoadBalancer>();
|
||||||
_ocelotConfigurationCreator = new FileOcelotConfigurationCreator(
|
_ocelotConfigurationCreator = new FileOcelotConfigurationCreator(
|
||||||
_fileConfig.Object, _validator.Object, _configParser.Object, _logger.Object,
|
_fileConfig.Object, _validator.Object, _configParser.Object, _logger.Object,
|
||||||
_loadBalancerFactory.Object, _loadBalancerHouse.Object);
|
_loadBalancerFactory.Object, _loadBalancerHouse.Object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void should_create_load_balancer()
|
||||||
|
{
|
||||||
|
this.Given(x => x.GivenTheConfigIs(new FileConfiguration
|
||||||
|
{
|
||||||
|
ReRoutes = new List<FileReRoute>
|
||||||
|
{
|
||||||
|
new FileReRoute
|
||||||
|
{
|
||||||
|
DownstreamHost = "127.0.0.1",
|
||||||
|
UpstreamTemplate = "/api/products/{productId}",
|
||||||
|
DownstreamPathTemplate = "/products/{productId}",
|
||||||
|
UpstreamHttpMethod = "Get",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
.And(x => x.GivenTheConfigIsValid())
|
||||||
|
.And(x => x.GivenTheLoadBalancerFactoryReturns())
|
||||||
|
.When(x => x.WhenICreateTheConfig())
|
||||||
|
.Then(x => x.TheLoadBalancerFactoryIsCalledCorrectly())
|
||||||
|
.And(x => x.ThenTheLoadBalancerHouseIsCalledCorrectly())
|
||||||
|
|
||||||
|
.BDDfy();
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void should_use_downstream_host()
|
public void should_use_downstream_host()
|
||||||
{
|
{
|
||||||
@ -70,6 +99,7 @@ namespace Ocelot.UnitTests.Configuration
|
|||||||
.BDDfy();
|
.BDDfy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
public void should_use_downstream_scheme()
|
public void should_use_downstream_scheme()
|
||||||
{
|
{
|
||||||
this.Given(x => x.GivenTheConfigIs(new FileConfiguration
|
this.Given(x => x.GivenTheConfigIs(new FileConfiguration
|
||||||
@ -580,5 +610,24 @@ namespace Ocelot.UnitTests.Configuration
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void GivenTheLoadBalancerFactoryReturns()
|
||||||
|
{
|
||||||
|
_loadBalancerFactory
|
||||||
|
.Setup(x => x.Get(It.IsAny<ReRoute>()))
|
||||||
|
.Returns(_loadBalancer.Object);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TheLoadBalancerFactoryIsCalledCorrectly()
|
||||||
|
{
|
||||||
|
_loadBalancerFactory
|
||||||
|
.Verify(x => x.Get(It.IsAny<ReRoute>()), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ThenTheLoadBalancerHouseIsCalledCorrectly()
|
||||||
|
{
|
||||||
|
_loadBalancerHouse
|
||||||
|
.Verify(x => x.Add(It.IsAny<string>(), _loadBalancer.Object), Times.Once);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,13 +15,22 @@ namespace Ocelot.UnitTests.LoadBalancer
|
|||||||
private LoadBalancerFactory _factory;
|
private LoadBalancerFactory _factory;
|
||||||
private ILoadBalancer _result;
|
private ILoadBalancer _result;
|
||||||
private Mock<IServiceProviderFactory> _serviceProviderFactory;
|
private Mock<IServiceProviderFactory> _serviceProviderFactory;
|
||||||
|
private Mock<IServiceProvider> _serviceProvider;
|
||||||
|
|
||||||
public LoadBalancerFactoryTests()
|
public LoadBalancerFactoryTests()
|
||||||
{
|
{
|
||||||
_serviceProviderFactory = new Mock<IServiceProviderFactory>();
|
_serviceProviderFactory = new Mock<IServiceProviderFactory>();
|
||||||
|
_serviceProvider = new Mock<IServiceProvider>();
|
||||||
_factory = new LoadBalancerFactory(_serviceProviderFactory.Object);
|
_factory = new LoadBalancerFactory(_serviceProviderFactory.Object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void GivenTheServiceProviderFactoryReturns()
|
||||||
|
{
|
||||||
|
_serviceProviderFactory
|
||||||
|
.Setup(x => x.Get(It.IsAny<ServiceConfiguraion>()))
|
||||||
|
.Returns(_serviceProvider.Object);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void should_return_no_load_balancer()
|
public void should_return_no_load_balancer()
|
||||||
{
|
{
|
||||||
@ -29,6 +38,7 @@ namespace Ocelot.UnitTests.LoadBalancer
|
|||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
this.Given(x => x.GivenAReRoute(reRoute))
|
this.Given(x => x.GivenAReRoute(reRoute))
|
||||||
|
.And(x => x.GivenTheServiceProviderFactoryReturns())
|
||||||
.When(x => x.WhenIGetTheLoadBalancer())
|
.When(x => x.WhenIGetTheLoadBalancer())
|
||||||
.Then(x => x.ThenTheLoadBalancerIsReturned<NoLoadBalancer>())
|
.Then(x => x.ThenTheLoadBalancerIsReturned<NoLoadBalancer>())
|
||||||
.BDDfy();
|
.BDDfy();
|
||||||
@ -42,6 +52,7 @@ namespace Ocelot.UnitTests.LoadBalancer
|
|||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
this.Given(x => x.GivenAReRoute(reRoute))
|
this.Given(x => x.GivenAReRoute(reRoute))
|
||||||
|
.And(x => x.GivenTheServiceProviderFactoryReturns())
|
||||||
.When(x => x.WhenIGetTheLoadBalancer())
|
.When(x => x.WhenIGetTheLoadBalancer())
|
||||||
.Then(x => x.ThenTheLoadBalancerIsReturned<RoundRobinLoadBalancer>())
|
.Then(x => x.ThenTheLoadBalancerIsReturned<RoundRobinLoadBalancer>())
|
||||||
.BDDfy();
|
.BDDfy();
|
||||||
@ -55,6 +66,7 @@ namespace Ocelot.UnitTests.LoadBalancer
|
|||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
this.Given(x => x.GivenAReRoute(reRoute))
|
this.Given(x => x.GivenAReRoute(reRoute))
|
||||||
|
.And(x => x.GivenTheServiceProviderFactoryReturns())
|
||||||
.When(x => x.WhenIGetTheLoadBalancer())
|
.When(x => x.WhenIGetTheLoadBalancer())
|
||||||
.Then(x => x.ThenTheLoadBalancerIsReturned<LeastConnectionLoadBalancer>())
|
.Then(x => x.ThenTheLoadBalancerIsReturned<LeastConnectionLoadBalancer>())
|
||||||
.BDDfy();
|
.BDDfy();
|
||||||
@ -68,6 +80,7 @@ namespace Ocelot.UnitTests.LoadBalancer
|
|||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
this.Given(x => x.GivenAReRoute(reRoute))
|
this.Given(x => x.GivenAReRoute(reRoute))
|
||||||
|
.And(x => x.GivenTheServiceProviderFactoryReturns())
|
||||||
.When(x => x.WhenIGetTheLoadBalancer())
|
.When(x => x.WhenIGetTheLoadBalancer())
|
||||||
.Then(x => x.ThenTheServiceProviderIsCalledCorrectly())
|
.Then(x => x.ThenTheServiceProviderIsCalledCorrectly())
|
||||||
.BDDfy();
|
.BDDfy();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user