mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 06:22:50 +08:00
unit tests passing again
This commit is contained in:
parent
e43732290a
commit
bc1ba53f21
@ -7,6 +7,7 @@ namespace Ocelot.UnitTests.LoadBalancer
|
|||||||
using Moq;
|
using Moq;
|
||||||
using Ocelot.Configuration;
|
using Ocelot.Configuration;
|
||||||
using Ocelot.Configuration.Builder;
|
using Ocelot.Configuration.Builder;
|
||||||
|
using Ocelot.Configuration.Provider;
|
||||||
using Ocelot.DownstreamRouteFinder;
|
using Ocelot.DownstreamRouteFinder;
|
||||||
using Ocelot.Errors;
|
using Ocelot.Errors;
|
||||||
using Ocelot.LoadBalancer.LoadBalancers;
|
using Ocelot.LoadBalancer.LoadBalancers;
|
||||||
@ -22,18 +23,20 @@ namespace Ocelot.UnitTests.LoadBalancer
|
|||||||
{
|
{
|
||||||
private readonly Mock<ILoadBalancerHouse> _loadBalancerHouse;
|
private readonly Mock<ILoadBalancerHouse> _loadBalancerHouse;
|
||||||
private readonly Mock<ILoadBalancer> _loadBalancer;
|
private readonly Mock<ILoadBalancer> _loadBalancer;
|
||||||
|
private readonly Mock<IOcelotConfigurationProvider> _configProvider;
|
||||||
private HostAndPort _hostAndPort;
|
private HostAndPort _hostAndPort;
|
||||||
private OkResponse<DownstreamRoute> _downstreamRoute;
|
private OkResponse<DownstreamRoute> _downstreamRoute;
|
||||||
private ErrorResponse<ILoadBalancer> _getLoadBalancerHouseError;
|
private ErrorResponse<ILoadBalancer> _getLoadBalancerHouseError;
|
||||||
private ErrorResponse<HostAndPort> _getHostAndPortError;
|
private ErrorResponse<HostAndPort> _getHostAndPortError;
|
||||||
private HttpRequestMessage _downstreamRequest;
|
private HttpRequestMessage _downstreamRequest;
|
||||||
|
private ServiceProviderConfiguration _config;
|
||||||
|
|
||||||
public LoadBalancerMiddlewareTests()
|
public LoadBalancerMiddlewareTests()
|
||||||
{
|
{
|
||||||
|
_configProvider = new Mock<IOcelotConfigurationProvider>();
|
||||||
_loadBalancerHouse = new Mock<ILoadBalancerHouse>();
|
_loadBalancerHouse = new Mock<ILoadBalancerHouse>();
|
||||||
_loadBalancer = new Mock<ILoadBalancer>();
|
_loadBalancer = new Mock<ILoadBalancer>();
|
||||||
_loadBalancerHouse = new Mock<ILoadBalancerHouse>();
|
_loadBalancerHouse = new Mock<ILoadBalancerHouse>();
|
||||||
|
|
||||||
_downstreamRequest = new HttpRequestMessage(HttpMethod.Get, "");
|
_downstreamRequest = new HttpRequestMessage(HttpMethod.Get, "");
|
||||||
|
|
||||||
ScopedRepository
|
ScopedRepository
|
||||||
@ -51,7 +54,11 @@ namespace Ocelot.UnitTests.LoadBalancer
|
|||||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||||
.Build());
|
.Build());
|
||||||
|
|
||||||
|
var serviceProviderConfig = new ServiceProviderConfigurationBuilder()
|
||||||
|
.Build();
|
||||||
|
|
||||||
this.Given(x => x.GivenTheDownStreamUrlIs("http://my.url/abc?q=123"))
|
this.Given(x => x.GivenTheDownStreamUrlIs("http://my.url/abc?q=123"))
|
||||||
|
.And(x => GivenTheConfigurationIs(serviceProviderConfig))
|
||||||
.And(x => x.GivenTheDownStreamRouteIs(downstreamRoute))
|
.And(x => x.GivenTheDownStreamRouteIs(downstreamRoute))
|
||||||
.And(x => x.GivenTheLoadBalancerHouseReturns())
|
.And(x => x.GivenTheLoadBalancerHouseReturns())
|
||||||
.And(x => x.GivenTheLoadBalancerReturns())
|
.And(x => x.GivenTheLoadBalancerReturns())
|
||||||
@ -68,7 +75,11 @@ namespace Ocelot.UnitTests.LoadBalancer
|
|||||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||||
.Build());
|
.Build());
|
||||||
|
|
||||||
|
var serviceProviderConfig = new ServiceProviderConfigurationBuilder()
|
||||||
|
.Build();
|
||||||
|
|
||||||
this.Given(x => x.GivenTheDownStreamUrlIs("http://my.url/abc?q=123"))
|
this.Given(x => x.GivenTheDownStreamUrlIs("http://my.url/abc?q=123"))
|
||||||
|
.And(x => GivenTheConfigurationIs(serviceProviderConfig))
|
||||||
.And(x => x.GivenTheDownStreamRouteIs(downstreamRoute))
|
.And(x => x.GivenTheDownStreamRouteIs(downstreamRoute))
|
||||||
.And(x => x.GivenTheLoadBalancerHouseReturnsAnError())
|
.And(x => x.GivenTheLoadBalancerHouseReturnsAnError())
|
||||||
.When(x => x.WhenICallTheMiddleware())
|
.When(x => x.WhenICallTheMiddleware())
|
||||||
@ -84,7 +95,11 @@ namespace Ocelot.UnitTests.LoadBalancer
|
|||||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||||
.Build());
|
.Build());
|
||||||
|
|
||||||
|
var serviceProviderConfig = new ServiceProviderConfigurationBuilder()
|
||||||
|
.Build();
|
||||||
|
|
||||||
this.Given(x => x.GivenTheDownStreamUrlIs("http://my.url/abc?q=123"))
|
this.Given(x => x.GivenTheDownStreamUrlIs("http://my.url/abc?q=123"))
|
||||||
|
.And(x => GivenTheConfigurationIs(serviceProviderConfig))
|
||||||
.And(x => x.GivenTheDownStreamRouteIs(downstreamRoute))
|
.And(x => x.GivenTheDownStreamRouteIs(downstreamRoute))
|
||||||
.And(x => x.GivenTheLoadBalancerHouseReturns())
|
.And(x => x.GivenTheLoadBalancerHouseReturns())
|
||||||
.And(x => x.GivenTheLoadBalancerReturnsAnError())
|
.And(x => x.GivenTheLoadBalancerReturnsAnError())
|
||||||
@ -93,11 +108,19 @@ namespace Ocelot.UnitTests.LoadBalancer
|
|||||||
.BDDfy();
|
.BDDfy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void GivenTheConfigurationIs(ServiceProviderConfiguration config)
|
||||||
|
{
|
||||||
|
_config = config;
|
||||||
|
_configProvider
|
||||||
|
.Setup(x => x.Get()).ReturnsAsync(new OkResponse<IOcelotConfiguration>(new OcelotConfiguration(null, null, _config)));
|
||||||
|
}
|
||||||
|
|
||||||
protected override void GivenTheTestServerServicesAreConfigured(IServiceCollection services)
|
protected override void GivenTheTestServerServicesAreConfigured(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddSingleton<IOcelotLoggerFactory, AspDotNetLoggerFactory>();
|
services.AddSingleton<IOcelotLoggerFactory, AspDotNetLoggerFactory>();
|
||||||
services.AddLogging();
|
services.AddLogging();
|
||||||
services.AddSingleton(_loadBalancerHouse.Object);
|
services.AddSingleton(_loadBalancerHouse.Object);
|
||||||
|
services.AddSingleton(_configProvider.Object);
|
||||||
services.AddSingleton(ScopedRepository.Object);
|
services.AddSingleton(ScopedRepository.Object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user