mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 06:22:50 +08:00
hacking around to get a POST acceptance test working, doesnt really mean anything tbh
This commit is contained in:
parent
72cec38c0e
commit
8423199754
@ -9,12 +9,12 @@ namespace Ocelot.Library.Infrastructure.Responder
|
|||||||
{
|
{
|
||||||
public async Task<HttpContext> CreateSuccessResponse(HttpContext context, HttpResponseMessage response)
|
public async Task<HttpContext> CreateSuccessResponse(HttpContext context, HttpResponseMessage response)
|
||||||
{
|
{
|
||||||
if (!response.IsSuccessStatusCode)
|
if (response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
context.Response.StatusCode = (int)response.StatusCode;
|
context.Response.StatusCode = (int)response.StatusCode;
|
||||||
|
await context.Response.WriteAsync(await response.Content.ReadAsStringAsync());
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
await context.Response.WriteAsync(await response.Content.ReadAsStringAsync());
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,8 +32,15 @@ namespace Ocelot.AcceptanceTests.Fake
|
|||||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
||||||
{
|
{
|
||||||
app.Run(async context =>
|
app.Run(async context =>
|
||||||
|
{
|
||||||
|
if (context.Request.Method.ToLower() == "get")
|
||||||
{
|
{
|
||||||
await context.Response.WriteAsync("Hello from Laura");
|
await context.Response.WriteAsync("Hello from Laura");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.Response.StatusCode = 201;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
{
|
{
|
||||||
this.Given(x => x.GivenThereIsAConfiguration(new Configuration()))
|
this.Given(x => x.GivenThereIsAConfiguration(new Configuration()))
|
||||||
.And(x => x.GivenTheApiGatewayIsRunning())
|
.And(x => x.GivenTheApiGatewayIsRunning())
|
||||||
.When(x => x.WhenIRequestTheUrlOnTheApiGateway("/"))
|
.When(x => x.WhenIGetUrlOnTheApiGateway("/"))
|
||||||
.Then(x => x.ThenTheStatusCodeShouldBe(HttpStatusCode.NotFound))
|
.Then(x => x.ThenTheStatusCodeShouldBe(HttpStatusCode.NotFound))
|
||||||
.BDDfy();
|
.BDDfy();
|
||||||
}
|
}
|
||||||
@ -54,12 +54,33 @@ namespace Ocelot.AcceptanceTests
|
|||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
.And(x => x.GivenTheApiGatewayIsRunning())
|
.And(x => x.GivenTheApiGatewayIsRunning())
|
||||||
.When(x => x.WhenIRequestTheUrlOnTheApiGateway("/"))
|
.When(x => x.WhenIGetUrlOnTheApiGateway("/"))
|
||||||
.Then(x => x.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
|
.Then(x => x.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
|
||||||
.And(x => x.ThenTheResponseBodyShouldBe("Hello from Laura"))
|
.And(x => x.ThenTheResponseBodyShouldBe("Hello from Laura"))
|
||||||
.BDDfy();
|
.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<ReRoute>
|
||||||
|
{
|
||||||
|
new ReRoute
|
||||||
|
{
|
||||||
|
DownstreamTemplate = "http://localhost:51879/",
|
||||||
|
UpstreamTemplate = "/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
.And(x => x.GivenTheApiGatewayIsRunning())
|
||||||
|
.When(x => x.WhenIPostUrlOnTheApiGateway("/"))
|
||||||
|
.Then(x => x.ThenTheStatusCodeShouldBe(HttpStatusCode.Created))
|
||||||
|
.BDDfy();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 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.
|
/// 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.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -91,11 +112,16 @@ namespace Ocelot.AcceptanceTests
|
|||||||
_fakeService.Start(url);
|
_fakeService.Start(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WhenIRequestTheUrlOnTheApiGateway(string url)
|
private void WhenIGetUrlOnTheApiGateway(string url)
|
||||||
{
|
{
|
||||||
_response = _client.GetAsync(url).Result;
|
_response = _client.GetAsync(url).Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void WhenIPostUrlOnTheApiGateway(string url)
|
||||||
|
{
|
||||||
|
_response = _client.PostAsync(url, new StringContent(string.Empty)).Result;
|
||||||
|
}
|
||||||
|
|
||||||
private void ThenTheStatusCodeShouldBe(HttpStatusCode expectedHttpStatusCode)
|
private void ThenTheStatusCodeShouldBe(HttpStatusCode expectedHttpStatusCode)
|
||||||
{
|
{
|
||||||
_response.StatusCode.ShouldBe(expectedHttpStatusCode);
|
_response.StatusCode.ShouldBe(expectedHttpStatusCode);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user