77namespace ServiceComposer . AspNetCore . Testing
88{
99 /// <summary>
10- /// Factory for bootstrapping an application in memory for functional end to end tests.
10+ /// Factory for bootstrapping an application in memory for functional end-to- end tests.
1111 /// </summary>
1212 /// <typeparam name="TEntryPoint">
1313 /// A type in the entry point assembly of the application. Typically the Startup
@@ -20,6 +20,8 @@ public class SelfContainedWebApplicationFactoryWithWebHost<TEntryPoint> :
2020 {
2121 readonly Action < IServiceCollection > _configureServices ;
2222 readonly Action < IApplicationBuilder > _configure ;
23+ readonly Action < WebHostBuilderContext , IServiceCollection > _configureServicesWithWebHostBuilderContext ;
24+ readonly Action < WebHostBuilderContext , IApplicationBuilder > _configureWithWebHostBuilderContext ;
2325
2426 public Action < IWebHostBuilder > BuilderCustomization { get ; set ; }
2527
@@ -28,21 +30,44 @@ public SelfContainedWebApplicationFactoryWithWebHost(Action<IServiceCollection>
2830 _configureServices = configureServices ;
2931 _configure = configure ;
3032 }
33+
34+ public SelfContainedWebApplicationFactoryWithWebHost ( Action < WebHostBuilderContext , IServiceCollection > configureServices , Action < WebHostBuilderContext , IApplicationBuilder > configure )
35+ {
36+ _configureServicesWithWebHostBuilderContext = configureServices ;
37+ _configureWithWebHostBuilderContext = configure ;
38+ }
3139
3240 protected override IWebHostBuilder CreateWebHostBuilder ( )
3341 {
34- var host = new WebHostBuilder ( )
35- . UseKestrel ( )
36- . ConfigureServices ( _configureServices )
37- . Configure ( _configure ) ;
42+ var host = new WebHostBuilder ( ) . UseKestrel ( ) ;
43+
44+ if ( _configureServices != null )
45+ {
46+ host . ConfigureServices ( _configureServices ) ;
47+ }
48+
49+ if ( _configureServicesWithWebHostBuilderContext != null )
50+ {
51+ host . ConfigureServices ( _configureServicesWithWebHostBuilderContext ) ;
52+ }
53+
54+ if ( _configure != null )
55+ {
56+ host . Configure ( _configure ) ;
57+ }
58+
59+ if ( _configureWithWebHostBuilderContext != null )
60+ {
61+ host . Configure ( _configureWithWebHostBuilderContext ) ;
62+ }
3863
3964 return host ;
4065 }
4166
4267 protected override void ConfigureWebHost ( IWebHostBuilder builder )
4368 {
4469 base . ConfigureWebHost ( builder ) ;
45-
70+
4671 BuilderCustomization ? . Invoke ( builder ) ;
4772 }
4873 }
0 commit comments