mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 04:38:14 +08:00
Now supports the same upstream url by difrenciating by http method. Also broke up the proxy middleware into three seperate pieces that do their thing and stick something into the OWIN context
This commit is contained in:
@ -50,7 +50,8 @@ namespace Ocelot.AcceptanceTests
|
||||
new ReRoute
|
||||
{
|
||||
DownstreamTemplate = "http://localhost:51879/",
|
||||
UpstreamTemplate = "/"
|
||||
UpstreamTemplate = "/",
|
||||
UpstreamHttpMethod = "Get"
|
||||
}
|
||||
}
|
||||
}))
|
||||
@ -72,7 +73,8 @@ namespace Ocelot.AcceptanceTests
|
||||
new ReRoute
|
||||
{
|
||||
DownstreamTemplate = "http://localhost:51879/",
|
||||
UpstreamTemplate = "/"
|
||||
UpstreamTemplate = "/",
|
||||
UpstreamHttpMethod = "Post"
|
||||
}
|
||||
}
|
||||
}))
|
||||
|
@ -1,3 +1,4 @@
|
||||
ReRoutes:
|
||||
- DownstreamTemplate: http://localhost:51879/
|
||||
UpstreamTemplate: /
|
||||
HttpMethod: Get
|
||||
|
@ -21,6 +21,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
private Response<DownstreamRoute> _response;
|
||||
private Library.Infrastructure.Configuration.Configuration _configuration;
|
||||
private UrlMatch _match;
|
||||
private string _upstreamHttpMethod;
|
||||
|
||||
public DownstreamRouteFinderTests()
|
||||
{
|
||||
@ -39,11 +40,13 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
new ReRoute()
|
||||
{
|
||||
UpstreamTemplate = "someUpstreamPath",
|
||||
DownstreamTemplate = "someDownstreamPath"
|
||||
DownstreamTemplate = "someDownstreamPath",
|
||||
UpstreamHttpMethod = "Get"
|
||||
}
|
||||
}
|
||||
}))
|
||||
.And(x => x.GivenTheUrlMatcherReturns(new UrlMatch(true, new List<TemplateVariableNameAndValue>(), "someDownstreamPath")))
|
||||
.And(x => x.GivenTheUpstreamHttpMethodIs("Get"))
|
||||
.When(x => x.WhenICallTheFinder())
|
||||
.Then(
|
||||
x => x.ThenTheFollowingIsReturned(new DownstreamRoute(new List<TemplateVariableNameAndValue>(), "someDownstreamPath")))
|
||||
@ -51,6 +54,36 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_correct_route_for_http_verb()
|
||||
{
|
||||
this.Given(x => x.GivenThereIsAnUpstreamUrlPath("someUpstreamPath"))
|
||||
.And(x => x.GivenTheConfigurationIs(new Library.Infrastructure.Configuration.Configuration
|
||||
{
|
||||
ReRoutes = new List<ReRoute>
|
||||
{
|
||||
new ReRoute()
|
||||
{
|
||||
UpstreamTemplate = "someUpstreamPath",
|
||||
DownstreamTemplate = "someDownstreamPath",
|
||||
UpstreamHttpMethod = "Get"
|
||||
},
|
||||
new ReRoute()
|
||||
{
|
||||
UpstreamTemplate = "someUpstreamPath",
|
||||
DownstreamTemplate = "someDownstreamPathForAPost",
|
||||
UpstreamHttpMethod = "Post"
|
||||
}
|
||||
}
|
||||
}))
|
||||
.And(x => x.GivenTheUrlMatcherReturns(new UrlMatch(true, new List<TemplateVariableNameAndValue>(), "someDownstreamPathForAPost")))
|
||||
.And(x => x.GivenTheUpstreamHttpMethodIs("Post"))
|
||||
.When(x => x.WhenICallTheFinder())
|
||||
.Then(
|
||||
x => x.ThenTheFollowingIsReturned(new DownstreamRoute(new List<TemplateVariableNameAndValue>(), "someDownstreamPathForAPost")))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_not_return_route()
|
||||
{
|
||||
@ -62,11 +95,13 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
new ReRoute()
|
||||
{
|
||||
UpstreamTemplate = "somePath",
|
||||
DownstreamTemplate = "somPath"
|
||||
DownstreamTemplate = "somPath",
|
||||
UpstreamHttpMethod = "Get"
|
||||
}
|
||||
}
|
||||
}))
|
||||
.And(x => x.GivenTheUrlMatcherReturns(new UrlMatch(false, new List<TemplateVariableNameAndValue>(), null)))
|
||||
.And(x => x.GivenTheUpstreamHttpMethodIs("Get"))
|
||||
.When(x => x.WhenICallTheFinder())
|
||||
.Then(
|
||||
x => x.ThenAnErrorResponseIsReturned())
|
||||
@ -74,6 +109,11 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void GivenTheUpstreamHttpMethodIs(string upstreamHttpMethod)
|
||||
{
|
||||
_upstreamHttpMethod = upstreamHttpMethod;
|
||||
}
|
||||
|
||||
private void ThenAnErrorResponseIsReturned()
|
||||
{
|
||||
_result.IsError.ShouldBeTrue();
|
||||
@ -108,7 +148,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
|
||||
private void WhenICallTheFinder()
|
||||
{
|
||||
_result = _downstreamRouteFinder.FindDownstreamRoute(_upstreamUrlPath);
|
||||
_result = _downstreamRouteFinder.FindDownstreamRoute(_upstreamUrlPath, _upstreamHttpMethod);
|
||||
}
|
||||
|
||||
private void ThenTheFollowingIsReturned(DownstreamRoute expected)
|
||||
|
@ -25,7 +25,8 @@
|
||||
"Shouldly": "2.8.0",
|
||||
"TestStack.BDDfy": "4.3.1",
|
||||
"YamlDotNet": "3.9.0",
|
||||
"Moq": "4.6.38-alpha"
|
||||
"Moq": "4.6.38-alpha",
|
||||
"Microsoft.AspNetCore.TestHost": "1.0.0"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
|
Reference in New Issue
Block a user