From 8ae8e2d834ac9d7733f6005ec67dc0e0315cb7f8 Mon Sep 17 00:00:00 2001 From: Tom Gardham-Pallister Date: Wed, 15 Feb 2017 07:48:49 +0000 Subject: [PATCH] added acceptance test for calling reroutes controller --- .../AdministrationTests.cs | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 test/Ocelot.AcceptanceTests/AdministrationTests.cs diff --git a/test/Ocelot.AcceptanceTests/AdministrationTests.cs b/test/Ocelot.AcceptanceTests/AdministrationTests.cs new file mode 100644 index 00000000..5a76e458 --- /dev/null +++ b/test/Ocelot.AcceptanceTests/AdministrationTests.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Net; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Ocelot.Configuration.File; +using TestStack.BDDfy; +using Xunit; + +namespace Ocelot.AcceptanceTests +{ + public class AdministrationTests : IDisposable + { + private IWebHost _builder; + private readonly Steps _steps; + + public AdministrationTests() + { + _steps = new Steps(); + } + + [Fact] + public void should_return_response_200_with_call_re_routes_controller() + { + var configuration = new FileConfiguration + { + GlobalConfiguration = new FileGlobalConfiguration + { + AdministrationPath = "/administration" + } + }; + + this.Given(x => _steps.GivenThereIsAConfiguration(configuration)) + .And(x => _steps.GivenOcelotIsRunning()) + .When(x => _steps.WhenIGetUrlOnTheApiGateway("/administration/reroutes")) + .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) + .BDDfy(); + } + + private void GivenThereIsAServiceRunningOn(string url, int statusCode, string responseBody) + { + _builder = new WebHostBuilder() + .UseUrls(url) + .UseKestrel() + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseIISIntegration() + .UseUrls(url) + .Configure(app => + { + app.Run(async context => + { + context.Response.StatusCode = statusCode; + await context.Response.WriteAsync(responseBody); + }); + }) + .Build(); + + _builder.Start(); + } + + public void Dispose() + { + _builder?.Dispose(); + _steps.Dispose(); + } + } +}