diff --git a/src/ServiceComposer.AspNetCore.Testing.Tests/ApiApprovals.Approve_API.verified.txt b/src/ServiceComposer.AspNetCore.Testing.Tests/ApiApprovals.Approve_API.verified.txt index 78409d2..f7ad6cf 100644 --- a/src/ServiceComposer.AspNetCore.Testing.Tests/ApiApprovals.Approve_API.verified.txt +++ b/src/ServiceComposer.AspNetCore.Testing.Tests/ApiApprovals.Approve_API.verified.txt @@ -17,4 +17,12 @@ protected override void ConfigureWebHost(Microsoft.AspNetCore.Hosting.IWebHostBuilder builder) { } protected override Microsoft.Extensions.Hosting.IHostBuilder CreateHostBuilder() { } } + public class WebApplicationFactoryWithWebHost : Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory + where TStartup : class + { + public WebApplicationFactoryWithWebHost() { } + public System.Action BuilderCustomization { get; set; } + protected override void ConfigureWebHost(Microsoft.AspNetCore.Hosting.IWebHostBuilder builder) { } + protected override Microsoft.Extensions.Hosting.IHostBuilder CreateHostBuilder() { } + } } \ No newline at end of file diff --git a/src/ServiceComposer.AspNetCore.Testing/WebApplicationFactoryWithWebHost.cs b/src/ServiceComposer.AspNetCore.Testing/WebApplicationFactoryWithWebHost.cs new file mode 100644 index 0000000..da39ed8 --- /dev/null +++ b/src/ServiceComposer.AspNetCore.Testing/WebApplicationFactoryWithWebHost.cs @@ -0,0 +1,30 @@ +using System; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc.Testing; +using Microsoft.Extensions.Hosting; + +namespace ServiceComposer.AspNetCore.Testing +{ + public class WebApplicationFactoryWithWebHost : + WebApplicationFactory + where TStartup : class + { + public Action BuilderCustomization { get; set; } + + protected override IHostBuilder CreateHostBuilder() + { + return Host.CreateDefaultBuilder(Array.Empty()) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } + + protected override void ConfigureWebHost(IWebHostBuilder builder) + { + base.ConfigureWebHost(builder); + + BuilderCustomization?.Invoke(builder); + } + } +}