mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 10:38:15 +08:00
Feature/automatic routes with sd (#351)
* #340 started looking at supporting automatic routing when using service discovery * #340 getting old routing tests to pass * #340 renamed stuff to provider rather than finder, as its not longer finding anything * #340 working towards supporting dynamic routing * #340 loads of refactoring to make configuration work with dynamic routing * #340 refactor consul config code so the registry class owns it * #340 default to consul to maintain backwards compat * #340 added docs, finished this branches todos
This commit is contained in:
@ -208,6 +208,121 @@ namespace Ocelot.AcceptanceTests
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_handle_request_to_consul_for_downstream_service_and_make_request_no_re_routes()
|
||||
{
|
||||
const int consulPort = 8513;
|
||||
const string serviceName = "web";
|
||||
const int downstreamServicePort = 8087;
|
||||
var downstreamServiceOneUrl = $"http://localhost:{downstreamServicePort}";
|
||||
var fakeConsulServiceDiscoveryUrl = $"http://localhost:{consulPort}";
|
||||
var serviceEntryOne = new ServiceEntry()
|
||||
{
|
||||
Service = new AgentService()
|
||||
{
|
||||
Service = serviceName,
|
||||
Address = "localhost",
|
||||
Port = downstreamServicePort,
|
||||
ID = "web_90_0_2_224_8080",
|
||||
Tags = new[] {"version-v1"}
|
||||
},
|
||||
};
|
||||
|
||||
var configuration = new FileConfiguration
|
||||
{
|
||||
GlobalConfiguration = new FileGlobalConfiguration
|
||||
{
|
||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
||||
{
|
||||
Host = "localhost",
|
||||
Port = consulPort
|
||||
},
|
||||
DownstreamScheme = "http",
|
||||
HttpHandlerOptions = new FileHttpHandlerOptions
|
||||
{
|
||||
AllowAutoRedirect = true,
|
||||
UseCookieContainer = true,
|
||||
UseTracing = false
|
||||
},
|
||||
QoSOptions = new FileQoSOptions
|
||||
{
|
||||
TimeoutValue = 100,
|
||||
DurationOfBreak = 1000,
|
||||
ExceptionsAllowedBeforeBreaking = 1
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn(downstreamServiceOneUrl, "/something", 200, "Hello from Laura"))
|
||||
.And(x => x.GivenThereIsAFakeConsulServiceDiscoveryProvider(fakeConsulServiceDiscoveryUrl, serviceName))
|
||||
.And(x => x.GivenTheServicesAreRegisteredWithConsul(serviceEntryOne))
|
||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||
.And(x => _steps.GivenOcelotIsRunning())
|
||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/web/something"))
|
||||
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
|
||||
.And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_use_consul_service_discovery_and_load_balance_request_no_re_routes()
|
||||
{
|
||||
var consulPort = 8510;
|
||||
var serviceName = "product";
|
||||
var serviceOnePort = 50888;
|
||||
var serviceTwoPort = 50889;
|
||||
var downstreamServiceOneUrl = $"http://localhost:{serviceOnePort}";
|
||||
var downstreamServiceTwoUrl = $"http://localhost:{serviceTwoPort}";
|
||||
var fakeConsulServiceDiscoveryUrl = $"http://localhost:{consulPort}";
|
||||
var serviceEntryOne = new ServiceEntry()
|
||||
{
|
||||
Service = new AgentService()
|
||||
{
|
||||
Service = serviceName,
|
||||
Address = "localhost",
|
||||
Port = serviceOnePort,
|
||||
ID = Guid.NewGuid().ToString(),
|
||||
Tags = new string[0]
|
||||
},
|
||||
};
|
||||
var serviceEntryTwo = new ServiceEntry()
|
||||
{
|
||||
Service = new AgentService()
|
||||
{
|
||||
Service = serviceName,
|
||||
Address = "localhost",
|
||||
Port = serviceTwoPort,
|
||||
ID = Guid.NewGuid().ToString(),
|
||||
Tags = new string[0]
|
||||
},
|
||||
};
|
||||
|
||||
var configuration = new FileConfiguration
|
||||
{
|
||||
GlobalConfiguration = new FileGlobalConfiguration()
|
||||
{
|
||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
||||
{
|
||||
Host = "localhost",
|
||||
Port = consulPort
|
||||
},
|
||||
LoadBalancerOptions = new FileLoadBalancerOptions { Type = "LeastConnection" },
|
||||
DownstreamScheme = "http"
|
||||
}
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenProductServiceOneIsRunning(downstreamServiceOneUrl, 200))
|
||||
.And(x => x.GivenProductServiceTwoIsRunning(downstreamServiceTwoUrl, 200))
|
||||
.And(x => x.GivenThereIsAFakeConsulServiceDiscoveryProvider(fakeConsulServiceDiscoveryUrl, serviceName))
|
||||
.And(x => x.GivenTheServicesAreRegisteredWithConsul(serviceEntryOne, serviceEntryTwo))
|
||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||
.And(x => _steps.GivenOcelotIsRunning())
|
||||
.When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimes($"/{serviceName}/", 50))
|
||||
.Then(x => x.ThenTheTwoServicesShouldHaveBeenCalledTimes(50))
|
||||
.And(x => x.ThenBothServicesCalledRealisticAmountOfTimes(24, 26))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_use_token_to_make_request_to_consul()
|
||||
{
|
||||
|
@ -55,7 +55,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
|
||||
_internalRepo
|
||||
.Setup(x => x.Get())
|
||||
.Returns(new OkResponse<IInternalConfiguration>(new InternalConfiguration(new List<ReRoute>(), "", new ServiceProviderConfigurationBuilder().Build(), "")));
|
||||
.Returns(new OkResponse<IInternalConfiguration>(new InternalConfiguration(new List<ReRoute>(), "", new ServiceProviderConfigurationBuilder().Build(), "", It.IsAny<LoadBalancerOptions>(), It.IsAny<string>(), It.IsAny<QoSOptions>(), It.IsAny<HttpHandlerOptions>())));
|
||||
|
||||
_repo = new ConsulFileConfigurationRepository(_cache.Object, _internalRepo.Object, _factory.Object, _loggerFactory.Object);
|
||||
}
|
||||
@ -140,7 +140,10 @@ namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
_internalRepo
|
||||
.Setup(x => x.Get())
|
||||
.Returns(new OkResponse<IInternalConfiguration>(new InternalConfiguration(new List<ReRoute>(), "", new ServiceProviderConfigurationBuilder().WithConfigurationKey(key).Build(), "")));
|
||||
.Returns(new OkResponse<IInternalConfiguration>(new InternalConfiguration(new List<ReRoute>(), "",
|
||||
new ServiceProviderConfigurationBuilder().WithConfigurationKey(key).Build(), "",
|
||||
new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(),
|
||||
new HttpHandlerOptionsBuilder().Build())));
|
||||
|
||||
_repo = new ConsulFileConfigurationRepository(_cache.Object, _internalRepo.Object, _factory.Object, _loggerFactory.Object);
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
var fileConfig = new FileConfiguration();
|
||||
var serviceProviderConfig = new ServiceProviderConfigurationBuilder().Build();
|
||||
var config = new InternalConfiguration(new List<ReRoute>(), string.Empty, serviceProviderConfig, "asdf");
|
||||
var config = new InternalConfiguration(new List<ReRoute>(), string.Empty, serviceProviderConfig, "asdf", new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(), new HttpHandlerOptionsBuilder().Build());
|
||||
|
||||
this.Given(x => GivenTheFollowingConfiguration(fileConfig))
|
||||
.And(x => GivenTheRepoReturns(new OkResponse()))
|
||||
|
@ -86,7 +86,7 @@
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithReRouteKey("CookieStickySessions:sessionid")
|
||||
.WithLoadBalancerKey("CookieStickySessions:sessionid")
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenTheConfigIs(new FileConfiguration
|
||||
@ -199,7 +199,7 @@
|
||||
.WithDownstreamScheme("http")
|
||||
.WithUpstreamHttpMethod(new List<string>() {"Get"})
|
||||
.WithDownstreamAddresses(new List<DownstreamHostAndPort>() {new DownstreamHostAndPort("localhost", 51878)})
|
||||
.WithReRouteKey("/laura|Get")
|
||||
.WithLoadBalancerKey("/laura|Get")
|
||||
.Build();
|
||||
|
||||
var lauraReRoute = new ReRouteBuilder()
|
||||
@ -218,7 +218,7 @@
|
||||
.WithDownstreamScheme("http")
|
||||
.WithUpstreamHttpMethod(new List<string>() { "Get" })
|
||||
.WithDownstreamAddresses(new List<DownstreamHostAndPort>() { new DownstreamHostAndPort("localhost", 51878) })
|
||||
.WithReRouteKey("/tom|Get")
|
||||
.WithLoadBalancerKey("/tom|Get")
|
||||
.Build();
|
||||
|
||||
var tomReRoute = new ReRouteBuilder()
|
||||
@ -361,7 +361,6 @@
|
||||
.Build();
|
||||
|
||||
var serviceOptions = new ReRouteOptionsBuilder()
|
||||
.WithIsQos(true)
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenTheConfigIs(new FileConfiguration
|
||||
@ -410,7 +409,7 @@
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod(new List<string> {"Get"})
|
||||
.WithReRouteKey("/api/products/{productId}|Get")
|
||||
.WithLoadBalancerKey("/api/products/{productId}|Get")
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenTheConfigIs(new FileConfiguration
|
||||
@ -462,7 +461,7 @@
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod(new List<string> {"Get"})
|
||||
.WithDelegatingHandlers(handlers)
|
||||
.WithReRouteKey("/api/products/{productId}|Get")
|
||||
.WithLoadBalancerKey("/api/products/{productId}|Get")
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenTheConfigIs(new FileConfiguration
|
||||
@ -507,7 +506,7 @@
|
||||
.WithUpstreamHttpMethod(new List<string> {"Get"})
|
||||
.WithUseServiceDiscovery(true)
|
||||
.WithServiceName("ProductService")
|
||||
.WithReRouteKey("/api/products/{productId}|Get")
|
||||
.WithLoadBalancerKey("/api/products/{productId}|Get")
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenTheConfigIs(new FileConfiguration
|
||||
@ -558,7 +557,7 @@
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod(new List<string> {"Get"})
|
||||
.WithUseServiceDiscovery(false)
|
||||
.WithReRouteKey("/api/products/{productId}|Get")
|
||||
.WithLoadBalancerKey("/api/products/{productId}|Get")
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenTheConfigIs(new FileConfiguration
|
||||
@ -601,7 +600,7 @@
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod(new List<string> {"Get"})
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("(?i)/api/products/.*/$", 1))
|
||||
.WithReRouteKey("/api/products/{productId}|Get")
|
||||
.WithLoadBalancerKey("/api/products/{productId}|Get")
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenTheConfigIs(new FileConfiguration
|
||||
@ -646,7 +645,7 @@
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod(new List<string> {"Get"})
|
||||
.WithRequestIdKey("blahhhh")
|
||||
.WithReRouteKey("/api/products/{productId}|Get")
|
||||
.WithLoadBalancerKey("/api/products/{productId}|Get")
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenTheConfigIs(new FileConfiguration
|
||||
@ -741,7 +740,7 @@
|
||||
{
|
||||
new ClaimToThing("CustomerId", "CustomerId", "", 0),
|
||||
})
|
||||
.WithReRouteKey("/api/products/{productId}|Get")
|
||||
.WithLoadBalancerKey("/api/products/{productId}|Get")
|
||||
.Build();
|
||||
|
||||
var expected = new List<ReRoute>
|
||||
@ -784,7 +783,7 @@
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod(new List<string> {"Get"})
|
||||
.WithAuthenticationOptions(authenticationOptions)
|
||||
.WithReRouteKey("/api/products/{productId}|Get")
|
||||
.WithLoadBalancerKey("/api/products/{productId}|Get")
|
||||
.Build();
|
||||
|
||||
var expected = new List<ReRoute>
|
||||
@ -942,16 +941,15 @@
|
||||
private void GivenTheQosOptionsCreatorReturns(QoSOptions qosOptions)
|
||||
{
|
||||
_qosOptionsCreator
|
||||
.Setup(x => x.Create(_fileConfiguration.ReRoutes[0]))
|
||||
.Setup(x => x.Create(_fileConfiguration.ReRoutes[0].QoSOptions, It.IsAny<string>(), It.IsAny<string[]>()))
|
||||
.Returns(qosOptions);
|
||||
}
|
||||
|
||||
private void ThenTheQosOptionsAre(QoSOptions qosOptions)
|
||||
{
|
||||
_config.Data.ReRoutes[0].DownstreamReRoute[0].QosOptionsOptions.DurationOfBreak.ShouldBe(qosOptions.DurationOfBreak);
|
||||
|
||||
_config.Data.ReRoutes[0].DownstreamReRoute[0].QosOptionsOptions.ExceptionsAllowedBeforeBreaking.ShouldBe(qosOptions.ExceptionsAllowedBeforeBreaking);
|
||||
_config.Data.ReRoutes[0].DownstreamReRoute[0].QosOptionsOptions.TimeoutValue.ShouldBe(qosOptions.TimeoutValue);
|
||||
_config.Data.ReRoutes[0].DownstreamReRoute[0].QosOptions.DurationOfBreak.ShouldBe(qosOptions.DurationOfBreak);
|
||||
_config.Data.ReRoutes[0].DownstreamReRoute[0].QosOptions.ExceptionsAllowedBeforeBreaking.ShouldBe(qosOptions.ExceptionsAllowedBeforeBreaking);
|
||||
_config.Data.ReRoutes[0].DownstreamReRoute[0].QosOptions.TimeoutValue.ShouldBe(qosOptions.TimeoutValue);
|
||||
}
|
||||
|
||||
private void ThenTheServiceProviderCreatorIsCalledCorrectly()
|
||||
@ -992,13 +990,13 @@
|
||||
|
||||
private void GivenTheFollowingHttpHandlerOptionsAreReturned(HttpHandlerOptions httpHandlerOptions)
|
||||
{
|
||||
_httpHandlerOptionsCreator.Setup(x => x.Create(It.IsAny<FileReRoute>()))
|
||||
_httpHandlerOptionsCreator.Setup(x => x.Create(It.IsAny<FileHttpHandlerOptions>()))
|
||||
.Returns(httpHandlerOptions);
|
||||
}
|
||||
|
||||
private void ThenTheHttpHandlerOptionsCreatorIsCalledCorrectly()
|
||||
{
|
||||
_httpHandlerOptionsCreator.Verify(x => x.Create(_fileConfiguration.ReRoutes[0]), Times.Once());
|
||||
_httpHandlerOptionsCreator.Verify(x => x.Create(_fileConfiguration.ReRoutes[0].HttpHandlerOptions), Times.Once());
|
||||
}
|
||||
|
||||
private void GivenTheDownstreamAddresses()
|
||||
|
@ -103,7 +103,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
|
||||
private void WhenICreateHttpHandlerOptions()
|
||||
{
|
||||
_httpHandlerOptions = _httpHandlerOptionsCreator.Create(_fileReRoute);
|
||||
_httpHandlerOptions = _httpHandlerOptionsCreator.Create(_fileReRoute.HttpHandlerOptions);
|
||||
}
|
||||
|
||||
private void ThenTheFollowingOptionsReturned(HttpHandlerOptions expected)
|
||||
|
@ -105,6 +105,10 @@ namespace Ocelot.UnitTests.Configuration
|
||||
public ServiceProviderConfiguration ServiceProviderConfiguration => throw new NotImplementedException();
|
||||
|
||||
public string RequestId {get;}
|
||||
public LoadBalancerOptions LoadBalancerOptions { get; }
|
||||
public string DownstreamScheme { get; }
|
||||
public QoSOptions QoSOptions { get; }
|
||||
public HttpHandlerOptions HttpHandlerOptions { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
|
||||
private void WhenICreate()
|
||||
{
|
||||
_result = _creator.Create(_fileReRoute);
|
||||
_result = _creator.Create(_fileReRoute.QoSOptions);
|
||||
}
|
||||
|
||||
private void ThenTheFollowingIsReturned(QoSOptions expected)
|
||||
@ -60,4 +60,4 @@ namespace Ocelot.UnitTests.Configuration
|
||||
_result.TimeoutValue.ShouldBe(expected.TimeoutValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,11 +29,6 @@ namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
EnableRateLimiting = true
|
||||
},
|
||||
QoSOptions = new FileQoSOptions
|
||||
{
|
||||
ExceptionsAllowedBeforeBreaking = 1,
|
||||
TimeoutValue = 1
|
||||
},
|
||||
AuthenticationOptions = new FileAuthenticationOptions()
|
||||
{
|
||||
AuthenticationProviderKey = "Test"
|
||||
@ -52,7 +47,6 @@ namespace Ocelot.UnitTests.Configuration
|
||||
.WithIsAuthenticated(true)
|
||||
.WithIsAuthorised(true)
|
||||
.WithIsCached(true)
|
||||
.WithIsQos(true)
|
||||
.WithRateLimiting(true)
|
||||
.Build();
|
||||
|
||||
@ -76,9 +70,8 @@ namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
_result.IsAuthenticated.ShouldBe(expected.IsAuthenticated);
|
||||
_result.IsAuthorised.ShouldBe(expected.IsAuthorised);
|
||||
_result.IsQos.ShouldBe(expected.IsQos);
|
||||
_result.IsCached.ShouldBe(expected.IsCached);
|
||||
_result.EnableRateLimiting.ShouldBe(expected.EnableRateLimiting);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,194 @@
|
||||
using Ocelot.DownstreamRouteFinder.Finder;
|
||||
using Xunit;
|
||||
using Shouldly;
|
||||
using Ocelot.Configuration;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
{
|
||||
using Moq;
|
||||
using Ocelot.Configuration.Builder;
|
||||
using Ocelot.Configuration.Creator;
|
||||
using Ocelot.DownstreamRouteFinder;
|
||||
using Ocelot.LoadBalancer.LoadBalancers;
|
||||
using Responses;
|
||||
using TestStack.BDDfy;
|
||||
|
||||
public class DownstreamRouteCreatorTests
|
||||
{
|
||||
private readonly DownstreamRouteCreator _creator;
|
||||
private readonly QoSOptions _qoSOptions;
|
||||
private readonly HttpHandlerOptions _handlerOptions;
|
||||
private readonly LoadBalancerOptions _loadBalancerOptions;
|
||||
private Response<DownstreamRoute> _result;
|
||||
private string _upstreamHost;
|
||||
private string _upstreamUrlPath;
|
||||
private string _upstreamHttpMethod;
|
||||
private IInternalConfiguration _configuration;
|
||||
private Mock<IQoSOptionsCreator> _qosOptionsCreator;
|
||||
|
||||
public DownstreamRouteCreatorTests()
|
||||
{
|
||||
_qosOptionsCreator = new Mock<IQoSOptionsCreator>();
|
||||
_qoSOptions = new QoSOptionsBuilder().Build();
|
||||
_handlerOptions = new HttpHandlerOptionsBuilder().Build();
|
||||
_loadBalancerOptions = new LoadBalancerOptionsBuilder().WithType(nameof(NoLoadBalancer)).Build();
|
||||
_qosOptionsCreator
|
||||
.Setup(x => x.Create(It.IsAny<QoSOptions>(), It.IsAny<string>(), It.IsAny<string[]>()))
|
||||
.Returns(_qoSOptions);
|
||||
_creator = new DownstreamRouteCreator(_qosOptionsCreator.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_create_downstream_route()
|
||||
{
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
|
||||
|
||||
this.Given(_ => GivenTheConfiguration(configuration))
|
||||
.When(_ => WhenICreate())
|
||||
.Then(_ => ThenTheDownstreamRouteIsCreated())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_create_downstream_route_with_no_path()
|
||||
{
|
||||
var upstreamUrlPath = "/auth/";
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
|
||||
|
||||
this.Given(_ => GivenTheConfiguration(configuration, upstreamUrlPath))
|
||||
.When(_ => WhenICreate())
|
||||
.Then(_ => ThenTheDownstreamPathIsForwardSlash())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_create_downstream_route_and_remove_query_string()
|
||||
{
|
||||
var upstreamUrlPath = "/auth/test?test=1&best=2";
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
|
||||
|
||||
this.Given(_ => GivenTheConfiguration(configuration, upstreamUrlPath))
|
||||
.When(_ => WhenICreate())
|
||||
.Then(_ => ThenTheQueryStringIsRemoved())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_create_downstream_route_for_sticky_sessions()
|
||||
{
|
||||
var loadBalancerOptions = new LoadBalancerOptionsBuilder().WithType(nameof(CookieStickySessions)).WithKey("boom").WithExpiryInMs(1).Build();
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
|
||||
|
||||
this.Given(_ => GivenTheConfiguration(configuration))
|
||||
.When(_ => WhenICreate())
|
||||
.Then(_ => ThenTheStickySessionLoadBalancerIsUsed(loadBalancerOptions))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_create_downstream_route_with_qos()
|
||||
{
|
||||
var qoSOptions = new QoSOptionsBuilder()
|
||||
.WithExceptionsAllowedBeforeBreaking(1)
|
||||
.WithTimeoutValue(1)
|
||||
.Build();
|
||||
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", qoSOptions, _handlerOptions);
|
||||
|
||||
this.Given(_ => GivenTheConfiguration(configuration))
|
||||
.And(_ => GivenTheQosCreatorReturns(qoSOptions))
|
||||
.When(_ => WhenICreate())
|
||||
.Then(_ => ThenTheQosOptionsAreSet(qoSOptions))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_create_downstream_route_with_handler_options()
|
||||
{
|
||||
var configuration = new InternalConfiguration(null, "doesnt matter", null, "doesnt matter", _loadBalancerOptions, "http", _qoSOptions, _handlerOptions);
|
||||
|
||||
this.Given(_ => GivenTheConfiguration(configuration))
|
||||
.When(_ => WhenICreate())
|
||||
.Then(_ => ThenTheHandlerOptionsAreSet())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void GivenTheQosCreatorReturns(QoSOptions options)
|
||||
{
|
||||
_qosOptionsCreator
|
||||
.Setup(x => x.Create(It.IsAny<QoSOptions>(), It.IsAny<string>(), It.IsAny<string[]>()))
|
||||
.Returns(options);
|
||||
}
|
||||
|
||||
private void ThenTheDownstreamRouteIsCreated()
|
||||
{
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].DownstreamPathTemplate.Value.ShouldBe("/test");
|
||||
_result.Data.ReRoute.UpstreamHttpMethod[0].ShouldBe(HttpMethod.Get);
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].ServiceName.ShouldBe("auth");
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].LoadBalancerKey.ShouldBe("/auth/test|GET");
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].UseServiceDiscovery.ShouldBeTrue();
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].HttpHandlerOptions.ShouldNotBeNull();
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].QosOptions.ShouldNotBeNull();
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].DownstreamScheme.ShouldBe("http");
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].LoadBalancerOptions.Type.ShouldBe(nameof(NoLoadBalancer));
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].HttpHandlerOptions.ShouldBe(_handlerOptions);
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].QosOptions.ShouldBe(_qoSOptions);
|
||||
}
|
||||
|
||||
private void ThenTheDownstreamPathIsForwardSlash()
|
||||
{
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].DownstreamPathTemplate.Value.ShouldBe("/");
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].ServiceName.ShouldBe("auth");
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].LoadBalancerKey.ShouldBe("/auth/|GET");
|
||||
}
|
||||
|
||||
private void ThenTheQueryStringIsRemoved()
|
||||
{
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].DownstreamPathTemplate.Value.ShouldBe("/test");
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].ServiceName.ShouldBe("auth");
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].LoadBalancerKey.ShouldBe("/auth/test|GET");
|
||||
}
|
||||
|
||||
private void ThenTheStickySessionLoadBalancerIsUsed(LoadBalancerOptions expected)
|
||||
{
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].LoadBalancerKey.ShouldBe($"{nameof(CookieStickySessions)}:boom");
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].LoadBalancerOptions.Type.ShouldBe(nameof(CookieStickySessions));
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].LoadBalancerOptions.ShouldBe(expected);
|
||||
}
|
||||
|
||||
private void ThenTheQosOptionsAreSet(QoSOptions expected)
|
||||
{
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].QosOptions.ShouldBe(expected);
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].QosOptions.UseQos.ShouldBeTrue();
|
||||
_qosOptionsCreator
|
||||
.Verify(x => x.Create(expected, _upstreamUrlPath, It.IsAny<string[]>()), Times.Once);
|
||||
}
|
||||
|
||||
private void GivenTheConfiguration(IInternalConfiguration config)
|
||||
{
|
||||
_upstreamHost = "doesnt matter";
|
||||
_upstreamUrlPath = "/auth/test";
|
||||
_upstreamHttpMethod = "GET";
|
||||
_configuration = config;
|
||||
}
|
||||
|
||||
private void GivenTheConfiguration(IInternalConfiguration config, string upstreamUrlPath)
|
||||
{
|
||||
_upstreamHost = "doesnt matter";
|
||||
_upstreamUrlPath = upstreamUrlPath;
|
||||
_upstreamHttpMethod = "GET";
|
||||
_configuration = config;
|
||||
}
|
||||
|
||||
private void ThenTheHandlerOptionsAreSet()
|
||||
{
|
||||
_result.Data.ReRoute.DownstreamReRoute[0].HttpHandlerOptions.ShouldBe(_handlerOptions);
|
||||
}
|
||||
|
||||
private void WhenICreate()
|
||||
{
|
||||
_result = _creator.Get(_upstreamUrlPath, _upstreamHttpMethod, _configuration, _upstreamHost);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,98 +1,99 @@
|
||||
namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Moq;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Builder;
|
||||
using Ocelot.DownstreamRouteFinder;
|
||||
using Ocelot.DownstreamRouteFinder.Finder;
|
||||
using Ocelot.DownstreamRouteFinder.Middleware;
|
||||
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
||||
using Ocelot.Logging;
|
||||
using Ocelot.Responses;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
using Ocelot.Configuration.Repository;
|
||||
using Ocelot.Middleware;
|
||||
using Ocelot.Middleware.Multiplexer;
|
||||
|
||||
public class DownstreamRouteFinderMiddlewareTests
|
||||
{
|
||||
private readonly Mock<IDownstreamRouteFinder> _finder;
|
||||
private readonly Mock<IInternalConfigurationRepository> _repo;
|
||||
private Response<DownstreamRoute> _downstreamRoute;
|
||||
private IInternalConfiguration _config;
|
||||
private Mock<IOcelotLoggerFactory> _loggerFactory;
|
||||
private Mock<IOcelotLogger> _logger;
|
||||
private readonly DownstreamRouteFinderMiddleware _middleware;
|
||||
private readonly DownstreamContext _downstreamContext;
|
||||
private OcelotRequestDelegate _next;
|
||||
private readonly Mock<IMultiplexer> _multiplexer;
|
||||
|
||||
public DownstreamRouteFinderMiddlewareTests()
|
||||
{
|
||||
_repo = new Mock<IInternalConfigurationRepository>();
|
||||
_finder = new Mock<IDownstreamRouteFinder>();
|
||||
_downstreamContext = new DownstreamContext(new DefaultHttpContext());
|
||||
_loggerFactory = new Mock<IOcelotLoggerFactory>();
|
||||
_logger = new Mock<IOcelotLogger>();
|
||||
_loggerFactory.Setup(x => x.CreateLogger<DownstreamRouteFinderMiddleware>()).Returns(_logger.Object);
|
||||
_next = context => Task.CompletedTask;
|
||||
_multiplexer = new Mock<IMultiplexer>();
|
||||
_middleware = new DownstreamRouteFinderMiddleware(_next, _loggerFactory.Object, _finder.Object, _repo.Object, _multiplexer.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_call_scoped_data_repository_correctly()
|
||||
{
|
||||
var config = new InternalConfiguration(null, null, new ServiceProviderConfigurationBuilder().Build(), "");
|
||||
|
||||
var downstreamReRoute = new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("any old string")
|
||||
.WithUpstreamHttpMethod(new List<string> {"Get"})
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenTheDownStreamRouteFinderReturns(
|
||||
new DownstreamRoute(
|
||||
new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(downstreamReRoute)
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.Build())))
|
||||
.And(x => GivenTheFollowingConfig(config))
|
||||
.When(x => x.WhenICallTheMiddleware())
|
||||
.Then(x => x.ThenTheScopedDataRepositoryIsCalledCorrectly())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void WhenICallTheMiddleware()
|
||||
{
|
||||
_middleware.Invoke(_downstreamContext).GetAwaiter().GetType();
|
||||
}
|
||||
|
||||
private void GivenTheFollowingConfig(IInternalConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
_repo
|
||||
.Setup(x => x.Get())
|
||||
.Returns(new OkResponse<IInternalConfiguration>(_config));
|
||||
}
|
||||
|
||||
private void GivenTheDownStreamRouteFinderReturns(DownstreamRoute downstreamRoute)
|
||||
{
|
||||
_downstreamRoute = new OkResponse<DownstreamRoute>(downstreamRoute);
|
||||
_finder
|
||||
.Setup(x => x.FindDownstreamRoute(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<IInternalConfiguration>(), It.IsAny<string>()))
|
||||
.Returns(_downstreamRoute);
|
||||
}
|
||||
|
||||
private void ThenTheScopedDataRepositoryIsCalledCorrectly()
|
||||
{
|
||||
_downstreamContext.TemplatePlaceholderNameAndValues.ShouldBe(_downstreamRoute.Data.TemplatePlaceholderNameAndValues);
|
||||
_downstreamContext.ServiceProviderConfiguration.ShouldBe(_config.ServiceProviderConfiguration);
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Moq;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Builder;
|
||||
using Ocelot.DownstreamRouteFinder;
|
||||
using Ocelot.DownstreamRouteFinder.Finder;
|
||||
using Ocelot.DownstreamRouteFinder.Middleware;
|
||||
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
||||
using Ocelot.Logging;
|
||||
using Ocelot.Responses;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
using Ocelot.Configuration.Repository;
|
||||
using Ocelot.Middleware;
|
||||
using Ocelot.Middleware.Multiplexer;
|
||||
|
||||
public class DownstreamRouteFinderMiddlewareTests
|
||||
{
|
||||
private readonly Mock<IDownstreamRouteProvider> _finder;
|
||||
private readonly Mock<IDownstreamRouteProviderFactory> _factory;
|
||||
private readonly Mock<IInternalConfigurationRepository> _repo;
|
||||
private Response<DownstreamRoute> _downstreamRoute;
|
||||
private IInternalConfiguration _config;
|
||||
private Mock<IOcelotLoggerFactory> _loggerFactory;
|
||||
private Mock<IOcelotLogger> _logger;
|
||||
private readonly DownstreamRouteFinderMiddleware _middleware;
|
||||
private readonly DownstreamContext _downstreamContext;
|
||||
private OcelotRequestDelegate _next;
|
||||
private readonly Mock<IMultiplexer> _multiplexer;
|
||||
|
||||
public DownstreamRouteFinderMiddlewareTests()
|
||||
{
|
||||
_repo = new Mock<IInternalConfigurationRepository>();
|
||||
_finder = new Mock<IDownstreamRouteProvider>();
|
||||
_factory = new Mock<IDownstreamRouteProviderFactory>();
|
||||
_factory.Setup(x => x.Get(It.IsAny<IInternalConfiguration>())).Returns(_finder.Object);
|
||||
_downstreamContext = new DownstreamContext(new DefaultHttpContext());
|
||||
_loggerFactory = new Mock<IOcelotLoggerFactory>();
|
||||
_logger = new Mock<IOcelotLogger>();
|
||||
_loggerFactory.Setup(x => x.CreateLogger<DownstreamRouteFinderMiddleware>()).Returns(_logger.Object);
|
||||
_next = context => Task.CompletedTask;
|
||||
_multiplexer = new Mock<IMultiplexer>();
|
||||
_middleware = new DownstreamRouteFinderMiddleware(_next, _loggerFactory.Object, _factory.Object, _repo.Object, _multiplexer.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_call_scoped_data_repository_correctly()
|
||||
{
|
||||
var config = new InternalConfiguration(null, null, new ServiceProviderConfigurationBuilder().Build(), "", new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(), new HttpHandlerOptionsBuilder().Build());
|
||||
|
||||
var downstreamReRoute = new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("any old string")
|
||||
.WithUpstreamHttpMethod(new List<string> {"Get"})
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenTheDownStreamRouteFinderReturns(
|
||||
new DownstreamRoute(
|
||||
new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(downstreamReRoute)
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.Build())))
|
||||
.And(x => GivenTheFollowingConfig(config))
|
||||
.When(x => x.WhenICallTheMiddleware())
|
||||
.Then(x => x.ThenTheScopedDataRepositoryIsCalledCorrectly())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void WhenICallTheMiddleware()
|
||||
{
|
||||
_middleware.Invoke(_downstreamContext).GetAwaiter().GetType();
|
||||
}
|
||||
|
||||
private void GivenTheFollowingConfig(IInternalConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
_downstreamContext.Configuration = config;
|
||||
}
|
||||
|
||||
private void GivenTheDownStreamRouteFinderReturns(DownstreamRoute downstreamRoute)
|
||||
{
|
||||
_downstreamRoute = new OkResponse<DownstreamRoute>(downstreamRoute);
|
||||
_finder
|
||||
.Setup(x => x.Get(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<IInternalConfiguration>(), It.IsAny<string>()))
|
||||
.Returns(_downstreamRoute);
|
||||
}
|
||||
|
||||
private void ThenTheScopedDataRepositoryIsCalledCorrectly()
|
||||
{
|
||||
_downstreamContext.TemplatePlaceholderNameAndValues.ShouldBe(_downstreamRoute.Data.TemplatePlaceholderNameAndValues);
|
||||
_downstreamContext.Configuration.ServiceProviderConfiguration.ShouldBe(_config.ServiceProviderConfiguration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,98 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Builder;
|
||||
using Ocelot.DownstreamRouteFinder;
|
||||
using Ocelot.DownstreamRouteFinder.Finder;
|
||||
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
||||
using Ocelot.Responses;
|
||||
using Ocelot.Values;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
{
|
||||
using Ocelot.Configuration.Creator;
|
||||
|
||||
public class DownstreamRouteProviderFactoryTests
|
||||
{
|
||||
private readonly DownstreamRouteProviderFactory _factory;
|
||||
private IInternalConfiguration _config;
|
||||
private IDownstreamRouteProvider _result;
|
||||
|
||||
public DownstreamRouteProviderFactoryTests()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<IPlaceholderNameAndValueFinder, UrlPathPlaceholderNameAndValueFinder>();
|
||||
services.AddSingleton<IUrlPathToUrlTemplateMatcher, RegExUrlMatcher>();
|
||||
services.AddSingleton<IQoSOptionsCreator, QoSOptionsCreator>();
|
||||
services.AddSingleton<IDownstreamRouteProvider, Ocelot.DownstreamRouteFinder.Finder.DownstreamRouteFinder>();
|
||||
services.AddSingleton<IDownstreamRouteProvider, Ocelot.DownstreamRouteFinder.Finder.DownstreamRouteCreator>();
|
||||
var provider = services.BuildServiceProvider();
|
||||
_factory = new DownstreamRouteProviderFactory(provider);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_downstream_route_finder()
|
||||
{
|
||||
var reRoutes = new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder().Build()
|
||||
};
|
||||
|
||||
this.Given(_ => GivenTheReRoutes(reRoutes))
|
||||
.When(_ => WhenIGet())
|
||||
.Then(_ => ThenTheResultShouldBe<Ocelot.DownstreamRouteFinder.Finder.DownstreamRouteFinder>())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_downstream_route_finder_as_no_service_discovery()
|
||||
{
|
||||
var spConfig = new ServiceProviderConfigurationBuilder().Build();
|
||||
var reRoutes = new List<ReRoute>
|
||||
{
|
||||
};
|
||||
|
||||
this.Given(_ => GivenTheReRoutes(reRoutes, spConfig))
|
||||
.When(_ => WhenIGet())
|
||||
.Then(_ => ThenTheResultShouldBe<Ocelot.DownstreamRouteFinder.Finder.DownstreamRouteFinder>())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_downstream_route_creator()
|
||||
{
|
||||
var spConfig = new ServiceProviderConfigurationBuilder().WithHost("test").WithPort(50).Build();
|
||||
var reRoutes = new List<ReRoute>
|
||||
{
|
||||
};
|
||||
this.Given(_ => GivenTheReRoutes(reRoutes, spConfig))
|
||||
.When(_ => WhenIGet())
|
||||
.Then(_ => ThenTheResultShouldBe<Ocelot.DownstreamRouteFinder.Finder.DownstreamRouteCreator>())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void ThenTheResultShouldBe<T>()
|
||||
{
|
||||
_result.ShouldBeOfType<T>();
|
||||
}
|
||||
|
||||
private void WhenIGet()
|
||||
{
|
||||
_result = _factory.Get(_config);
|
||||
}
|
||||
|
||||
private void GivenTheReRoutes(List<ReRoute> reRoutes)
|
||||
{
|
||||
_config = new InternalConfiguration(reRoutes, "", null, "", new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(), new HttpHandlerOptionsBuilder().Build());
|
||||
}
|
||||
|
||||
private void GivenTheReRoutes(List<ReRoute> reRoutes, ServiceProviderConfiguration config)
|
||||
{
|
||||
_config = new InternalConfiguration(reRoutes, "", config, "", new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(), new HttpHandlerOptionsBuilder().Build());
|
||||
}
|
||||
}
|
||||
}
|
@ -192,8 +192,9 @@
|
||||
}
|
||||
|
||||
private void GivenTheServiceProviderConfigIs(ServiceProviderConfiguration config)
|
||||
{
|
||||
_downstreamContext.ServiceProviderConfiguration = config;
|
||||
{
|
||||
var configuration = new InternalConfiguration(null, null, config, null, null, null, null, null);
|
||||
_downstreamContext.Configuration = configuration;
|
||||
}
|
||||
|
||||
private void WhenICallTheMiddleware()
|
||||
|
@ -51,7 +51,7 @@ namespace Ocelot.UnitTests.Errors
|
||||
[Fact]
|
||||
public void NoDownstreamException()
|
||||
{
|
||||
var config = new InternalConfiguration(null, null, null, null);
|
||||
var config = new InternalConfiguration(null, null, null, null, null, null, null, null);
|
||||
|
||||
this.Given(_ => GivenAnExceptionWillNotBeThrownDownstream())
|
||||
.And(_ => GivenTheConfigurationIs(config))
|
||||
@ -64,7 +64,7 @@ namespace Ocelot.UnitTests.Errors
|
||||
[Fact]
|
||||
public void DownstreamException()
|
||||
{
|
||||
var config = new InternalConfiguration(null, null, null, null);
|
||||
var config = new InternalConfiguration(null, null, null, null, null, null, null, null);
|
||||
|
||||
this.Given(_ => GivenAnExceptionWillBeThrownDownstream())
|
||||
.And(_ => GivenTheConfigurationIs(config))
|
||||
@ -76,7 +76,7 @@ namespace Ocelot.UnitTests.Errors
|
||||
[Fact]
|
||||
public void ShouldSetRequestId()
|
||||
{
|
||||
var config = new InternalConfiguration(null, null, null, "requestidkey");
|
||||
var config = new InternalConfiguration(null, null, null, "requestidkey", null, null, null, null);
|
||||
|
||||
this.Given(_ => GivenAnExceptionWillNotBeThrownDownstream())
|
||||
.And(_ => GivenTheConfigurationIs(config))
|
||||
@ -89,7 +89,7 @@ namespace Ocelot.UnitTests.Errors
|
||||
[Fact]
|
||||
public void ShouldSetAspDotNetRequestId()
|
||||
{
|
||||
var config = new InternalConfiguration(null, null, null, null);
|
||||
var config = new InternalConfiguration(null, null, null, null, null, null, null, null);
|
||||
|
||||
this.Given(_ => GivenAnExceptionWillNotBeThrownDownstream())
|
||||
.And(_ => GivenTheConfigurationIs(config))
|
||||
|
@ -33,7 +33,7 @@ namespace Ocelot.UnitTests.LoadBalancer
|
||||
public void should_store_load_balancer_on_first_request()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithReRouteKey("test")
|
||||
.WithLoadBalancerKey("test")
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenThereIsALoadBalancer(reRoute, new FakeLoadBalancer()))
|
||||
@ -46,7 +46,7 @@ namespace Ocelot.UnitTests.LoadBalancer
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithLoadBalancerOptions(new LoadBalancerOptions("FakeLoadBalancer", "", 0))
|
||||
.WithReRouteKey("test")
|
||||
.WithLoadBalancerKey("test")
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenThereIsALoadBalancer(reRoute, new FakeLoadBalancer()))
|
||||
@ -60,12 +60,12 @@ namespace Ocelot.UnitTests.LoadBalancer
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithLoadBalancerOptions(new LoadBalancerOptions("FakeLoadBalancer", "", 0))
|
||||
.WithReRouteKey("test")
|
||||
.WithLoadBalancerKey("test")
|
||||
.Build();
|
||||
|
||||
var reRouteTwo = new DownstreamReRouteBuilder()
|
||||
.WithLoadBalancerOptions(new LoadBalancerOptions("FakeRoundRobinLoadBalancer", "", 0))
|
||||
.WithReRouteKey("testtwo")
|
||||
.WithLoadBalancerKey("testtwo")
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenThereIsALoadBalancer(reRoute, new FakeLoadBalancer()))
|
||||
@ -92,12 +92,12 @@ namespace Ocelot.UnitTests.LoadBalancer
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithLoadBalancerOptions(new LoadBalancerOptions("FakeLoadBalancer", "", 0))
|
||||
.WithReRouteKey("test")
|
||||
.WithLoadBalancerKey("test")
|
||||
.Build();
|
||||
|
||||
var reRouteTwo = new DownstreamReRouteBuilder()
|
||||
.WithLoadBalancerOptions(new LoadBalancerOptions("LeastConnection", "", 0))
|
||||
.WithReRouteKey("test")
|
||||
.WithLoadBalancerKey("test")
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenThereIsALoadBalancer(reRoute, new FakeLoadBalancer()))
|
||||
|
@ -117,7 +117,8 @@ namespace Ocelot.UnitTests.LoadBalancer
|
||||
private void GivenTheConfigurationIs(ServiceProviderConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
_downstreamContext.ServiceProviderConfiguration = config;
|
||||
var configuration = new InternalConfiguration(null, null, config, null, null, null, null, null);
|
||||
_downstreamContext.Configuration = configuration;
|
||||
}
|
||||
|
||||
private void GivenTheDownStreamUrlIs(string downstreamUrl)
|
||||
|
@ -38,14 +38,21 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_follow_ordering_add_specifics()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithIsQos(true)
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.WithTimeoutValue(1)
|
||||
.WithDurationOfBreak(1)
|
||||
.WithExceptionsAllowedBeforeBreaking(1)
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true))
|
||||
.WithDelegatingHandlers(new List<string>
|
||||
{
|
||||
"FakeDelegatingHandler",
|
||||
"FakeDelegatingHandlerTwo"
|
||||
})
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.Build();
|
||||
|
||||
this.Given(x => GivenTheFollowingRequest(reRoute))
|
||||
@ -67,7 +74,14 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_follow_ordering_order_specifics_and_globals()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithIsQos(true)
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.WithTimeoutValue(1)
|
||||
.WithDurationOfBreak(1)
|
||||
.WithExceptionsAllowedBeforeBreaking(1)
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true))
|
||||
.WithDelegatingHandlers(new List<string>
|
||||
{
|
||||
@ -75,7 +89,7 @@ namespace Ocelot.UnitTests.Requester
|
||||
"FakeDelegatingHandler",
|
||||
"FakeDelegatingHandlerFour"
|
||||
})
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.Build();
|
||||
|
||||
this.Given(x => GivenTheFollowingRequest(reRoute))
|
||||
@ -97,14 +111,21 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_follow_ordering_order_specifics()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithIsQos(true)
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.WithTimeoutValue(1)
|
||||
.WithDurationOfBreak(1)
|
||||
.WithExceptionsAllowedBeforeBreaking(1)
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true))
|
||||
.WithDelegatingHandlers(new List<string>
|
||||
{
|
||||
"FakeDelegatingHandlerTwo",
|
||||
"FakeDelegatingHandler"
|
||||
})
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.Build();
|
||||
|
||||
this.Given(x => GivenTheFollowingRequest(reRoute))
|
||||
@ -126,13 +147,20 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_follow_ordering_order_and_only_add_specifics_in_config()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithIsQos(true)
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.WithTimeoutValue(1)
|
||||
.WithDurationOfBreak(1)
|
||||
.WithExceptionsAllowedBeforeBreaking(1)
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true))
|
||||
.WithDelegatingHandlers(new List<string>
|
||||
{
|
||||
"FakeDelegatingHandler",
|
||||
})
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.Build();
|
||||
|
||||
this.Given(x => GivenTheFollowingRequest(reRoute))
|
||||
@ -153,9 +181,16 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_follow_ordering_dont_add_specifics()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithIsQos(true)
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.WithTimeoutValue(1)
|
||||
.WithDurationOfBreak(1)
|
||||
.WithExceptionsAllowedBeforeBreaking(1)
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, true))
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.Build();
|
||||
|
||||
this.Given(x => GivenTheFollowingRequest(reRoute))
|
||||
@ -175,14 +210,18 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_apply_re_route_specific()
|
||||
{
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false))
|
||||
.WithDelegatingHandlers(new List<string>
|
||||
{
|
||||
"FakeDelegatingHandler",
|
||||
"FakeDelegatingHandlerTwo"
|
||||
})
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.Build();
|
||||
|
||||
this.Given(x => GivenTheFollowingRequest(reRoute))
|
||||
@ -197,8 +236,15 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_all_from_all_routes_provider_and_qos()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithIsQos(true)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false)).WithReRouteKey("").Build();
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.WithTimeoutValue(1)
|
||||
.WithDurationOfBreak(1)
|
||||
.WithExceptionsAllowedBeforeBreaking(1)
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false)).WithLoadBalancerKey("").Build();
|
||||
|
||||
this.Given(x => GivenTheFollowingRequest(reRoute))
|
||||
.And(x => GivenTheQosProviderHouseReturns(new OkResponse<IQoSProvider>(It.IsAny<PollyQoSProvider>())))
|
||||
@ -213,8 +259,12 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_return_provider_with_no_delegates()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithIsQos(false)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false)).WithReRouteKey("").Build();
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false)).WithLoadBalancerKey("").Build();
|
||||
|
||||
this.Given(x => GivenTheFollowingRequest(reRoute))
|
||||
.And(x => GivenTheServiceProviderReturnsNothing())
|
||||
@ -226,8 +276,15 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_return_provider_with_qos_delegate()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithIsQos(true)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false)).WithReRouteKey("").Build();
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.WithTimeoutValue(1)
|
||||
.WithDurationOfBreak(1)
|
||||
.WithExceptionsAllowedBeforeBreaking(1)
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false)).WithLoadBalancerKey("").Build();
|
||||
|
||||
this.Given(x => GivenTheFollowingRequest(reRoute))
|
||||
.And(x => GivenTheQosProviderHouseReturns(new OkResponse<IQoSProvider>(It.IsAny<PollyQoSProvider>())))
|
||||
@ -241,8 +298,15 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_return_error()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithIsQos(true)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false)).WithReRouteKey("").Build();
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.WithTimeoutValue(1)
|
||||
.WithDurationOfBreak(1)
|
||||
.WithExceptionsAllowedBeforeBreaking(1)
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(true, true, false)).WithLoadBalancerKey("").Build();
|
||||
|
||||
this.Given(x => GivenTheFollowingRequest(reRoute))
|
||||
.And(x => GivenTheQosProviderHouseReturns(new ErrorResponse<IQoSProvider>(It.IsAny<Error>())))
|
||||
|
@ -46,10 +46,13 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_build_http_client()
|
||||
{
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithIsQos(false)
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false))
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.Build();
|
||||
|
||||
@ -63,10 +66,13 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_log_if_ignoring_ssl_errors()
|
||||
{
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithIsQos(false)
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false))
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.WithDangerousAcceptAnyServerCertificateValidator(true)
|
||||
.Build();
|
||||
@ -82,10 +88,13 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_call_delegating_handlers_in_order()
|
||||
{
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithIsQos(false)
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false))
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.Build();
|
||||
|
||||
@ -110,10 +119,13 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_re_use_cookies_from_container()
|
||||
{
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithIsQos(false)
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, true, false))
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.Build();
|
||||
|
||||
@ -142,10 +154,13 @@ namespace Ocelot.UnitTests.Requester
|
||||
|
||||
HttpMethod method = new HttpMethod(verb);
|
||||
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithIsQos(false)
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false))
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.Build();
|
||||
|
||||
|
@ -47,10 +47,13 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_call_request_correctly()
|
||||
{
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithIsQos(false)
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false))
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.Build();
|
||||
|
||||
@ -70,10 +73,13 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_call_request_unable_to_complete_request()
|
||||
{
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithIsQos(false)
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false))
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.WithQosOptions(new QoSOptionsBuilder().Build())
|
||||
.Build();
|
||||
|
||||
@ -92,10 +98,13 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void http_client_request_times_out()
|
||||
{
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithIsQos(false)
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithHttpHandlerOptions(new HttpHandlerOptions(false, false, false))
|
||||
.WithReRouteKey("")
|
||||
.WithLoadBalancerKey("")
|
||||
.WithQosOptions(new QoSOptionsBuilder().WithTimeoutValue(1).Build())
|
||||
.Build();
|
||||
|
||||
|
@ -31,9 +31,12 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_return_no_qos_provider()
|
||||
{
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.WithUpstreamHttpMethod(new List<string> { "get" })
|
||||
.WithIsQos(false)
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenAReRoute(reRoute))
|
||||
@ -53,7 +56,6 @@ namespace Ocelot.UnitTests.Requester
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithUpstreamHttpMethod(new List<string> { "get" })
|
||||
.WithIsQos(true)
|
||||
.WithQosOptions(qosOptions)
|
||||
.Build();
|
||||
|
||||
|
@ -25,8 +25,14 @@ namespace Ocelot.UnitTests.Requester
|
||||
|
||||
[Fact]
|
||||
public void should_store_qos_provider_on_first_request()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithQosKey("test").Build();
|
||||
{
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.WithKey("test")
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenThereIsAQoSProvider(reRoute, new FakeQoSProvider()))
|
||||
.Then(x => x.ThenItIsAdded())
|
||||
@ -36,7 +42,13 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_not_store_qos_provider_on_first_request()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithQosKey("test").Build();
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.WithKey("test")
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenThereIsAQoSProvider(reRoute, new FakeQoSProvider()))
|
||||
.When(x => x.WhenWeGetTheQoSProvider(reRoute))
|
||||
@ -47,8 +59,21 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_store_qos_providers_by_key()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithQosKey("test").Build();
|
||||
var reRouteTwo = new DownstreamReRouteBuilder().WithQosKey("testTwo").Build();
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.WithKey("test")
|
||||
.Build();
|
||||
|
||||
var qosOptionsTwo = new QoSOptionsBuilder()
|
||||
.WithKey("testTwo")
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.Build();
|
||||
|
||||
var reRouteTwo = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptionsTwo)
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenThereIsAQoSProvider(reRoute, new FakeQoSProvider()))
|
||||
.And(x => x.GivenThereIsAQoSProvider(reRouteTwo, new FakePollyQoSProvider()))
|
||||
@ -62,7 +87,12 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_return_error_if_no_qos_provider_with_key()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().Build();
|
||||
var qosOptions = new QoSOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(qosOptions)
|
||||
.Build();
|
||||
|
||||
this.When(x => x.WhenWeGetTheQoSProvider(reRoute))
|
||||
.Then(x => x.ThenAnErrorIsReturned())
|
||||
@ -72,9 +102,24 @@ namespace Ocelot.UnitTests.Requester
|
||||
[Fact]
|
||||
public void should_get_new_qos_provider_if_reroute_qos_provider_has_changed()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder().WithQosKey("test").Build();
|
||||
var useQoSOptions = new QoSOptionsBuilder()
|
||||
.WithTimeoutValue(1)
|
||||
.WithKey("test")
|
||||
.WithDurationOfBreak(1)
|
||||
.WithExceptionsAllowedBeforeBreaking(1)
|
||||
.Build();
|
||||
|
||||
var reRouteTwo = new DownstreamReRouteBuilder().WithQosKey("test").WithIsQos(true).Build();
|
||||
var dontUseQoSOptions = new QoSOptionsBuilder()
|
||||
.WithKey("test")
|
||||
.Build();
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(dontUseQoSOptions)
|
||||
.Build();
|
||||
|
||||
var reRouteTwo = new DownstreamReRouteBuilder()
|
||||
.WithQosOptions(useQoSOptions)
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenThereIsAQoSProvider(reRoute, new FakeQoSProvider()))
|
||||
.When(x => x.WhenWeGetTheQoSProvider(reRoute))
|
||||
|
Reference in New Issue
Block a user