/// <summary> /// Adds the host factory for asp net core /// </summary> /// <param name="builder">The testing server builder</param> /// <param name="configureOptions">Configures options.</param> /// <param name="configure">Configuration delegate for the web host</param> /// <returns>The testing server builder</returns> public static TestingServerBuilder AddAspNetCoreHostFactory(this TestingServerBuilder builder, Action <AspNetCoreHostOptions> configureOptions, Action <IWebHostBuilder> configure) { var channel = new LogMessageChannel(); var c = new Action <IWebHostBuilder>(webHost => { configure(webHost); webHost .ConfigureServices((context, services) => { var descriptor = ServiceDescriptor.Singleton <IServiceProviderFactory <IServiceCollection> >(new TestingServiceProviderFactory(context.Configuration, channel)); services.Replace(descriptor); }) ; }); builder .ConfigureAspNetCoreHost(configureOptions) .AddTestingServices(services => { services.RemoveAll <LogMessageChannel>(); services.RemoveAll <LogMessageReader>(); services.AddSingleton(channel); services.AddSingleton <LogMessageReader>(); services.AddSingleton <IWebHostOptionsProvider>(new WebHostOptionsProvider { Configure = c }); services.TryAddSingleton <IWebHostFactory, DefaultWebHostFactory>(); }) ; return(builder.AddHostFactory <AspNetCoreInMemoryHostFactory>()); }
public static TestingServerBuilder ConfigureAspNetCoreHost(this TestingServerBuilder builder, Action <AspNetCoreHostOptions> configureOptions) { return(builder.AddTestingServices(services => { services.Configure(configureOptions); })); }
/// <summary> /// Adds the host factory for asp net core hosted on https /// </summary> /// <param name="builder">The testing server builder</param> /// <param name="hostname">The hostname for the in memory host</param> /// <param name="configure">Configuration delegate for the web host</param> /// <returns>The testing server builder</returns> public static TestingServerBuilder AddAspNetCoreHttpsHostFactory(this TestingServerBuilder builder, string hostname, Action <IWebHostBuilder> configure) { builder .AddTestingServices(services => { services .AddSingleton <ISelfSignedCertificateFactory, SelfSignedCertificateFactory>() .AddSingleton <IWebHostFactory, HttpsWebHostFactory>() .AddSingleton <IConfigureOptions <HttpClientFactoryOptions>, ConfigureNamedHttpClientFactoryOptions>() ; services.TryAddTransient <IHttpClientProvider, TestingHttpClientProvider>(); }) ; return(builder.AddAspNetCoreHostFactory(hostname, configure)); }
/// <summary> /// Adds the host factory for asp net core hosted on https /// </summary> /// <param name="builder">The testing server builder</param> /// <param name="configure">Configuration delegate for the web host</param> /// <returns>The testing server builder</returns> public static TestingServerBuilder AddAspNetCoreHttpsHostFactory(this TestingServerBuilder builder, Action <IWebHostBuilder> configure) => builder.AddAspNetCoreHttpsHostFactory(_defaultHostName, configure);
/// <summary> /// Adds the host factory for asp net core hosted on https /// </summary> /// <param name="builder">The testing server builder</param> /// <param name="hostname">The hostname for the in memory host</param> /// <returns>The testing server builder</returns> public static TestingServerBuilder AddAspNetCoreHttpsHostFactory(this TestingServerBuilder builder, string hostname) => builder.AddAspNetCoreHttpsHostFactory(hostname, _ => { });
/// <summary> /// Adds the host factory for asp net core hosted on https /// </summary> /// <param name="builder">The testing server builder</param> /// <returns>The testing server builder</returns> public static TestingServerBuilder AddAspNetCoreHttpsHostFactory(this TestingServerBuilder builder) => builder.AddAspNetCoreHttpsHostFactory(_defaultHostName);
/// <summary> /// Adds a host factory for asp.net owin /// </summary> /// <param name="builder">The testing server builder</param> /// <returns>The testing server builder</returns> public static TestingServerBuilder AddOwinHostFactory(this TestingServerBuilder builder) { return(builder.AddHostFactory(new OwinInMemoryHostFactory())); }
/// <summary> /// Adds the host factory for asp net core /// </summary> /// <param name="builder">The testing server builder</param> /// <param name="hostname">The hostname for the in memory host</param> /// <param name="configure">Configuration delegate for the web host</param> /// <returns>The testing server builder</returns> public static TestingServerBuilder AddAspNetCoreHostFactory(this TestingServerBuilder builder, string hostname, Action <IWebHostBuilder> configure) => builder.AddAspNetCoreHostFactory(options => options.HostName = hostname, configure);