public void GlobalSetupPlaintext() { var transportFactory = new InMemoryTransportFactory(connectionsPerEndPoint: 1); _host = new HostBuilder() .ConfigureWebHost(webHostBuilder => { webHostBuilder // Prevent VS from attaching to hosting startup which could impact results .UseSetting("preventHostingStartup", "true") .UseKestrel() // Bind to a single non-HTTPS endpoint .UseUrls("http://127.0.0.1:5000") .Configure(app => app.UseMiddleware <PlaintextMiddleware>()); }) .ConfigureServices(services => services.AddSingleton <IConnectionListenerFactory>(transportFactory)) .Build(); _host.Start(); // Ensure there is a single endpoint and single connection _connection = transportFactory.Connections.Values.Single().Single(); ValidateResponseAsync(RequestParsingData.PlaintextTechEmpowerRequest, _plaintextExpectedResponse).Wait(); ValidateResponseAsync(RequestParsingData.PlaintextTechEmpowerPipelinedRequests, _plaintextPipelinedExpectedResponse).Wait(); }
public TestServer(RequestDelegate app, TestServiceContext context, Action <KestrelServerOptions> configureKestrel, Action <IServiceCollection> configureServices) { _app = app; Context = context; _memoryPool = context.MemoryPoolFactory(); _transportFactory = new InMemoryTransportFactory(); HttpClientSlim = new InMemoryHttpClientSlim(this); var hostBuilder = new HostBuilder() .ConfigureWebHost(webHostBuilder => { webHostBuilder .UseSetting(WebHostDefaults.ShutdownTimeoutKey, TestConstants.DefaultTimeout.TotalSeconds.ToString(CultureInfo.InvariantCulture)) .Configure(app => { app.Run(_app); }); }) .ConfigureServices(services => { configureServices(services); services.AddSingleton <IStartup>(this); services.AddSingleton(context.LoggerFactory); services.AddSingleton <IServer>(sp => { context.ServerOptions.ApplicationServices = sp; configureKestrel(context.ServerOptions); return(new KestrelServerImpl( new IConnectionListenerFactory[] { _transportFactory }, sp.GetServices <IMultiplexedConnectionListenerFactory>(), context)); }); }); _host = hostBuilder.Build(); _host.Start(); }