private static void Configure <TOptions>(IWebHostBuilder builder, OpenIdTests <TOptions> tests) where TOptions : OpenIdAuthenticationOptions { // Route application logs to xunit output for debugging builder.ConfigureLogging(logging => { logging.AddXUnit(tests) .SetMinimumLevel(LogLevel.Information); }); // Configure the test application builder.Configure(ConfigureApplication) .ConfigureServices(services => { // Allow HTTP requests to external services to be intercepted services.AddHttpClient(); services.AddSingleton <IHttpMessageHandlerBuilderFilter, HttpRequestInterceptionFilter>( (_) => new HttpRequestInterceptionFilter(tests.Interceptor)); // Set up the test endpoint services.AddRouting(); // Configure authentication var authentication = services .AddAuthentication("External") .AddCookie("External", o => o.ForwardChallenge = tests.DefaultScheme); tests.RegisterAuthentication(authentication); services.AddAuthorization(); }); }
/// <summary> /// Creates a test application for the specified type of authentication. /// </summary> /// <typeparam name="TOptions">The type of the configuration options for the authentication provider.</typeparam> /// <param name="tests">The test class to configure the application for.</param> /// <param name="configureServices">An optional delegate to configure additional application services.</param> /// <returns> /// The test application to use for the authentication provider. /// </returns> public static WebApplicationFactory <Program> CreateApplication <TOptions>(OpenIdTests <TOptions> tests, Action <IServiceCollection> configureServices = null) where TOptions : OpenIdAuthenticationOptions { return(new TestApplicationFactory() .WithWebHostBuilder(builder => { Configure(builder, tests); if (configureServices != null) { builder.ConfigureServices(configureServices); } })); }