Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,16 @@

namespace ServiceComposer.AspNetCore.Testing
{
public class SelfContainedWebApplicationFactoryWithHost<TEntryPoint> :
public class SelfContainedWebApplicationFactoryWithHost<TEntryPoint>(Action<IServiceCollection> configureServices, Action<IApplicationBuilder> configure, string[] args = null) :
WebApplicationFactory<TEntryPoint>
where TEntryPoint : class
{
private readonly Action<IServiceCollection> configureServices;
private readonly Action<IApplicationBuilder> configure;
private readonly string[] args;
private readonly string[] args = args ?? new string[0];

public Action<IHostBuilder> HostBuilderCustomization { get; set; }

public Action<IWebHostBuilder> WebHostBuilderCustomization { get; set; }

public SelfContainedWebApplicationFactoryWithHost(Action<IServiceCollection> configureServices, Action<IApplicationBuilder> configure, string[] args = null)
{
this.configureServices = configureServices;
this.configure = configure;
this.args = args ?? new string[0];
}

protected override IHostBuilder CreateHostBuilder()
{
var hostBuilder = Host.CreateDefaultBuilder(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace ServiceComposer.AspNetCore.Testing
{
/// <summary>
/// Factory for bootstrapping an application in memory for functional end to end tests.
/// Factory for bootstrapping an application in memory for functional end-to-end tests.
/// </summary>
/// <typeparam name="TEntryPoint">
/// A type in the entry point assembly of the application. Typically the Startup
Expand All @@ -20,6 +20,8 @@
{
readonly Action<IServiceCollection> _configureServices;
readonly Action<IApplicationBuilder> _configure;
readonly Action<WebHostBuilderContext, IServiceCollection> _configureServicesWithWebHostBuilderContext;
readonly Action<WebHostBuilderContext, IApplicationBuilder> _configureWithWebHostBuilderContext;

public Action<IWebHostBuilder> BuilderCustomization { get; set; }

Expand All @@ -28,21 +30,44 @@
_configureServices = configureServices;
_configure = configure;
}

public SelfContainedWebApplicationFactoryWithWebHost(Action<WebHostBuilderContext, IServiceCollection> configureServices, Action<WebHostBuilderContext, IApplicationBuilder> configure)
{
_configureServicesWithWebHostBuilderContext = configureServices;
_configureWithWebHostBuilderContext = configure;
}

protected override IWebHostBuilder CreateWebHostBuilder()
{
var host = new WebHostBuilder()
.UseKestrel()
.ConfigureServices(_configureServices)
.Configure(_configure);
var host = new WebHostBuilder().UseKestrel();

Check warning on line 42 in src/ServiceComposer.AspNetCore.Testing/SelfContainedWebApplicationFactoryWithWebHost.cs

View workflow job for this annotation

GitHub Actions / Build and test on Windows

'WebHostBuilder' is obsolete: 'WebHostBuilder is deprecated in favor of HostBuilder and WebApplicationBuilder. For more information, visit https://aka.ms/aspnet/deprecate/004.' (https://aka.ms/aspnet/deprecate/004)

Check warning on line 42 in src/ServiceComposer.AspNetCore.Testing/SelfContainedWebApplicationFactoryWithWebHost.cs

View workflow job for this annotation

GitHub Actions / Build and test on Windows

'WebHostBuilder' is obsolete: 'WebHostBuilder is deprecated in favor of HostBuilder and WebApplicationBuilder. For more information, visit https://aka.ms/aspnet/deprecate/004.' (https://aka.ms/aspnet/deprecate/004)

Check warning on line 42 in src/ServiceComposer.AspNetCore.Testing/SelfContainedWebApplicationFactoryWithWebHost.cs

View workflow job for this annotation

GitHub Actions / Build and test on Linux

'WebHostBuilder' is obsolete: 'WebHostBuilder is deprecated in favor of HostBuilder and WebApplicationBuilder. For more information, visit https://aka.ms/aspnet/deprecate/004.' (https://aka.ms/aspnet/deprecate/004)

Check warning on line 42 in src/ServiceComposer.AspNetCore.Testing/SelfContainedWebApplicationFactoryWithWebHost.cs

View workflow job for this annotation

GitHub Actions / Build and test on Linux

'WebHostBuilder' is obsolete: 'WebHostBuilder is deprecated in favor of HostBuilder and WebApplicationBuilder. For more information, visit https://aka.ms/aspnet/deprecate/004.' (https://aka.ms/aspnet/deprecate/004)

if (_configureServices != null)
{
host.ConfigureServices(_configureServices);
}

if (_configureServicesWithWebHostBuilderContext != null)
{
host.ConfigureServices(_configureServicesWithWebHostBuilderContext);
}

if (_configure != null)
{
host.Configure(_configure);
}

if (_configureWithWebHostBuilderContext != null)
{
host.Configure(_configureWithWebHostBuilderContext);
}

return host;
}

protected override void ConfigureWebHost(IWebHostBuilder builder)
{
base.ConfigureWebHost(builder);

BuilderCustomization?.Invoke(builder);
}
}
Expand Down
Loading