From fcd4ad17bb5b794b81db26312f322b7546be0f83 Mon Sep 17 00:00:00 2001 From: Paul Johnson Date: Sat, 12 Feb 2022 11:40:39 +0000 Subject: [PATCH] Make webhost setup less confusing. --- .../UmbracoTestServerTestBase.cs | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/tests/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs b/tests/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs index 6d7835b889..632bbe87d3 100644 --- a/tests/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs +++ b/tests/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs @@ -142,32 +142,26 @@ namespace Umbraco.Cms.Tests.Integration.TestServerTest Configuration = configBuilder.Build(); }) - /* It is important that ConfigureWebHost is called before ConfigureServices, this is consistent with the host setup - * found in Program.cs and avoids nasty surprises. - * - * e.g. the registration for RefreshingRazorViewEngine requires that IWebHostEnvironment is registered - * at the point in time that the service collection is snapshotted. - */ .ConfigureWebHost(builder => { - // need to configure the IWebHostEnvironment too - builder.ConfigureServices((c, s) => c.HostingEnvironment = TestHelper.GetWebHostEnvironment()); + builder.ConfigureServices((context, services) => + { + context.HostingEnvironment = TestHelper.GetWebHostEnvironment(); + + ConfigureServices(services); + ConfigureTestSpecificServices(services); + + if (!TestOptions.Boot) + { + // If boot is false, we don't want the CoreRuntime hosted service to start + // So we replace it with a Mock + services.AddUnique(Mock.Of()); + } + }); // call startup builder.Configure(Configure); }) - .ConfigureServices((_, services) => - { - ConfigureServices(services); - ConfigureTestSpecificServices(services); - - if (!TestOptions.Boot) - { - // If boot is false, we don't want the CoreRuntime hosted service to start - // So we replace it with a Mock - services.AddUnique(Mock.Of()); - } - }) .UseDefaultServiceProvider(cfg => { // These default to true *if* WebHostEnvironment.EnvironmentName == Development