mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 15:58:16 +08:00
moved logic to request mapper and public setter gone
This commit is contained in:
@ -12,6 +12,7 @@
|
||||
using Ocelot.Responses;
|
||||
using Shouldly;
|
||||
using System.Net.Http;
|
||||
using Ocelot.Configuration;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
@ -69,20 +70,16 @@
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("POST", "POST")]
|
||||
[InlineData(null, "GET")]
|
||||
[InlineData("", "GET")]
|
||||
public void Should_map_downstream_reroute_method_to_downstream_request(string input, string expected)
|
||||
[Fact]
|
||||
public void Should_map_downstream_reroute_method_to_downstream_request()
|
||||
{
|
||||
this.Given(_ => GivenTheHttpContextContainsARequest())
|
||||
.And(_ => GivenTheDownstreamReRouteMethodIs(input))
|
||||
.And(_ => GivenTheMapperWillReturnAMappedRequest())
|
||||
.When(_ => WhenTheMiddlewareIsInvoked())
|
||||
.Then(_ => ThenTheContexRequestIsMappedToADownstreamRequest())
|
||||
.And(_ => ThenTheDownstreamRequestIsStored())
|
||||
.And(_ => ThenTheNextMiddlewareIsInvoked())
|
||||
.And(_ => ThenTheDownstreamRequestMethodIs(expected))
|
||||
.And(_ => ThenTheDownstreamRequestMethodIs("GET"))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -98,11 +95,6 @@
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void GivenTheDownstreamReRouteMethodIs(string input)
|
||||
{
|
||||
_downstreamContext.DownstreamReRoute = new DownstreamReRouteBuilder().WithDownStreamHttpMethod(input).Build();
|
||||
}
|
||||
|
||||
private void ThenTheDownstreamRequestMethodIs(string expected)
|
||||
{
|
||||
_downstreamContext.DownstreamRequest.Method.ShouldBe(expected);
|
||||
@ -120,7 +112,7 @@
|
||||
_mappedRequest = new OkResponse<HttpRequestMessage>(new HttpRequestMessage(HttpMethod.Get, "http://www.bbc.co.uk"));
|
||||
|
||||
_requestMapper
|
||||
.Setup(rm => rm.Map(It.IsAny<HttpRequest>()))
|
||||
.Setup(rm => rm.Map(It.IsAny<HttpRequest>(), It.IsAny<DownstreamReRoute>()))
|
||||
.ReturnsAsync(_mappedRequest);
|
||||
}
|
||||
|
||||
@ -129,7 +121,7 @@
|
||||
_mappedRequest = new ErrorResponse<HttpRequestMessage>(new UnmappableRequestError(new System.Exception("boooom!")));
|
||||
|
||||
_requestMapper
|
||||
.Setup(rm => rm.Map(It.IsAny<HttpRequest>()))
|
||||
.Setup(rm => rm.Map(It.IsAny<HttpRequest>(), It.IsAny<DownstreamReRoute>()))
|
||||
.ReturnsAsync(_mappedRequest);
|
||||
}
|
||||
|
||||
@ -140,7 +132,7 @@
|
||||
|
||||
private void ThenTheContexRequestIsMappedToADownstreamRequest()
|
||||
{
|
||||
_requestMapper.Verify(rm => rm.Map(_httpRequest.Object), Times.Once);
|
||||
_requestMapper.Verify(rm => rm.Map(_httpRequest.Object, _downstreamContext.DownstreamReRoute), Times.Once);
|
||||
}
|
||||
|
||||
private void ThenTheDownstreamRequestIsStored()
|
||||
|
@ -13,6 +13,8 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Builder;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
@ -27,6 +29,8 @@
|
||||
|
||||
private List<KeyValuePair<string, StringValues>> _inputHeaders = null;
|
||||
|
||||
private DownstreamReRoute _downstreamReRoute;
|
||||
|
||||
public RequestMapperTests()
|
||||
{
|
||||
_httpContext = new DefaultHttpContext();
|
||||
@ -82,6 +86,21 @@
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("", "GET")]
|
||||
[InlineData(null, "GET")]
|
||||
[InlineData("POST", "POST")]
|
||||
public void Should_use_downstream_reroute_method_if_set(string input, string expected)
|
||||
{
|
||||
this.Given(_ => GivenTheInputRequestHasMethod("GET"))
|
||||
.And(_ => GivenTheDownstreamReRouteMethodIs(input))
|
||||
.And(_ => GivenTheInputRequestHasAValidUri())
|
||||
.When(_ => WhenMapped())
|
||||
.Then(_ => ThenNoErrorIsReturned())
|
||||
.And(_ => ThenTheMappedRequestHasMethod(expected))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_map_all_headers()
|
||||
{
|
||||
@ -154,16 +173,6 @@
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void GivenTheInputRequestHasNoContentLength()
|
||||
{
|
||||
_inputRequest.ContentLength = null;
|
||||
}
|
||||
|
||||
private void GivenTheInputRequestHasNoContentType()
|
||||
{
|
||||
_inputRequest.ContentType = null;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_map_content_headers()
|
||||
{
|
||||
@ -212,6 +221,22 @@
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void GivenTheDownstreamReRouteMethodIs(string input)
|
||||
{
|
||||
_downstreamReRoute = new DownstreamReRouteBuilder().WithDownStreamHttpMethod(input).Build();
|
||||
}
|
||||
|
||||
private void GivenTheInputRequestHasNoContentLength()
|
||||
{
|
||||
_inputRequest.ContentLength = null;
|
||||
}
|
||||
|
||||
private void GivenTheInputRequestHasNoContentType()
|
||||
{
|
||||
_inputRequest.ContentType = null;
|
||||
}
|
||||
|
||||
|
||||
private void ThenTheContentHeadersAreNotAddedToNonContentHeaders()
|
||||
{
|
||||
_mappedRequest.Data.Headers.ShouldNotContain(x => x.Key == "Content-Disposition");
|
||||
@ -380,7 +405,7 @@
|
||||
|
||||
private async Task WhenMapped()
|
||||
{
|
||||
_mappedRequest = await _requestMapper.Map(_inputRequest);
|
||||
_mappedRequest = await _requestMapper.Map(_inputRequest, _downstreamReRoute);
|
||||
}
|
||||
|
||||
private void ThenNoErrorIsReturned()
|
||||
|
Reference in New Issue
Block a user