diff --git a/src/Ocelot.Library/Infrastructure/Responder/HttpContextResponder.cs b/src/Ocelot.Library/Infrastructure/Responder/HttpContextResponder.cs index a90543fc..fed95e9e 100644 --- a/src/Ocelot.Library/Infrastructure/Responder/HttpContextResponder.cs +++ b/src/Ocelot.Library/Infrastructure/Responder/HttpContextResponder.cs @@ -9,12 +9,12 @@ namespace Ocelot.Library.Infrastructure.Responder { public async Task CreateSuccessResponse(HttpContext context, HttpResponseMessage response) { - if (!response.IsSuccessStatusCode) + if (response.IsSuccessStatusCode) { context.Response.StatusCode = (int)response.StatusCode; + await context.Response.WriteAsync(await response.Content.ReadAsStringAsync()); return context; } - await context.Response.WriteAsync(await response.Content.ReadAsStringAsync()); return context; } diff --git a/test/Ocelot.AcceptanceTests/Fake/FakeStartup.cs b/test/Ocelot.AcceptanceTests/Fake/FakeStartup.cs index 35d5e644..7f8ceaea 100644 --- a/test/Ocelot.AcceptanceTests/Fake/FakeStartup.cs +++ b/test/Ocelot.AcceptanceTests/Fake/FakeStartup.cs @@ -33,7 +33,14 @@ namespace Ocelot.AcceptanceTests.Fake { app.Run(async context => { - await context.Response.WriteAsync("Hello from Laura"); + if (context.Request.Method.ToLower() == "get") + { + await context.Response.WriteAsync("Hello from Laura"); + } + else + { + context.Response.StatusCode = 201; + } }); } } diff --git a/test/Ocelot.AcceptanceTests/OcelotTests.cs b/test/Ocelot.AcceptanceTests/OcelotTests.cs index 20164ea8..41911a4d 100644 --- a/test/Ocelot.AcceptanceTests/OcelotTests.cs +++ b/test/Ocelot.AcceptanceTests/OcelotTests.cs @@ -33,7 +33,7 @@ namespace Ocelot.AcceptanceTests { this.Given(x => x.GivenThereIsAConfiguration(new Configuration())) .And(x => x.GivenTheApiGatewayIsRunning()) - .When(x => x.WhenIRequestTheUrlOnTheApiGateway("/")) + .When(x => x.WhenIGetUrlOnTheApiGateway("/")) .Then(x => x.ThenTheStatusCodeShouldBe(HttpStatusCode.NotFound)) .BDDfy(); } @@ -54,12 +54,33 @@ namespace Ocelot.AcceptanceTests } })) .And(x => x.GivenTheApiGatewayIsRunning()) - .When(x => x.WhenIRequestTheUrlOnTheApiGateway("/")) + .When(x => x.WhenIGetUrlOnTheApiGateway("/")) .Then(x => x.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .And(x => x.ThenTheResponseBodyShouldBe("Hello from Laura")) .BDDfy(); } + [Fact] + public void should_return_response_201() + { + this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879")) + .And(x => x.GivenThereIsAConfiguration(new Configuration + { + ReRoutes = new List + { + new ReRoute + { + DownstreamTemplate = "http://localhost:51879/", + UpstreamTemplate = "/" + } + } + })) + .And(x => x.GivenTheApiGatewayIsRunning()) + .When(x => x.WhenIPostUrlOnTheApiGateway("/")) + .Then(x => x.ThenTheStatusCodeShouldBe(HttpStatusCode.Created)) + .BDDfy(); + } + /// /// This is annoying cos it should be in the constructor but we need to set up the yaml file before calling startup so its a step. /// @@ -91,11 +112,16 @@ namespace Ocelot.AcceptanceTests _fakeService.Start(url); } - private void WhenIRequestTheUrlOnTheApiGateway(string url) + private void WhenIGetUrlOnTheApiGateway(string url) { _response = _client.GetAsync(url).Result; } + private void WhenIPostUrlOnTheApiGateway(string url) + { + _response = _client.PostAsync(url, new StringContent(string.Empty)).Result; + } + private void ThenTheStatusCodeShouldBe(HttpStatusCode expectedHttpStatusCode) { _response.StatusCode.ShouldBe(expectedHttpStatusCode);