mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 08:18:16 +08:00
Changed routing to support a catch all style (#187)
* Changed routing to support a catch all style * refactoring placeholder tuff * implemented simple priority in the routing
This commit is contained in:
@ -52,7 +52,7 @@ namespace Ocelot.AcceptanceTests
|
||||
}
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879", "", 200, "Hello from Laura"))
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879/", "/", 200, "Hello from Laura"))
|
||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||
.And(x => _steps.GivenOcelotIsRunning())
|
||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
|
||||
@ -61,6 +61,145 @@ namespace Ocelot.AcceptanceTests
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_response_200_favouring_forward_slash_with_path_route()
|
||||
{
|
||||
var configuration = new FileConfiguration
|
||||
{
|
||||
ReRoutes = new List<FileReRoute>
|
||||
{
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamPathTemplate = "/{url}",
|
||||
DownstreamScheme = "http",
|
||||
DownstreamHost = "localhost",
|
||||
DownstreamPort = 51880,
|
||||
UpstreamPathTemplate = "/{url}",
|
||||
UpstreamHttpMethod = new List<string> { "Get" },
|
||||
},
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamPathTemplate = "/",
|
||||
DownstreamScheme = "http",
|
||||
DownstreamHost = "localhost",
|
||||
DownstreamPort = 51879,
|
||||
UpstreamPathTemplate = "/",
|
||||
UpstreamHttpMethod = new List<string> { "Get" },
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51880/", "/test", 200, "Hello from Laura"))
|
||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||
.And(x => _steps.GivenOcelotIsRunning())
|
||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/test"))
|
||||
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
|
||||
.And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_response_200_favouring_forward_slash()
|
||||
{
|
||||
var configuration = new FileConfiguration
|
||||
{
|
||||
ReRoutes = new List<FileReRoute>
|
||||
{
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamPathTemplate = "/{url}",
|
||||
DownstreamScheme = "http",
|
||||
DownstreamHost = "localhost",
|
||||
DownstreamPort = 51880,
|
||||
UpstreamPathTemplate = "/{url}",
|
||||
UpstreamHttpMethod = new List<string> { "Get" },
|
||||
},
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamPathTemplate = "/",
|
||||
DownstreamScheme = "http",
|
||||
DownstreamHost = "localhost",
|
||||
DownstreamPort = 51879,
|
||||
UpstreamPathTemplate = "/",
|
||||
UpstreamHttpMethod = new List<string> { "Get" },
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879/", "/", 200, "Hello from Laura"))
|
||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||
.And(x => _steps.GivenOcelotIsRunning())
|
||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
|
||||
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
|
||||
.And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_response_200_favouring_forward_slash_route_because_it_is_first()
|
||||
{
|
||||
var configuration = new FileConfiguration
|
||||
{
|
||||
ReRoutes = new List<FileReRoute>
|
||||
{
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamPathTemplate = "/",
|
||||
DownstreamScheme = "http",
|
||||
DownstreamHost = "localhost",
|
||||
DownstreamPort = 51880,
|
||||
UpstreamPathTemplate = "/",
|
||||
UpstreamHttpMethod = new List<string> { "Get" },
|
||||
},
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamPathTemplate = "/{url}",
|
||||
DownstreamScheme = "http",
|
||||
DownstreamHost = "localhost",
|
||||
DownstreamPort = 51879,
|
||||
UpstreamPathTemplate = "/{url}",
|
||||
UpstreamHttpMethod = new List<string> { "Get" },
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51880/", "/", 200, "Hello from Laura"))
|
||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||
.And(x => _steps.GivenOcelotIsRunning())
|
||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
|
||||
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
|
||||
.And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_response_200_with_nothing_and_placeholder_only()
|
||||
{
|
||||
var configuration = new FileConfiguration
|
||||
{
|
||||
ReRoutes = new List<FileReRoute>
|
||||
{
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamPathTemplate = "/{url}",
|
||||
DownstreamScheme = "http",
|
||||
DownstreamHost = "localhost",
|
||||
DownstreamPort = 51879,
|
||||
UpstreamPathTemplate = "/{url}",
|
||||
UpstreamHttpMethod = new List<string> { "Get" },
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879", "/", 200, "Hello from Laura"))
|
||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||
.And(x => _steps.GivenOcelotIsRunning())
|
||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway(""))
|
||||
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
|
||||
.And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_response_200_with_simple_url()
|
||||
{
|
||||
@ -80,7 +219,7 @@ namespace Ocelot.AcceptanceTests
|
||||
}
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879", "", 200, "Hello from Laura"))
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879", "/", 200, "Hello from Laura"))
|
||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||
.And(x => _steps.GivenOcelotIsRunning())
|
||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
|
||||
@ -378,7 +517,7 @@ namespace Ocelot.AcceptanceTests
|
||||
}
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879", "", 201, string.Empty))
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879", "/", 201, string.Empty))
|
||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||
.And(x => _steps.GivenOcelotIsRunning())
|
||||
.And(x => _steps.GivenThePostHasContent("postContent"))
|
||||
@ -406,7 +545,7 @@ namespace Ocelot.AcceptanceTests
|
||||
}
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879", "", 200, "Hello from Laura"))
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879", "/newThing", 200, "Hello from Laura"))
|
||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||
.And(x => _steps.GivenOcelotIsRunning())
|
||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/newThing?DeviceType=IphoneApp&Browser=moonpigIphone&BrowserString=-&CountryCode=123&DeviceName=iPhone 5 (GSM+CDMA)&OperatingSystem=iPhone OS 7.1.2&BrowserVersion=3708AdHoc&ipAddress=-"))
|
||||
@ -434,7 +573,7 @@ namespace Ocelot.AcceptanceTests
|
||||
}
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879", "/myApp1Name/api/products/1", 200, "Some Product"))
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879", "/api/products/1", 200, "Some Product"))
|
||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||
.And(x => _steps.GivenOcelotIsRunning())
|
||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/myApp1Name/api/products/1"))
|
||||
@ -490,7 +629,7 @@ namespace Ocelot.AcceptanceTests
|
||||
}
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879", "", 200, "Hello from Laura"))
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879", "/", 200, "Hello from Laura"))
|
||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||
.And(x => _steps.GivenOcelotIsRunning())
|
||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
|
||||
@ -564,7 +703,7 @@ namespace Ocelot.AcceptanceTests
|
||||
}
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51899", "", 200, "Hello from Laura"))
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51899", "/api/swagger/lib/backbone-min.js", 200, "Hello from Laura"))
|
||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||
.And(x => _steps.GivenOcelotIsRunning())
|
||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/platform/swagger/lib/backbone-min.js"))
|
||||
@ -587,8 +726,17 @@ namespace Ocelot.AcceptanceTests
|
||||
app.Run(async context =>
|
||||
{
|
||||
_downstreamPath = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value;
|
||||
context.Response.StatusCode = statusCode;
|
||||
await context.Response.WriteAsync(responseBody);
|
||||
|
||||
if(_downstreamPath != basePath)
|
||||
{
|
||||
context.Response.StatusCode = statusCode;
|
||||
await context.Response.WriteAsync("downstream path didnt match base path");
|
||||
}
|
||||
else
|
||||
{
|
||||
context.Response.StatusCode = statusCode;
|
||||
await context.Response.WriteAsync(responseBody);
|
||||
}
|
||||
});
|
||||
})
|
||||
.Build();
|
||||
|
@ -29,7 +29,7 @@
|
||||
{
|
||||
this.Given(x => x.GivenTheDownStreamRouteIs(
|
||||
new DownstreamRoute(
|
||||
new List<UrlPathPlaceholderNameAndValue>(),
|
||||
new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder().WithUpstreamHttpMethod(new List<string> { "Get" }).Build())))
|
||||
.When(x => x.WhenICallTheMiddleware())
|
||||
.Then(x => x.ThenTheUserIsAuthenticated())
|
||||
|
@ -32,7 +32,7 @@
|
||||
[Fact]
|
||||
public void should_call_authorisation_service()
|
||||
{
|
||||
this.Given(x => x.GivenTheDownStreamRouteIs(new DownstreamRoute(new List<UrlPathPlaceholderNameAndValue>(),
|
||||
this.Given(x => x.GivenTheDownStreamRouteIs(new DownstreamRoute(new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithIsAuthorised(true)
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
|
@ -94,7 +94,7 @@
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.Build();
|
||||
|
||||
var downstreamRoute = new DownstreamRoute(new List<UrlPathPlaceholderNameAndValue>(), reRoute);
|
||||
var downstreamRoute = new DownstreamRoute(new List<PlaceholderNameAndValue>(), reRoute);
|
||||
|
||||
ScopedRepository
|
||||
.Setup(x => x.Get<DownstreamRoute>(It.IsAny<string>()))
|
||||
|
@ -31,7 +31,7 @@
|
||||
[Fact]
|
||||
public void should_call_claims_to_request_correctly()
|
||||
{
|
||||
var downstreamRoute = new DownstreamRoute(new List<UrlPathPlaceholderNameAndValue>(),
|
||||
var downstreamRoute = new DownstreamRoute(new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("any old string")
|
||||
.WithClaimsToClaims(new List<ClaimToThing>
|
||||
|
@ -18,6 +18,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
using Ocelot.DependencyInjection;
|
||||
using Ocelot.Errors;
|
||||
using Ocelot.UnitTests.TestData;
|
||||
using Ocelot.Values;
|
||||
|
||||
public class FileConfigurationCreatorTests
|
||||
{
|
||||
@ -367,7 +368,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern("(?i)/api/products/.*/$")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("(?i)/api/products/.*/$", 1))
|
||||
.Build()
|
||||
}))
|
||||
.BDDfy();
|
||||
@ -580,7 +581,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
result.DownstreamPathTemplate.Value.ShouldBe(expected.DownstreamPathTemplate.Value);
|
||||
result.UpstreamHttpMethod.ShouldBe(expected.UpstreamHttpMethod);
|
||||
result.UpstreamPathTemplate.Value.ShouldBe(expected.UpstreamPathTemplate.Value);
|
||||
result.UpstreamTemplatePattern.ShouldBe(expected.UpstreamTemplatePattern);
|
||||
result.UpstreamTemplatePattern?.Template.ShouldBe(expected.UpstreamTemplatePattern?.Template);
|
||||
result.ClaimsToClaims.Count.ShouldBe(expected.ClaimsToClaims.Count);
|
||||
result.ClaimsToHeaders.Count.ShouldBe(expected.ClaimsToHeaders.Count);
|
||||
result.ClaimsToQueries.Count.ShouldBe(expected.ClaimsToQueries.Count);
|
||||
@ -623,7 +624,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
_upstreamTemplatePatternCreator
|
||||
.Setup(x => x.Create(It.IsAny<FileReRoute>()))
|
||||
.Returns(pattern);
|
||||
.Returns(new UpstreamPathTemplate(pattern, 1));
|
||||
}
|
||||
|
||||
private void ThenTheRequestIdKeyCreatorIsCalledCorrectly()
|
||||
|
@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using Ocelot.Configuration.Creator;
|
||||
using Ocelot.Configuration.File;
|
||||
using Ocelot.Values;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
@ -10,7 +12,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
private FileReRoute _fileReRoute;
|
||||
private UpstreamTemplatePatternCreator _creator;
|
||||
private string _result;
|
||||
private UpstreamPathTemplate _result;
|
||||
|
||||
public UpstreamTemplatePatternCreatorTests()
|
||||
{
|
||||
@ -29,6 +31,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
this.Given(x => x.GivenTheFollowingFileReRoute(fileReRoute))
|
||||
.When(x => x.WhenICreateTheTemplatePattern())
|
||||
.Then(x => x.ThenTheFollowingIsReturned("^(?i)/PRODUCTS/[0-9a-zA-Z].*$"))
|
||||
.And(x => ThenThePriorityIs(1))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -45,6 +48,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
this.Given(x => x.GivenTheFollowingFileReRoute(fileReRoute))
|
||||
.When(x => x.WhenICreateTheTemplatePattern())
|
||||
.Then(x => x.ThenTheFollowingIsReturned("^(?i)/PRODUCTS(/|)$"))
|
||||
.And(x => ThenThePriorityIs(1))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -59,6 +63,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
this.Given(x => x.GivenTheFollowingFileReRoute(fileReRoute))
|
||||
.When(x => x.WhenICreateTheTemplatePattern())
|
||||
.Then(x => x.ThenTheFollowingIsReturned("^/PRODUCTS/[0-9a-zA-Z].*$"))
|
||||
.And(x => ThenThePriorityIs(1))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -74,6 +79,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
this.Given(x => x.GivenTheFollowingFileReRoute(fileReRoute))
|
||||
.When(x => x.WhenICreateTheTemplatePattern())
|
||||
.Then(x => x.ThenTheFollowingIsReturned("^/api/products/[0-9a-zA-Z].*$"))
|
||||
.And(x => ThenThePriorityIs(1))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -89,6 +95,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
this.Given(x => x.GivenTheFollowingFileReRoute(fileReRoute))
|
||||
.When(x => x.WhenICreateTheTemplatePattern())
|
||||
.Then(x => x.ThenTheFollowingIsReturned("^/api/products/[0-9a-zA-Z].*/variants/[0-9a-zA-Z].*$"))
|
||||
.And(x => ThenThePriorityIs(1))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -104,6 +111,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
this.Given(x => x.GivenTheFollowingFileReRoute(fileReRoute))
|
||||
.When(x => x.WhenICreateTheTemplatePattern())
|
||||
.Then(x => x.ThenTheFollowingIsReturned("^/api/products/[0-9a-zA-Z].*/variants/[0-9a-zA-Z].*(/|)$"))
|
||||
.And(x => ThenThePriorityIs(1))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -118,6 +126,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
this.Given(x => x.GivenTheFollowingFileReRoute(fileReRoute))
|
||||
.When(x => x.WhenICreateTheTemplatePattern())
|
||||
.Then(x => x.ThenTheFollowingIsReturned("^/$"))
|
||||
.And(x => ThenThePriorityIs(1))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -132,6 +141,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
this.Given(x => x.GivenTheFollowingFileReRoute(fileReRoute))
|
||||
.When(x => x.WhenICreateTheTemplatePattern())
|
||||
.Then(x => x.ThenTheFollowingIsReturned("^/.*"))
|
||||
.And(x => ThenThePriorityIs(0))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -147,6 +157,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
this.Given(x => x.GivenTheFollowingFileReRoute(fileReRoute))
|
||||
.When(x => x.WhenICreateTheTemplatePattern())
|
||||
.Then(x => x.ThenTheFollowingIsReturned("^/[0-9a-zA-Z].*/products/variants/[0-9a-zA-Z].*(/|)$"))
|
||||
.And(x => ThenThePriorityIs(1))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -162,7 +173,12 @@ namespace Ocelot.UnitTests.Configuration
|
||||
|
||||
private void ThenTheFollowingIsReturned(string expected)
|
||||
{
|
||||
_result.ShouldBe(expected);
|
||||
_result.Template.ShouldBe(expected);
|
||||
}
|
||||
|
||||
private void ThenThePriorityIs(int v)
|
||||
{
|
||||
_result.Priority.ShouldBe(v);
|
||||
}
|
||||
}
|
||||
}
|
@ -38,7 +38,7 @@
|
||||
|
||||
this.Given(x => x.GivenTheDownStreamRouteFinderReturns(
|
||||
new DownstreamRoute(
|
||||
new List<UrlPathPlaceholderNameAndValue>(),
|
||||
new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("any old string")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
|
@ -2,11 +2,13 @@
|
||||
using Moq;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Builder;
|
||||
using Ocelot.Configuration.Creator;
|
||||
using Ocelot.Configuration.Provider;
|
||||
using Ocelot.DownstreamRouteFinder;
|
||||
using Ocelot.DownstreamRouteFinder.Finder;
|
||||
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
||||
using Ocelot.Responses;
|
||||
using Ocelot.Values;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
@ -17,7 +19,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
{
|
||||
private readonly IDownstreamRouteFinder _downstreamRouteFinder;
|
||||
private readonly Mock<IUrlPathToUrlTemplateMatcher> _mockMatcher;
|
||||
private readonly Mock<IUrlPathPlaceholderNameAndValueFinder> _finder;
|
||||
private readonly Mock<IPlaceholderNameAndValueFinder> _finder;
|
||||
private string _upstreamUrlPath;
|
||||
private Response<DownstreamRoute> _result;
|
||||
private List<ReRoute> _reRoutesConfig;
|
||||
@ -28,10 +30,84 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
public DownstreamRouteFinderTests()
|
||||
{
|
||||
_mockMatcher = new Mock<IUrlPathToUrlTemplateMatcher>();
|
||||
_finder = new Mock<IUrlPathPlaceholderNameAndValueFinder>();
|
||||
_finder = new Mock<IPlaceholderNameAndValueFinder>();
|
||||
_downstreamRouteFinder = new Ocelot.DownstreamRouteFinder.Finder.DownstreamRouteFinder(_mockMatcher.Object, _finder.Object);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void should_return_highest_priority_when_first()
|
||||
{
|
||||
var serviceProviderConfig = new ServiceProviderConfigurationBuilder().Build();
|
||||
|
||||
this.Given(x => x.GivenThereIsAnUpstreamUrlPath("someUpstreamPath"))
|
||||
.And(x => x.GivenTheTemplateVariableAndNameFinderReturns(
|
||||
new OkResponse<List<PlaceholderNameAndValue>>(new List<PlaceholderNameAndValue>())))
|
||||
.And(x => x.GivenTheConfigurationIs(new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 1))
|
||||
.Build(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 0))
|
||||
.Build()
|
||||
}, string.Empty, serviceProviderConfig))
|
||||
.And(x => x.GivenTheUrlMatcherReturns(new OkResponse<UrlMatch>(new UrlMatch(true))))
|
||||
.And(x => x.GivenTheUpstreamHttpMethodIs("Post"))
|
||||
.When(x => x.WhenICallTheFinder())
|
||||
.Then(x => x.ThenTheFollowingIsReturned(new DownstreamRoute(new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 1))
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 1))
|
||||
.Build()
|
||||
)))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_highest_priority_when_lowest()
|
||||
{
|
||||
var serviceProviderConfig = new ServiceProviderConfigurationBuilder().Build();
|
||||
|
||||
this.Given(x => x.GivenThereIsAnUpstreamUrlPath("someUpstreamPath"))
|
||||
.And(x => x.GivenTheTemplateVariableAndNameFinderReturns(
|
||||
new OkResponse<List<PlaceholderNameAndValue>>(new List<PlaceholderNameAndValue>())))
|
||||
.And(x => x.GivenTheConfigurationIs(new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 0))
|
||||
.Build(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 1))
|
||||
.Build()
|
||||
}, string.Empty, serviceProviderConfig))
|
||||
.And(x => x.GivenTheUrlMatcherReturns(new OkResponse<UrlMatch>(new UrlMatch(true))))
|
||||
.And(x => x.GivenTheUpstreamHttpMethodIs("Post"))
|
||||
.When(x => x.WhenICallTheFinder())
|
||||
.Then(x => x.ThenTheFollowingIsReturned(new DownstreamRoute(new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("test", 1))
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.Build()
|
||||
)))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_route()
|
||||
{
|
||||
@ -39,15 +115,15 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
|
||||
this.Given(x => x.GivenThereIsAnUpstreamUrlPath("matchInUrlMatcher/"))
|
||||
.And(x =>x.GivenTheTemplateVariableAndNameFinderReturns(
|
||||
new OkResponse<List<UrlPathPlaceholderNameAndValue>>(
|
||||
new List<UrlPathPlaceholderNameAndValue>())))
|
||||
new OkResponse<List<PlaceholderNameAndValue>>(
|
||||
new List<PlaceholderNameAndValue>())))
|
||||
.And(x => x.GivenTheConfigurationIs(new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern("someUpstreamPath")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1))
|
||||
.Build()
|
||||
}, string.Empty, serviceProviderConfig
|
||||
))
|
||||
@ -56,10 +132,11 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.When(x => x.WhenICallTheFinder())
|
||||
.Then(
|
||||
x => x.ThenTheFollowingIsReturned(new DownstreamRoute(
|
||||
new List<UrlPathPlaceholderNameAndValue>(),
|
||||
new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1))
|
||||
.Build()
|
||||
)))
|
||||
.And(x => x.ThenTheUrlMatcherIsCalledCorrectly())
|
||||
@ -74,15 +151,15 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
|
||||
this.Given(x => x.GivenThereIsAnUpstreamUrlPath("matchInUrlMatcher"))
|
||||
.And(x =>x.GivenTheTemplateVariableAndNameFinderReturns(
|
||||
new OkResponse<List<UrlPathPlaceholderNameAndValue>>(
|
||||
new List<UrlPathPlaceholderNameAndValue>())))
|
||||
new OkResponse<List<PlaceholderNameAndValue>>(
|
||||
new List<PlaceholderNameAndValue>())))
|
||||
.And(x => x.GivenTheConfigurationIs(new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern("someUpstreamPath")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1))
|
||||
.Build()
|
||||
}, string.Empty, serviceProviderConfig
|
||||
))
|
||||
@ -91,10 +168,11 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.When(x => x.WhenICallTheFinder())
|
||||
.Then(
|
||||
x => x.ThenTheFollowingIsReturned(new DownstreamRoute(
|
||||
new List<UrlPathPlaceholderNameAndValue>(),
|
||||
new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1))
|
||||
.Build()
|
||||
)))
|
||||
.And(x => x.ThenTheUrlMatcherIsCalledCorrectly("matchInUrlMatcher"))
|
||||
@ -110,14 +188,14 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.And(
|
||||
x =>
|
||||
x.GivenTheTemplateVariableAndNameFinderReturns(
|
||||
new OkResponse<List<UrlPathPlaceholderNameAndValue>>(new List<UrlPathPlaceholderNameAndValue>())))
|
||||
new OkResponse<List<PlaceholderNameAndValue>>(new List<PlaceholderNameAndValue>())))
|
||||
.And(x => x.GivenTheConfigurationIs(new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern("someUpstreamPath")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1))
|
||||
.Build()
|
||||
}, string.Empty, serviceProviderConfig
|
||||
))
|
||||
@ -125,10 +203,11 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.And(x => x.GivenTheUpstreamHttpMethodIs("Get"))
|
||||
.When(x => x.WhenICallTheFinder())
|
||||
.Then(
|
||||
x => x.ThenTheFollowingIsReturned(new DownstreamRoute(new List<UrlPathPlaceholderNameAndValue>(),
|
||||
x => x.ThenTheFollowingIsReturned(new DownstreamRoute(new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("someUpstreamPath", 1))
|
||||
.Build()
|
||||
)))
|
||||
.And(x => x.ThenTheUrlMatcherIsNotCalled())
|
||||
@ -144,20 +223,20 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.And(
|
||||
x =>
|
||||
x.GivenTheTemplateVariableAndNameFinderReturns(
|
||||
new OkResponse<List<UrlPathPlaceholderNameAndValue>>(new List<UrlPathPlaceholderNameAndValue>())))
|
||||
new OkResponse<List<PlaceholderNameAndValue>>(new List<PlaceholderNameAndValue>())))
|
||||
.And(x => x.GivenTheConfigurationIs(new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern("")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1))
|
||||
.Build(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPathForAPost")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern("")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1))
|
||||
.Build()
|
||||
}, string.Empty, serviceProviderConfig
|
||||
))
|
||||
@ -165,10 +244,11 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.And(x => x.GivenTheUpstreamHttpMethodIs("Post"))
|
||||
.When(x => x.WhenICallTheFinder())
|
||||
.Then(
|
||||
x => x.ThenTheFollowingIsReturned(new DownstreamRoute(new List<UrlPathPlaceholderNameAndValue>(),
|
||||
x => x.ThenTheFollowingIsReturned(new DownstreamRoute(new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPathForAPost")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1))
|
||||
.Build()
|
||||
)))
|
||||
.BDDfy();
|
||||
@ -186,7 +266,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.WithDownstreamPathTemplate("somPath")
|
||||
.WithUpstreamPathTemplate("somePath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithUpstreamTemplatePattern("somePath")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("somePath", 1))
|
||||
.Build(),
|
||||
}, string.Empty, serviceProviderConfig
|
||||
))
|
||||
@ -208,14 +288,14 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.And(
|
||||
x =>
|
||||
x.GivenTheTemplateVariableAndNameFinderReturns(
|
||||
new OkResponse<List<UrlPathPlaceholderNameAndValue>>(new List<UrlPathPlaceholderNameAndValue>())))
|
||||
new OkResponse<List<PlaceholderNameAndValue>>(new List<PlaceholderNameAndValue>())))
|
||||
.And(x => x.GivenTheConfigurationIs(new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get", "Post" })
|
||||
.WithUpstreamTemplatePattern("")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1))
|
||||
.Build()
|
||||
}, string.Empty, serviceProviderConfig
|
||||
))
|
||||
@ -223,10 +303,11 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.And(x => x.GivenTheUpstreamHttpMethodIs("Post"))
|
||||
.When(x => x.WhenICallTheFinder())
|
||||
.Then(
|
||||
x => x.ThenTheFollowingIsReturned(new DownstreamRoute(new List<UrlPathPlaceholderNameAndValue>(),
|
||||
x => x.ThenTheFollowingIsReturned(new DownstreamRoute(new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1))
|
||||
.Build()
|
||||
)))
|
||||
.BDDfy();
|
||||
@ -241,14 +322,14 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.And(
|
||||
x =>
|
||||
x.GivenTheTemplateVariableAndNameFinderReturns(
|
||||
new OkResponse<List<UrlPathPlaceholderNameAndValue>>(new List<UrlPathPlaceholderNameAndValue>())))
|
||||
new OkResponse<List<PlaceholderNameAndValue>>(new List<PlaceholderNameAndValue>())))
|
||||
.And(x => x.GivenTheConfigurationIs(new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string>())
|
||||
.WithUpstreamTemplatePattern("")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1))
|
||||
.Build()
|
||||
}, string.Empty, serviceProviderConfig
|
||||
))
|
||||
@ -256,10 +337,11 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.And(x => x.GivenTheUpstreamHttpMethodIs("Post"))
|
||||
.When(x => x.WhenICallTheFinder())
|
||||
.Then(
|
||||
x => x.ThenTheFollowingIsReturned(new DownstreamRoute(new List<UrlPathPlaceholderNameAndValue>(),
|
||||
x => x.ThenTheFollowingIsReturned(new DownstreamRoute(new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Post" })
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1))
|
||||
.Build()
|
||||
)))
|
||||
.BDDfy();
|
||||
@ -274,14 +356,14 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.And(
|
||||
x =>
|
||||
x.GivenTheTemplateVariableAndNameFinderReturns(
|
||||
new OkResponse<List<UrlPathPlaceholderNameAndValue>>(new List<UrlPathPlaceholderNameAndValue>())))
|
||||
new OkResponse<List<PlaceholderNameAndValue>>(new List<PlaceholderNameAndValue>())))
|
||||
.And(x => x.GivenTheConfigurationIs(new List<ReRoute>
|
||||
{
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("someDownstreamPath")
|
||||
.WithUpstreamPathTemplate("someUpstreamPath")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get", "Patch", "Delete" })
|
||||
.WithUpstreamTemplatePattern("")
|
||||
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("", 1))
|
||||
.Build()
|
||||
}, string.Empty, serviceProviderConfig
|
||||
))
|
||||
@ -294,7 +376,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void GivenTheTemplateVariableAndNameFinderReturns(Response<List<UrlPathPlaceholderNameAndValue>> response)
|
||||
private void GivenTheTemplateVariableAndNameFinderReturns(Response<List<PlaceholderNameAndValue>> response)
|
||||
{
|
||||
_finder
|
||||
.Setup(x => x.Find(It.IsAny<string>(), It.IsAny<string>()))
|
||||
@ -356,14 +438,12 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
private void ThenTheFollowingIsReturned(DownstreamRoute expected)
|
||||
{
|
||||
_result.Data.ReRoute.DownstreamPathTemplate.Value.ShouldBe(expected.ReRoute.DownstreamPathTemplate.Value);
|
||||
_result.Data.ReRoute.UpstreamTemplatePattern.Priority.ShouldBe(expected.ReRoute.UpstreamTemplatePattern.Priority);
|
||||
|
||||
for (int i = 0; i < _result.Data.TemplatePlaceholderNameAndValues.Count; i++)
|
||||
{
|
||||
_result.Data.TemplatePlaceholderNameAndValues[i].TemplateVariableName.ShouldBe(
|
||||
expected.TemplatePlaceholderNameAndValues[i].TemplateVariableName);
|
||||
|
||||
_result.Data.TemplatePlaceholderNameAndValues[i].TemplateVariableValue.ShouldBe(
|
||||
expected.TemplatePlaceholderNameAndValues[i].TemplateVariableValue);
|
||||
_result.Data.TemplatePlaceholderNameAndValues[i].Name.ShouldBe(expected.TemplatePlaceholderNameAndValues[i].Name);
|
||||
_result.Data.TemplatePlaceholderNameAndValues[i].Value.ShouldBe(expected.TemplatePlaceholderNameAndValues[i].Value);
|
||||
}
|
||||
|
||||
_result.IsError.ShouldBeFalse();
|
||||
|
@ -18,6 +18,18 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher
|
||||
_urlMatcher = new RegExUrlMatcher();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_not_match_slash_becaue_we_need_to_match_something_after_it()
|
||||
{
|
||||
const string RegExForwardSlashAndOnePlaceHolder = "^/[0-9a-zA-Z].*";
|
||||
|
||||
this.Given(x => x.GivenIHaveAUpstreamPath("/"))
|
||||
.And(x => x.GivenIHaveAnUpstreamUrlTemplatePattern(RegExForwardSlashAndOnePlaceHolder))
|
||||
.When(x => x.WhenIMatchThePaths())
|
||||
.And(x => x.ThenTheResultIsFalse())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_not_match_forward_slash_only_regex()
|
||||
{
|
||||
|
@ -8,14 +8,14 @@ using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher
|
||||
{
|
||||
public class UrlPathToUrlTemplateMatcherTests
|
||||
public class UrlPathPlaceholderNameAndValueFinderTests
|
||||
{
|
||||
private readonly IUrlPathPlaceholderNameAndValueFinder _finder;
|
||||
private readonly IPlaceholderNameAndValueFinder _finder;
|
||||
private string _downstreamUrlPath;
|
||||
private string _downstreamPathTemplate;
|
||||
private Response<List<UrlPathPlaceholderNameAndValue>> _result;
|
||||
private Response<List<PlaceholderNameAndValue>> _result;
|
||||
|
||||
public UrlPathToUrlTemplateMatcherTests()
|
||||
public UrlPathPlaceholderNameAndValueFinderTests()
|
||||
{
|
||||
_finder = new UrlPathPlaceholderNameAndValueFinder();
|
||||
}
|
||||
@ -26,7 +26,82 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher
|
||||
this.Given(x => x.GivenIHaveAUpstreamPath(""))
|
||||
.And(x => x.GivenIHaveAnUpstreamUrlTemplate(""))
|
||||
.When(x => x.WhenIFindTheUrlVariableNamesAndValues())
|
||||
.And(x => x.ThenTheTemplatesVariablesAre(new List<UrlPathPlaceholderNameAndValue>()))
|
||||
.And(x => x.ThenTheTemplatesVariablesAre(new List<PlaceholderNameAndValue>()))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void can_match_down_stream_url_with_nothing_then_placeholder_no_value_is_blank()
|
||||
{
|
||||
var expectedTemplates = new List<PlaceholderNameAndValue>
|
||||
{
|
||||
new PlaceholderNameAndValue("{url}", "")
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenIHaveAUpstreamPath(""))
|
||||
.And(x => x.GivenIHaveAnUpstreamUrlTemplate("/{url}"))
|
||||
.When(x => x.WhenIFindTheUrlVariableNamesAndValues())
|
||||
.And(x => x.ThenTheTemplatesVariablesAre(expectedTemplates))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void can_match_down_stream_url_with_nothing_then_placeholder_value_is_test()
|
||||
{
|
||||
var expectedTemplates = new List<PlaceholderNameAndValue>
|
||||
{
|
||||
new PlaceholderNameAndValue("{url}", "test")
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenIHaveAUpstreamPath("/test"))
|
||||
.And(x => x.GivenIHaveAnUpstreamUrlTemplate("/{url}"))
|
||||
.When(x => x.WhenIFindTheUrlVariableNamesAndValues())
|
||||
.And(x => x.ThenTheTemplatesVariablesAre(expectedTemplates))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void can_match_down_stream_url_with_forward_slash_then_placeholder_no_value_is_blank()
|
||||
{
|
||||
var expectedTemplates = new List<PlaceholderNameAndValue>
|
||||
{
|
||||
new PlaceholderNameAndValue("{url}", "")
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenIHaveAUpstreamPath("/"))
|
||||
.And(x => x.GivenIHaveAnUpstreamUrlTemplate("/{url}"))
|
||||
.When(x => x.WhenIFindTheUrlVariableNamesAndValues())
|
||||
.And(x => x.ThenTheTemplatesVariablesAre(expectedTemplates))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void can_match_down_stream_url_with_forward_slash()
|
||||
{
|
||||
var expectedTemplates = new List<PlaceholderNameAndValue>
|
||||
{
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenIHaveAUpstreamPath("/"))
|
||||
.And(x => x.GivenIHaveAnUpstreamUrlTemplate("/"))
|
||||
.When(x => x.WhenIFindTheUrlVariableNamesAndValues())
|
||||
.And(x => x.ThenTheTemplatesVariablesAre(expectedTemplates))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void can_match_down_stream_url_with_forward_slash_then_placeholder_then_another_value()
|
||||
{
|
||||
var expectedTemplates = new List<PlaceholderNameAndValue>
|
||||
{
|
||||
new PlaceholderNameAndValue("{url}", "1")
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenIHaveAUpstreamPath("/1/products"))
|
||||
.And(x => x.GivenIHaveAnUpstreamUrlTemplate("/{url}/products"))
|
||||
.When(x => x.WhenIFindTheUrlVariableNamesAndValues())
|
||||
.And(x => x.ThenTheTemplatesVariablesAre(expectedTemplates))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -36,7 +111,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher
|
||||
this.Given(x => x.GivenIHaveAUpstreamPath("/products"))
|
||||
.And(x => x.GivenIHaveAnUpstreamUrlTemplate("/products/"))
|
||||
.When(x => x.WhenIFindTheUrlVariableNamesAndValues())
|
||||
.And(x => x.ThenTheTemplatesVariablesAre(new List<UrlPathPlaceholderNameAndValue>()))
|
||||
.And(x => x.ThenTheTemplatesVariablesAre(new List<PlaceholderNameAndValue>()))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -46,7 +121,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher
|
||||
this.Given(x => x.GivenIHaveAUpstreamPath("api"))
|
||||
.Given(x => x.GivenIHaveAnUpstreamUrlTemplate("api"))
|
||||
.When(x => x.WhenIFindTheUrlVariableNamesAndValues())
|
||||
.And(x => x.ThenTheTemplatesVariablesAre(new List<UrlPathPlaceholderNameAndValue>()))
|
||||
.And(x => x.ThenTheTemplatesVariablesAre(new List<PlaceholderNameAndValue>()))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -56,7 +131,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher
|
||||
this.Given(x => x.GivenIHaveAUpstreamPath("api/"))
|
||||
.Given(x => x.GivenIHaveAnUpstreamUrlTemplate("api/"))
|
||||
.When(x => x.WhenIFindTheUrlVariableNamesAndValues())
|
||||
.And(x => x.ThenTheTemplatesVariablesAre(new List<UrlPathPlaceholderNameAndValue>()))
|
||||
.And(x => x.ThenTheTemplatesVariablesAre(new List<PlaceholderNameAndValue>()))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -66,16 +141,16 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher
|
||||
this.Given(x => x.GivenIHaveAUpstreamPath("api/product/products/"))
|
||||
.Given(x => x.GivenIHaveAnUpstreamUrlTemplate("api/product/products/"))
|
||||
.When(x => x.WhenIFindTheUrlVariableNamesAndValues())
|
||||
.And(x => x.ThenTheTemplatesVariablesAre(new List<UrlPathPlaceholderNameAndValue>()))
|
||||
.And(x => x.ThenTheTemplatesVariablesAre(new List<PlaceholderNameAndValue>()))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void can_match_down_stream_url_with_downstream_template_with_one_place_holder()
|
||||
{
|
||||
var expectedTemplates = new List<UrlPathPlaceholderNameAndValue>
|
||||
var expectedTemplates = new List<PlaceholderNameAndValue>
|
||||
{
|
||||
new UrlPathPlaceholderNameAndValue("{productId}", "1")
|
||||
new PlaceholderNameAndValue("{productId}", "1")
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenIHaveAUpstreamPath("api/product/products/1"))
|
||||
@ -88,10 +163,10 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher
|
||||
[Fact]
|
||||
public void can_match_down_stream_url_with_downstream_template_with_two_place_holders()
|
||||
{
|
||||
var expectedTemplates = new List<UrlPathPlaceholderNameAndValue>
|
||||
var expectedTemplates = new List<PlaceholderNameAndValue>
|
||||
{
|
||||
new UrlPathPlaceholderNameAndValue("{productId}", "1"),
|
||||
new UrlPathPlaceholderNameAndValue("{categoryId}", "2")
|
||||
new PlaceholderNameAndValue("{productId}", "1"),
|
||||
new PlaceholderNameAndValue("{categoryId}", "2")
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenIHaveAUpstreamPath("api/product/products/1/2"))
|
||||
@ -104,10 +179,10 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher
|
||||
[Fact]
|
||||
public void can_match_down_stream_url_with_downstream_template_with_two_place_holders_seperated_by_something()
|
||||
{
|
||||
var expectedTemplates = new List<UrlPathPlaceholderNameAndValue>
|
||||
var expectedTemplates = new List<PlaceholderNameAndValue>
|
||||
{
|
||||
new UrlPathPlaceholderNameAndValue("{productId}", "1"),
|
||||
new UrlPathPlaceholderNameAndValue("{categoryId}", "2")
|
||||
new PlaceholderNameAndValue("{productId}", "1"),
|
||||
new PlaceholderNameAndValue("{categoryId}", "2")
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenIHaveAUpstreamPath("api/product/products/1/categories/2"))
|
||||
@ -120,11 +195,11 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher
|
||||
[Fact]
|
||||
public void can_match_down_stream_url_with_downstream_template_with_three_place_holders_seperated_by_something()
|
||||
{
|
||||
var expectedTemplates = new List<UrlPathPlaceholderNameAndValue>
|
||||
var expectedTemplates = new List<PlaceholderNameAndValue>
|
||||
{
|
||||
new UrlPathPlaceholderNameAndValue("{productId}", "1"),
|
||||
new UrlPathPlaceholderNameAndValue("{categoryId}", "2"),
|
||||
new UrlPathPlaceholderNameAndValue("{variantId}", "123")
|
||||
new PlaceholderNameAndValue("{productId}", "1"),
|
||||
new PlaceholderNameAndValue("{categoryId}", "2"),
|
||||
new PlaceholderNameAndValue("{variantId}", "123")
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenIHaveAUpstreamPath("api/product/products/1/categories/2/variant/123"))
|
||||
@ -137,10 +212,10 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher
|
||||
[Fact]
|
||||
public void can_match_down_stream_url_with_downstream_template_with_three_place_holders()
|
||||
{
|
||||
var expectedTemplates = new List<UrlPathPlaceholderNameAndValue>
|
||||
var expectedTemplates = new List<PlaceholderNameAndValue>
|
||||
{
|
||||
new UrlPathPlaceholderNameAndValue("{productId}", "1"),
|
||||
new UrlPathPlaceholderNameAndValue("{categoryId}", "2")
|
||||
new PlaceholderNameAndValue("{productId}", "1"),
|
||||
new PlaceholderNameAndValue("{categoryId}", "2")
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenIHaveAUpstreamPath("api/product/products/1/categories/2/variant/"))
|
||||
@ -153,9 +228,9 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher
|
||||
[Fact]
|
||||
public void can_match_down_stream_url_with_downstream_template_with_place_holder_to_final_url_path()
|
||||
{
|
||||
var expectedTemplates = new List<UrlPathPlaceholderNameAndValue>
|
||||
var expectedTemplates = new List<PlaceholderNameAndValue>
|
||||
{
|
||||
new UrlPathPlaceholderNameAndValue("{finalUrlPath}", "product/products/categories/"),
|
||||
new PlaceholderNameAndValue("{finalUrlPath}", "product/products/categories/"),
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenIHaveAUpstreamPath("api/product/products/categories/"))
|
||||
@ -165,13 +240,12 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void ThenTheTemplatesVariablesAre(List<UrlPathPlaceholderNameAndValue> expectedResults)
|
||||
private void ThenTheTemplatesVariablesAre(List<PlaceholderNameAndValue> expectedResults)
|
||||
{
|
||||
foreach (var expectedResult in expectedResults)
|
||||
{
|
||||
var result = _result.Data
|
||||
.First(t => t.TemplateVariableName == expectedResult.TemplateVariableName);
|
||||
result.TemplateVariableValue.ShouldBe(expectedResult.TemplateVariableValue);
|
||||
var result = _result.Data.First(t => t.Name == expectedResult.Name);
|
||||
result.Value.ShouldBe(expectedResult.Value);
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@
|
||||
{
|
||||
this.Given(x => x.GivenTheDownStreamRouteIs(
|
||||
new DownstreamRoute(
|
||||
new List<UrlPathPlaceholderNameAndValue>(),
|
||||
new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("any old string")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
@ -91,7 +91,7 @@
|
||||
{
|
||||
_downstreamPath = new OkResponse<DownstreamPath>(new DownstreamPath(path));
|
||||
_downstreamUrlTemplateVariableReplacer
|
||||
.Setup(x => x.Replace(It.IsAny<PathTemplate>(), It.IsAny<List<UrlPathPlaceholderNameAndValue>>()))
|
||||
.Setup(x => x.Replace(It.IsAny<PathTemplate>(), It.IsAny<List<PlaceholderNameAndValue>>()))
|
||||
.Returns(_downstreamPath);
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer
|
||||
{
|
||||
this.Given(x => x.GivenThereIsAUrlMatch(
|
||||
new DownstreamRoute(
|
||||
new List<UrlPathPlaceholderNameAndValue>(),
|
||||
new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.Build())))
|
||||
@ -41,7 +41,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer
|
||||
{
|
||||
this.Given(x => x.GivenThereIsAUrlMatch(
|
||||
new DownstreamRoute(
|
||||
new List<UrlPathPlaceholderNameAndValue>(),
|
||||
new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("/")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
@ -54,7 +54,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer
|
||||
[Fact]
|
||||
public void can_replace_url_no_slash()
|
||||
{
|
||||
this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(new List<UrlPathPlaceholderNameAndValue>(),
|
||||
this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("api")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
@ -67,7 +67,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer
|
||||
[Fact]
|
||||
public void can_replace_url_one_slash()
|
||||
{
|
||||
this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(new List<UrlPathPlaceholderNameAndValue>(),
|
||||
this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("api/")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
@ -80,7 +80,7 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer
|
||||
[Fact]
|
||||
public void can_replace_url_multiple_slash()
|
||||
{
|
||||
this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(new List<UrlPathPlaceholderNameAndValue>(),
|
||||
this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("api/product/products/")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
@ -93,9 +93,9 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer
|
||||
[Fact]
|
||||
public void can_replace_url_one_template_variable()
|
||||
{
|
||||
var templateVariables = new List<UrlPathPlaceholderNameAndValue>()
|
||||
var templateVariables = new List<PlaceholderNameAndValue>()
|
||||
{
|
||||
new UrlPathPlaceholderNameAndValue("{productId}", "1")
|
||||
new PlaceholderNameAndValue("{productId}", "1")
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(templateVariables,
|
||||
@ -111,9 +111,9 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer
|
||||
[Fact]
|
||||
public void can_replace_url_one_template_variable_with_path_after()
|
||||
{
|
||||
var templateVariables = new List<UrlPathPlaceholderNameAndValue>()
|
||||
var templateVariables = new List<PlaceholderNameAndValue>()
|
||||
{
|
||||
new UrlPathPlaceholderNameAndValue("{productId}", "1")
|
||||
new PlaceholderNameAndValue("{productId}", "1")
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(templateVariables,
|
||||
@ -129,10 +129,10 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer
|
||||
[Fact]
|
||||
public void can_replace_url_two_template_variable()
|
||||
{
|
||||
var templateVariables = new List<UrlPathPlaceholderNameAndValue>()
|
||||
var templateVariables = new List<PlaceholderNameAndValue>()
|
||||
{
|
||||
new UrlPathPlaceholderNameAndValue("{productId}", "1"),
|
||||
new UrlPathPlaceholderNameAndValue("{variantId}", "12")
|
||||
new PlaceholderNameAndValue("{productId}", "1"),
|
||||
new PlaceholderNameAndValue("{variantId}", "12")
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(templateVariables,
|
||||
@ -148,11 +148,11 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator.UrlTemplateReplacer
|
||||
[Fact]
|
||||
public void can_replace_url_three_template_variable()
|
||||
{
|
||||
var templateVariables = new List<UrlPathPlaceholderNameAndValue>()
|
||||
var templateVariables = new List<PlaceholderNameAndValue>()
|
||||
{
|
||||
new UrlPathPlaceholderNameAndValue("{productId}", "1"),
|
||||
new UrlPathPlaceholderNameAndValue("{variantId}", "12"),
|
||||
new UrlPathPlaceholderNameAndValue("{categoryId}", "34")
|
||||
new PlaceholderNameAndValue("{productId}", "1"),
|
||||
new PlaceholderNameAndValue("{variantId}", "12"),
|
||||
new PlaceholderNameAndValue("{categoryId}", "34")
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenThereIsAUrlMatch(new DownstreamRoute(templateVariables,
|
||||
|
@ -37,7 +37,7 @@
|
||||
[Fact]
|
||||
public void should_call_add_headers_to_request_correctly()
|
||||
{
|
||||
var downstreamRoute = new DownstreamRoute(new List<UrlPathPlaceholderNameAndValue>(),
|
||||
var downstreamRoute = new DownstreamRoute(new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("any old string")
|
||||
.WithClaimsToHeaders(new List<ClaimToThing>
|
||||
|
@ -47,7 +47,7 @@ namespace Ocelot.UnitTests.LoadBalancer
|
||||
[Fact]
|
||||
public void should_call_scoped_data_repository_correctly()
|
||||
{
|
||||
var downstreamRoute = new DownstreamRoute(new List<Ocelot.DownstreamRouteFinder.UrlMatcher.UrlPathPlaceholderNameAndValue>(),
|
||||
var downstreamRoute = new DownstreamRoute(new List<Ocelot.DownstreamRouteFinder.UrlMatcher.PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.Build());
|
||||
@ -68,7 +68,7 @@ namespace Ocelot.UnitTests.LoadBalancer
|
||||
[Fact]
|
||||
public void should_set_pipeline_error_if_cannot_get_load_balancer()
|
||||
{
|
||||
var downstreamRoute = new DownstreamRoute(new List<Ocelot.DownstreamRouteFinder.UrlMatcher.UrlPathPlaceholderNameAndValue>(),
|
||||
var downstreamRoute = new DownstreamRoute(new List<Ocelot.DownstreamRouteFinder.UrlMatcher.PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.Build());
|
||||
@ -88,7 +88,7 @@ namespace Ocelot.UnitTests.LoadBalancer
|
||||
[Fact]
|
||||
public void should_set_pipeline_error_if_cannot_get_least()
|
||||
{
|
||||
var downstreamRoute = new DownstreamRoute(new List<Ocelot.DownstreamRouteFinder.UrlMatcher.UrlPathPlaceholderNameAndValue>(),
|
||||
var downstreamRoute = new DownstreamRoute(new List<Ocelot.DownstreamRouteFinder.UrlMatcher.PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.Build());
|
||||
|
@ -37,7 +37,7 @@
|
||||
[Fact]
|
||||
public void should_call_add_queries_correctly()
|
||||
{
|
||||
var downstreamRoute = new DownstreamRoute(new List<UrlPathPlaceholderNameAndValue>(),
|
||||
var downstreamRoute = new DownstreamRoute(new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("any old string")
|
||||
.WithClaimsToQueries(new List<ClaimToThing>
|
||||
|
@ -31,7 +31,7 @@
|
||||
[Fact]
|
||||
public void should_call_middleware_and_ratelimiting()
|
||||
{
|
||||
var downstreamRoute = new DownstreamRoute(new List<Ocelot.DownstreamRouteFinder.UrlMatcher.UrlPathPlaceholderNameAndValue>(),
|
||||
var downstreamRoute = new DownstreamRoute(new List<Ocelot.DownstreamRouteFinder.UrlMatcher.PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder().WithEnableRateLimiting(true).WithRateLimitOptions(
|
||||
new Ocelot.Configuration.RateLimitOptions(true, "ClientId", new List<string>(), false, "", "", new Ocelot.Configuration.RateLimitRule("1s", 100, 3), 429))
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
@ -48,7 +48,7 @@
|
||||
[Fact]
|
||||
public void should_call_middleware_withWhitelistClient()
|
||||
{
|
||||
var downstreamRoute = new DownstreamRoute(new List<Ocelot.DownstreamRouteFinder.UrlMatcher.UrlPathPlaceholderNameAndValue>(),
|
||||
var downstreamRoute = new DownstreamRoute(new List<Ocelot.DownstreamRouteFinder.UrlMatcher.PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder().WithEnableRateLimiting(true).WithRateLimitOptions(
|
||||
new Ocelot.Configuration.RateLimitOptions(true, "ClientId", new List<string>() { "ocelotclient2" }, false, "", "", new RateLimitRule( "1s", 100,3),429))
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
|
@ -47,7 +47,7 @@
|
||||
public void should_call_scoped_data_repository_correctly()
|
||||
{
|
||||
|
||||
var downstreamRoute = new DownstreamRoute(new List<UrlPathPlaceholderNameAndValue>(),
|
||||
var downstreamRoute = new DownstreamRoute(new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithRequestIdKey("LSRequestId")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
|
@ -40,7 +40,7 @@
|
||||
[Fact]
|
||||
public void should_pass_down_request_id_from_upstream_request()
|
||||
{
|
||||
var downstreamRoute = new DownstreamRoute(new List<UrlPathPlaceholderNameAndValue>(),
|
||||
var downstreamRoute = new DownstreamRoute(new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("any old string")
|
||||
.WithRequestIdKey("LSRequestId")
|
||||
@ -59,7 +59,7 @@
|
||||
[Fact]
|
||||
public void should_add_request_id_when_not_on_upstream_request()
|
||||
{
|
||||
var downstreamRoute = new DownstreamRoute(new List<UrlPathPlaceholderNameAndValue>(),
|
||||
var downstreamRoute = new DownstreamRoute(new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("any old string")
|
||||
.WithRequestIdKey("LSRequestId")
|
||||
|
Reference in New Issue
Block a user