/// <summary> /// Create an end-to-end API test. /// </summary> /// <param name="loggingConfiguration"> /// Custom logging configuration. /// </param> /// <param name="output"> /// The output helper that logger will write information to. /// </param> protected WebAppFactBase( TestLoggingConfiguration loggingConfiguration, ITestOutputHelper output) : this( WebAppFactHttpClientConfiguration.DefaultHttpClientOptions, loggingConfiguration, output) { }
/// <summary> /// Create an end-to-end API test using customized configuration. /// </summary> /// <param name="clientOptions">The HTTP client configuration.</param> /// <param name="loggingConfiguration">Logging configuration.</param> /// <param name="outputHelper"> /// The output helper that logger will write information to. /// </param> /// <param name="serviceConfigurator"> /// The service configuration that can be used to override default services configuration /// in a common manner. /// </param> protected WebAppFactBase( WebApplicationFactoryClientOptions clientOptions, TestLoggingConfiguration loggingConfiguration, ITestOutputHelper outputHelper, ITestServiceConfigurator serviceConfigurator = null) { this.clientOptions = clientOptions ?? throw new ArgumentNullException(nameof(clientOptions)); this.loggingConfiguration = loggingConfiguration ?? throw new ArgumentNullException(nameof(loggingConfiguration)); testServiceConfigurator = serviceConfigurator ?? new WebAppServiceConfigurator(); Output = outputHelper ?? new NullOutputHelper(); app = new WebAppForTest <T>(); }
static void ResetLogging( IServiceCollection services, TestLoggingConfiguration loggingConfiguration, ITestOutputHelper output) { services.RemoveAll <ILoggerFactory>(); services.RemoveAll(typeof(ILogger <>)); services.AddLogging( lb => { lb.ClearProviders(); if (loggingConfiguration.EnableLogging) { lb.AddProvider( new XUnitLoggerProvider(output, loggingConfiguration.SupportScope)) .SetMinimumLevel(loggingConfiguration.MinimumLevel); } }); }