2020-12-23 11:35:49 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
2020-12-17 12:18:28 +00:00
|
|
|
using System;
|
2020-06-17 16:39:28 +02:00
|
|
|
using Microsoft.AspNetCore.Mvc.Testing;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
namespace Umbraco.Cms.Tests.Integration.TestServerTest
|
2020-06-17 16:39:28 +02:00
|
|
|
{
|
2020-12-23 11:35:49 +01:00
|
|
|
public class UmbracoWebApplicationFactory<TStartup> : WebApplicationFactory<TStartup>
|
|
|
|
|
where TStartup : class
|
2020-06-17 16:39:28 +02:00
|
|
|
{
|
2020-09-02 18:10:29 +10:00
|
|
|
private readonly Func<IHostBuilder> _createHostBuilder;
|
2020-12-17 12:18:28 +00:00
|
|
|
private readonly Action<IHost> _beforeStart;
|
2020-06-17 16:39:28 +02:00
|
|
|
|
2020-09-02 18:10:29 +10:00
|
|
|
/// <summary>
|
|
|
|
|
/// Constructor to create a new WebApplicationFactory
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="createHostBuilder">Method to create the IHostBuilder</param>
|
2020-12-17 12:18:28 +00:00
|
|
|
/// <param name="beforeStart">Method to perform an action before IHost starts</param>
|
2022-02-11 20:37:56 +00:00
|
|
|
public UmbracoWebApplicationFactory(Func<IHostBuilder> createHostBuilder) => _createHostBuilder = createHostBuilder;
|
2020-06-17 16:39:28 +02:00
|
|
|
|
2020-09-02 18:10:29 +10:00
|
|
|
protected override IHostBuilder CreateHostBuilder() => _createHostBuilder();
|
2020-12-17 12:18:28 +00:00
|
|
|
|
|
|
|
|
protected override IHost CreateHost(IHostBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
IHost host = builder.Build();
|
|
|
|
|
|
|
|
|
|
_beforeStart?.Invoke(host);
|
|
|
|
|
|
|
|
|
|
host.Start();
|
|
|
|
|
|
|
|
|
|
return host;
|
|
|
|
|
}
|
2020-06-17 16:39:28 +02:00
|
|
|
}
|
|
|
|
|
}
|