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:
TomPallister
2016-10-04 21:30:16 +01:00
parent da1957311b
commit ab8407e7dc
17 changed files with 227 additions and 82 deletions

View File

@ -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)