diff --git a/test/Ocelot.AcceptanceTests/Fake/FakeService.cs b/test/Ocelot.AcceptanceTests/Fake/FakeService.cs deleted file mode 100644 index 56f97ce5..00000000 --- a/test/Ocelot.AcceptanceTests/Fake/FakeService.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.IO; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting; - -namespace Ocelot.AcceptanceTests.Fake -{ - public class FakeService - { - private Task _handler; - private IWebHost _webHostBuilder; - - public void Start(string url) - { - _webHostBuilder = new WebHostBuilder() - .UseKestrel() - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseIISIntegration() - .UseUrls(url) - .UseStartup() - .Build(); - - _handler = Task.Run(() => _webHostBuilder.Run()); - } - - public void Stop() - { - if(_webHostBuilder != null) - { - _webHostBuilder.Dispose(); - _handler.Wait(); - } - } - } -} \ No newline at end of file diff --git a/test/Ocelot.AcceptanceTests/Fake/FakeStartup.cs b/test/Ocelot.AcceptanceTests/Fake/FakeStartup.cs deleted file mode 100644 index 7f8ceaea..00000000 --- a/test/Ocelot.AcceptanceTests/Fake/FakeStartup.cs +++ /dev/null @@ -1,47 +0,0 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -namespace Ocelot.AcceptanceTests.Fake -{ - public class FakeStartup - { - public FakeStartup(IHostingEnvironment env) - { - var builder = new ConfigurationBuilder() - .SetBasePath(env.ContentRootPath) - .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) - .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) - .AddEnvironmentVariables(); - Configuration = builder.Build(); - } - - public IConfigurationRoot Configuration { get; } - - // This method gets called by the runtime. Use this method to add services to the container. - public void ConfigureServices(IServiceCollection services) - { - // Add framework services. - - } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) - { - app.Run(async context => - { - 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 a4c3d5d5..f327d586 100644 --- a/test/Ocelot.AcceptanceTests/OcelotTests.cs +++ b/test/Ocelot.AcceptanceTests/OcelotTests.cs @@ -1,32 +1,33 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Net; -using System.Net.Http; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.TestHost; -using Ocelot.AcceptanceTests.Fake; -using Ocelot.Library.Infrastructure.Configuration.Yaml; -using Shouldly; -using TestStack.BDDfy; -using Xunit; -using YamlDotNet.Serialization; - namespace Ocelot.AcceptanceTests { + using System; + using System.Collections.Generic; + using System.IO; + using System.Net; + using System.Net.Http; + using Microsoft.AspNetCore.Hosting; + using Microsoft.AspNetCore.TestHost; + using Ocelot.Library.Infrastructure.Configuration.Yaml; + using Shouldly; + using TestStack.BDDfy; + using Xunit; + using YamlDotNet.Serialization; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Builder; + using Microsoft.AspNetCore.Http; + public class OcelotTests : IDisposable { - private readonly FakeService _fakeService; private TestServer _server; private HttpClient _client; private HttpResponseMessage _response; private readonly string _configurationPath; private StringContent _postContent; + private Task _fake; public OcelotTests() { _configurationPath = "./bin/Debug/netcoreapp1.0/configuration.yaml"; - _fakeService = new FakeService(); } [Fact] @@ -117,7 +118,29 @@ namespace Ocelot.AcceptanceTests private void GivenThereIsAServiceRunningOn(string url) { - _fakeService.Start(url); + var builder = new WebHostBuilder() + .Configure(app => + { + app.Run(async context => + { + if (context.Request.Method.ToLower() == "get") + { + await context.Response.WriteAsync("Hello from Laura"); + } + else + { + context.Response.StatusCode = 201; + } + }); + }) + .UseUrls(url) + .UseKestrel() + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseIISIntegration() + .UseUrls(url) + .Build(); + + _fake = Task.Run(() => builder.Run()); } private void WhenIGetUrlOnTheApiGateway(string url) @@ -141,8 +164,7 @@ namespace Ocelot.AcceptanceTests } public void Dispose() - { - _fakeService.Stop(); + { _client.Dispose(); _server.Dispose(); } diff --git a/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs b/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs index 3675459a..791a6aa2 100644 --- a/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs +++ b/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs @@ -18,7 +18,6 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder private readonly Mock _finder; private string _upstreamUrlPath; private Response _result; - private Response _response; private List _reRoutesConfig; private Response _match; private string _upstreamHttpMethod;