private void SetupClients() { const string Environment = "Testing"; using (var webHostScope = _container.BeginLifetimeScope(builder => builder.RegisterType <TestApiServerStartup>().AsSelf())) { var fullPath = Path.GetFullPath(Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "..", "..", "..", "..", "..", "src", "JAH.Api")); var factory = webHostScope.Resolve <Func <IHostingEnvironment, IConfiguration, TestApiServerStartup> >(); var builder = new WebHostBuilder().UseKestrel() .UseContentRoot(fullPath) .UseEnvironment(Environment) .UseStartup <TestApiServerStartup>() .ConfigureAppConfiguration((builderContext, config) => { var env = builderContext.HostingEnvironment; config.AddJsonFile("appsettings.json", false, true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", true, true); }) .ConfigureServices(services => services.TryAddTransient(provider => SetupStartup(provider, factory))); _testServer = new TestServer(builder); _apiClient = _testServer.CreateClient(); } using (var webHostScope = _container.BeginLifetimeScope(builder => builder.RegisterType <Startup>().AsSelf())) { var fullPath = Path.GetFullPath(Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "..", "..", "..", "..", "..", "src", "JAH.Web")); var factory = webHostScope.Resolve <Func <IHostingEnvironment, IConfiguration, Startup> >(); var builder = new WebHostBuilder().UseKestrel() .UseContentRoot(fullPath) .UseEnvironment(Environment) .UseStartup <Startup>() .ConfigureServices(services => services.AddTransient(provider => SetupStartup(provider, factory))) .ConfigureServices(services => services.TryAddSingleton(_apiClient)); var testServer = new TestServer(builder); WebClient = testServer.CreateClient(); } }