mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-10-31 22:45:28 +08:00 
			
		
		
		
	hacking around to get a POST acceptance test working, doesnt really mean anything tbh
This commit is contained in:
		| @@ -9,12 +9,12 @@ namespace Ocelot.Library.Infrastructure.Responder | ||||
|     { | ||||
|         public async Task<HttpContext> 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; | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -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; | ||||
|                 } | ||||
|             }); | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -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<ReRoute> | ||||
|                     { | ||||
|                         new ReRoute | ||||
|                         { | ||||
|                             DownstreamTemplate = "http://localhost:51879/", | ||||
|                             UpstreamTemplate = "/" | ||||
|                         } | ||||
|                     } | ||||
|                 })) | ||||
|                 .And(x => x.GivenTheApiGatewayIsRunning()) | ||||
|                 .When(x => x.WhenIPostUrlOnTheApiGateway("/")) | ||||
|                 .Then(x => x.ThenTheStatusCodeShouldBe(HttpStatusCode.Created)) | ||||
|                 .BDDfy(); | ||||
|         } | ||||
|  | ||||
|         /// <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. | ||||
|         /// </summary> | ||||
| @@ -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); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 TomPallister
					TomPallister