mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 16:18:14 +08:00
* #298 initial hacking around better aggregation * #298 bit more hacking around * #298 abstraction over httpresponsemessage * #298 tidying up * #298 docs * #298 missed this
This commit is contained in:
@ -120,7 +120,7 @@ namespace Ocelot.UnitTests.Responder
|
||||
// If this test fails then it's because the number of error codes has changed.
|
||||
// You should make the appropriate changes to the test cases here to ensure
|
||||
// they cover all the error codes, and then modify this assertion.
|
||||
Enum.GetNames(typeof(OcelotErrorCode)).Length.ShouldBe(34, "Looks like the number of error codes has changed. Do you need to modify ErrorsToHttpStatusCodeMapper?");
|
||||
Enum.GetNames(typeof(OcelotErrorCode)).Length.ShouldBe(35, "Looks like the number of error codes has changed. Do you need to modify ErrorsToHttpStatusCodeMapper?");
|
||||
}
|
||||
|
||||
private void ShouldMapErrorToStatusCode(OcelotErrorCode errorCode, HttpStatusCode expectedHttpStatusCode)
|
||||
|
@ -1,10 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Headers;
|
||||
using Ocelot.Middleware;
|
||||
using Ocelot.Middleware.Multiplexer;
|
||||
using Ocelot.Responder;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
@ -26,9 +27,13 @@ namespace Ocelot.UnitTests.Responder
|
||||
public void should_remove_transfer_encoding_header()
|
||||
{
|
||||
var httpContext = new DefaultHttpContext();
|
||||
var httpResponseMessage = new HttpResponseMessage {Content = new StringContent("")};
|
||||
httpResponseMessage.Headers.Add("Transfer-Encoding", "woop");
|
||||
_responder.SetResponseOnHttpContext(httpContext, httpResponseMessage).GetAwaiter().GetResult();
|
||||
var response = new DownstreamResponse(new StringContent(""), HttpStatusCode.OK,
|
||||
new List<KeyValuePair<string, IEnumerable<string>>>
|
||||
{
|
||||
new KeyValuePair<string, IEnumerable<string>>("Transfer-Encoding", new List<string> {"woop"})
|
||||
});
|
||||
|
||||
_responder.SetResponseOnHttpContext(httpContext, response).GetAwaiter().GetResult();
|
||||
var header = httpContext.Response.Headers["Transfer-Encoding"];
|
||||
header.ShouldBeEmpty();
|
||||
}
|
||||
@ -37,8 +42,10 @@ namespace Ocelot.UnitTests.Responder
|
||||
public void should_have_content_length()
|
||||
{
|
||||
var httpContext = new DefaultHttpContext();
|
||||
var httpResponseMessage = new HttpResponseMessage { Content = new StringContent("test") };
|
||||
_responder.SetResponseOnHttpContext(httpContext, httpResponseMessage).GetAwaiter().GetResult();
|
||||
var response = new DownstreamResponse(new StringContent("test"), HttpStatusCode.OK,
|
||||
new List<KeyValuePair<string, IEnumerable<string>>>());
|
||||
|
||||
_responder.SetResponseOnHttpContext(httpContext, response).GetAwaiter().GetResult();
|
||||
var header = httpContext.Response.Headers["Content-Length"];
|
||||
header.First().ShouldBe("4");
|
||||
}
|
||||
@ -47,9 +54,13 @@ namespace Ocelot.UnitTests.Responder
|
||||
public void should_add_header()
|
||||
{
|
||||
var httpContext = new DefaultHttpContext();
|
||||
var httpResponseMessage = new HttpResponseMessage { Content = new StringContent("test") };
|
||||
httpResponseMessage.Headers.Add("test", "test");
|
||||
_responder.SetResponseOnHttpContext(httpContext, httpResponseMessage).GetAwaiter().GetResult();
|
||||
var response = new DownstreamResponse(new StringContent(""), HttpStatusCode.OK,
|
||||
new List<KeyValuePair<string, IEnumerable<string>>>
|
||||
{
|
||||
new KeyValuePair<string, IEnumerable<string>>("test", new List<string> {"test"})
|
||||
});
|
||||
|
||||
_responder.SetResponseOnHttpContext(httpContext, response).GetAwaiter().GetResult();
|
||||
var header = httpContext.Response.Headers["test"];
|
||||
header.First().ShouldBe("test");
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using Ocelot.Middleware;
|
||||
using Ocelot.Middleware.Multiplexer;
|
||||
|
||||
namespace Ocelot.UnitTests.Responder
|
||||
{
|
||||
@ -40,8 +41,7 @@ namespace Ocelot.UnitTests.Responder
|
||||
[Fact]
|
||||
public void should_not_return_any_errors()
|
||||
{
|
||||
this.Given(x => x.GivenTheHttpResponseMessageIs(new HttpResponseMessage()))
|
||||
.And(x => x.GivenThereAreNoPipelineErrors())
|
||||
this.Given(x => x.GivenTheHttpResponseMessageIs(new DownstreamResponse(new HttpResponseMessage())))
|
||||
.When(x => x.WhenICallTheMiddleware())
|
||||
.Then(x => x.ThenThereAreNoErrors())
|
||||
.BDDfy();
|
||||
@ -50,7 +50,7 @@ namespace Ocelot.UnitTests.Responder
|
||||
[Fact]
|
||||
public void should_return_any_errors()
|
||||
{
|
||||
this.Given(x => x.GivenTheHttpResponseMessageIs(new HttpResponseMessage()))
|
||||
this.Given(x => x.GivenTheHttpResponseMessageIs(new DownstreamResponse(new HttpResponseMessage())))
|
||||
.And(x => x.GivenThereArePipelineErrors(new UnableToFindDownstreamRouteError("/path", "GET")))
|
||||
.When(x => x.WhenICallTheMiddleware())
|
||||
.Then(x => x.ThenThereAreNoErrors())
|
||||
@ -62,16 +62,11 @@ namespace Ocelot.UnitTests.Responder
|
||||
_middleware.Invoke(_downstreamContext).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
private void GivenTheHttpResponseMessageIs(HttpResponseMessage response)
|
||||
private void GivenTheHttpResponseMessageIs(DownstreamResponse response)
|
||||
{
|
||||
_downstreamContext.DownstreamResponse = response;
|
||||
}
|
||||
|
||||
private void GivenThereAreNoPipelineErrors()
|
||||
{
|
||||
_downstreamContext.Errors = new List<Error>();
|
||||
}
|
||||
|
||||
private void ThenThereAreNoErrors()
|
||||
{
|
||||
//todo a better assert?
|
||||
@ -79,7 +74,7 @@ namespace Ocelot.UnitTests.Responder
|
||||
|
||||
private void GivenThereArePipelineErrors(Error error)
|
||||
{
|
||||
_downstreamContext.Errors = new List<Error>(){error};
|
||||
_downstreamContext.Errors.Add(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user