// Copyright (c) Umbraco. // See LICENSE for more details. using System; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.Extensions.Hosting; namespace Umbraco.Cms.Tests.Integration.TestServerTest { public class UmbracoWebApplicationFactory : WebApplicationFactory where TStartup : class { private readonly Func _createHostBuilder; private readonly Action _beforeStart; /// /// Constructor to create a new WebApplicationFactory /// /// Method to create the IHostBuilder /// Method to perform an action before IHost starts public UmbracoWebApplicationFactory(Func createHostBuilder) => _createHostBuilder = createHostBuilder; protected override IHostBuilder CreateHostBuilder() => _createHostBuilder(); protected override IHost CreateHost(IHostBuilder builder) { IHost host = builder.Build(); _beforeStart?.Invoke(host); host.Start(); return host; } } }