internal AgentTesterWaf(Action <IWebHostBuilder> configuration, string?environmentVariablePrefix = null, string?environment = TestSetUp.DefaultEnvironment, bool configureLocalRefData = true) : base(configureLocalRefData) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } var action = new Action <IWebHostBuilder>(whb => { configuration(whb); whb.UseSolutionRelativeContentRoot(""); whb.ConfigureAppConfiguration((context, config) => { config.AddConfiguration(AgentTester.BuildConfiguration <TStartup>(environmentVariablePrefix, environment)); }); whb.ConfigureServices(sc => { sc.AddLogging(configure => { configure.ClearProviders(); configure.AddCorrelationId(); }); }); whb.ConfigureTestServices(sc => { ReplaceEventPublisher(sc); }); }); WebApplicationFactory = new WebApplicationFactory <TStartup>().WithWebHostBuilder(action); }
/// <summary> /// Initializes a new instance of the <see cref="AgentTesterServer{TStartup}"/> class enabling configuration of the <see cref="TestServer"/>. /// </summary> /// <param name="environmentVariablePrefix">The prefix that the environment variables must start with (will automatically add a trailing underscore where not supplied).</param> /// <param name="environment">The environment to be used by the underlying web host.</param> /// <param name="config">The <see cref="IConfiguration"/>; defaults to <see cref="AgentTester.BuildConfiguration{TStartup}(string?, string?)"/> where <c>null</c>.</param> /// <param name="services">An optional action to perform further <see cref="IServiceCollection"/> configuration.</param> /// <param name="configureLocalRefData">Indicates whether the pre-set local <see cref="TestSetUp.SetDefaultLocalReferenceData{TRefService, TRefProvider, TRefAgentService, TRefAgent}">reference data</see> is configured.</param> internal AgentTesterServer(string?environmentVariablePrefix = null, string environment = TestSetUp.DefaultEnvironment, IConfiguration?config = null, Action <IServiceCollection>?services = null, bool configureLocalRefData = true) : base(configureLocalRefData) { var action = new Action <IServiceCollection>(sc => { services?.Invoke(sc); sc.AddLogging(configure => configure.AddCorrelationId()); ReplaceEventPublisher(sc); }); var whb = new WebHostBuilder() .UseEnvironment(environment) .UseStartup <TStartup>() .ConfigureTestServices(action) .UseConfiguration(config ?? AgentTester.BuildConfiguration <TStartup>(environmentVariablePrefix, environment)); TestServer = new TestServer(whb); }