Skip to content

Commit 1e226d5

Browse files
Bring back WebApplicationFactoryWithWebHost (#216)
1 parent 4cd904b commit 1e226d5

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/ServiceComposer.AspNetCore.Testing.Tests/ApiApprovals.Approve_API.verified.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,12 @@
1717
protected override void ConfigureWebHost(Microsoft.AspNetCore.Hosting.IWebHostBuilder builder) { }
1818
protected override Microsoft.Extensions.Hosting.IHostBuilder CreateHostBuilder() { }
1919
}
20+
public class WebApplicationFactoryWithWebHost<TStartup> : Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TStartup>
21+
where TStartup : class
22+
{
23+
public WebApplicationFactoryWithWebHost() { }
24+
public System.Action<Microsoft.AspNetCore.Hosting.IWebHostBuilder> BuilderCustomization { get; set; }
25+
protected override void ConfigureWebHost(Microsoft.AspNetCore.Hosting.IWebHostBuilder builder) { }
26+
protected override Microsoft.Extensions.Hosting.IHostBuilder CreateHostBuilder() { }
27+
}
2028
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.AspNetCore.Mvc.Testing;
4+
using Microsoft.Extensions.Hosting;
5+
6+
namespace ServiceComposer.AspNetCore.Testing
7+
{
8+
public class WebApplicationFactoryWithWebHost<TStartup> :
9+
WebApplicationFactory<TStartup>
10+
where TStartup : class
11+
{
12+
public Action<IWebHostBuilder> BuilderCustomization { get; set; }
13+
14+
protected override IHostBuilder CreateHostBuilder()
15+
{
16+
return Host.CreateDefaultBuilder(Array.Empty<string>())
17+
.ConfigureWebHostDefaults(webBuilder =>
18+
{
19+
webBuilder.UseStartup<TStartup>();
20+
});
21+
}
22+
23+
protected override void ConfigureWebHost(IWebHostBuilder builder)
24+
{
25+
base.ConfigureWebHost(builder);
26+
27+
BuilderCustomization?.Invoke(builder);
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)