From fa4766325968cc6cec93173a01073c4d6d1f7670 Mon Sep 17 00:00:00 2001 From: TomPallister Date: Sun, 19 Feb 2017 12:58:22 +0000 Subject: [PATCH] changed file config stuff to just use app base directory --- .../ServiceCollectionExtensions.cs | 2 ++ src/Ocelot/Services/GetFileConfiguration.cs | 2 +- .../AdministrationTests.cs | 35 +++++++------------ test/Ocelot.AcceptanceTests/Steps.cs | 4 ++- .../TestConfiguration.cs | 35 +++---------------- .../Services/GetFileConfigurationTests.cs | 7 ++-- 6 files changed, 26 insertions(+), 59 deletions(-) diff --git a/src/Ocelot/DependencyInjection/ServiceCollectionExtensions.cs b/src/Ocelot/DependencyInjection/ServiceCollectionExtensions.cs index e9be9841..74e6f97e 100644 --- a/src/Ocelot/DependencyInjection/ServiceCollectionExtensions.cs +++ b/src/Ocelot/DependencyInjection/ServiceCollectionExtensions.cs @@ -31,6 +31,7 @@ using Ocelot.Requester; using Ocelot.Requester.QoS; using Ocelot.Responder; using Ocelot.ServiceDiscovery; +using Ocelot.Services; namespace Ocelot.DependencyInjection { @@ -62,6 +63,7 @@ namespace Ocelot.DependencyInjection { services.AddMvcCore().AddJsonFormatters(); services.AddLogging(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/src/Ocelot/Services/GetFileConfiguration.cs b/src/Ocelot/Services/GetFileConfiguration.cs index b97cac92..536a0b46 100644 --- a/src/Ocelot/Services/GetFileConfiguration.cs +++ b/src/Ocelot/Services/GetFileConfiguration.cs @@ -10,7 +10,7 @@ namespace Ocelot.Services { public Response Invoke() { - var configFilePath = "configuration.json"; + var configFilePath = $"{AppContext.BaseDirectory}/configuration.json"; var json = File.ReadAllText(configFilePath); var fileConfiguration = JsonConvert.DeserializeObject(json); return new OkResponse(fileConfiguration); diff --git a/test/Ocelot.AcceptanceTests/AdministrationTests.cs b/test/Ocelot.AcceptanceTests/AdministrationTests.cs index 29ad10a8..525d9be5 100644 --- a/test/Ocelot.AcceptanceTests/AdministrationTests.cs +++ b/test/Ocelot.AcceptanceTests/AdministrationTests.cs @@ -36,7 +36,6 @@ namespace Ocelot.AcceptanceTests .And(x => _steps.GivenOcelotIsRunning()) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/administration/configuration")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) - .And(x => _steps.ThenTheResponseBodyShouldBe("hi from re routes controller")) .BDDfy(); } @@ -56,7 +55,18 @@ namespace Ocelot.AcceptanceTests DownstreamHost = "localhost", DownstreamPort = 80, DownstreamScheme = "https", - DownstreamPathTemplate = "/" + DownstreamPathTemplate = "/", + UpstreamHttpMethod = "get", + UpstreamPathTemplate = "/" + }, + new FileReRoute() + { + DownstreamHost = "localhost", + DownstreamPort = 80, + DownstreamScheme = "https", + DownstreamPathTemplate = "/", + UpstreamHttpMethod = "get", + UpstreamPathTemplate = "/test" } } }; @@ -69,27 +79,6 @@ namespace Ocelot.AcceptanceTests .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(); diff --git a/test/Ocelot.AcceptanceTests/Steps.cs b/test/Ocelot.AcceptanceTests/Steps.cs index 73585017..4a946947 100644 --- a/test/Ocelot.AcceptanceTests/Steps.cs +++ b/test/Ocelot.AcceptanceTests/Steps.cs @@ -31,7 +31,7 @@ namespace Ocelot.AcceptanceTests private BearerToken _token; public HttpClient OcelotClient => _ocelotClient; public string RequestIdKey = "OcRequestId"; - private Random _random; + private readonly Random _random; public Steps() { @@ -91,6 +91,8 @@ namespace Ocelot.AcceptanceTests response.ReRoutes[i].DownstreamPathTemplate.ShouldBe(expected.ReRoutes[i].DownstreamPathTemplate); response.ReRoutes[i].DownstreamPort.ShouldBe(expected.ReRoutes[i].DownstreamPort); response.ReRoutes[i].DownstreamScheme.ShouldBe(expected.ReRoutes[i].DownstreamScheme); + response.ReRoutes[i].UpstreamPathTemplate.ShouldBe(expected.ReRoutes[i].UpstreamPathTemplate); + response.ReRoutes[i].UpstreamHttpMethod.ShouldBe(expected.ReRoutes[i].UpstreamHttpMethod); } } diff --git a/test/Ocelot.AcceptanceTests/TestConfiguration.cs b/test/Ocelot.AcceptanceTests/TestConfiguration.cs index 6784391c..b4e6b778 100644 --- a/test/Ocelot.AcceptanceTests/TestConfiguration.cs +++ b/test/Ocelot.AcceptanceTests/TestConfiguration.cs @@ -1,36 +1,9 @@ -namespace Ocelot.AcceptanceTests -{ - using System.Runtime.InteropServices; +using System; +namespace Ocelot.AcceptanceTests +{ public static class TestConfiguration { - public static double Version => 1.1; - public static string ConfigurationPath => GetConfigurationPath(); - - public static string GetConfigurationPath() - { - var osArchitecture = RuntimeInformation.OSArchitecture.ToString(); - - if(RuntimeInformation.OSDescription.ToLower().Contains("darwin")) - { - return FormatConfigurationPath("osx.10.11", osArchitecture); - } - - if(RuntimeInformation.OSDescription.ToLower().Contains("microsoft windows 10")) - { - return FormatConfigurationPath("win10", osArchitecture); - } - - return FormatConfigurationPath("win7", osArchitecture); - } - - private static string FormatConfigurationPath(string oSDescription, string osArchitecture) - { - var runTime = $"{oSDescription}-{osArchitecture}".ToLower(); - - var configPath = $"./test/Ocelot.AcceptanceTests/bin/Debug/netcoreapp{Version}/{runTime}/configuration.json"; - - return configPath; - } + public static string ConfigurationPath => $"{AppContext.BaseDirectory}/configuration.json"; } } diff --git a/test/Ocelot.UnitTests/Services/GetFileConfigurationTests.cs b/test/Ocelot.UnitTests/Services/GetFileConfigurationTests.cs index 89ce22b1..fa86ced6 100644 --- a/test/Ocelot.UnitTests/Services/GetFileConfigurationTests.cs +++ b/test/Ocelot.UnitTests/Services/GetFileConfigurationTests.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using Moq; using Ocelot.Configuration; @@ -14,7 +15,7 @@ namespace Ocelot.UnitTests.Services { public class GetFileConfigurationTests { - private IGetFileConfiguration _getReRoutes; + private readonly IGetFileConfiguration _getReRoutes; private FileConfiguration _result; public GetFileConfigurationTests() @@ -59,7 +60,8 @@ namespace Ocelot.UnitTests.Services private void GivenTheConfigurationIs(FileConfiguration fileConfiguration) { - var configurationPath = "configuration.json"; + var configurationPath = $"{AppContext.BaseDirectory}/configuration.json"; + var jsonConfiguration = JsonConvert.SerializeObject(fileConfiguration); if (File.Exists(configurationPath)) @@ -89,7 +91,6 @@ namespace Ocelot.UnitTests.Services _result.ReRoutes[i].DownstreamPathTemplate.ShouldBe(expected.ReRoutes[i].DownstreamPathTemplate); _result.ReRoutes[i].DownstreamPort.ShouldBe(expected.ReRoutes[i].DownstreamPort); _result.ReRoutes[i].DownstreamScheme.ShouldBe(expected.ReRoutes[i].DownstreamScheme); - //todo -- add more! } } }