From 687de61793e2a4dcfe5791f6b84b5f8d76e10653 Mon Sep 17 00:00:00 2001 From: Paul Johnson Date: Tue, 19 Oct 2021 10:09:48 +0100 Subject: [PATCH] Drop ref to Web.UI from integration tests (#11413) * Remove reference to Web.UI, Fix test server content root * Cleanup test databases in parallel --- .../TestServerTest/UmbracoTestServerTestBase.cs | 13 +++++++++---- .../Testing/LocalDbTestDatabase.cs | 9 +++++---- .../Testing/SqlDeveloperTestDatabase.cs | 6 ++---- .../Umbraco.Tests.Integration.csproj | 3 +-- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/tests/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs b/tests/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs index 86f6a03216..2d140e4336 100644 --- a/tests/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs +++ b/tests/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs @@ -4,6 +4,7 @@ using System; using System.Linq.Expressions; using System.Net.Http; +using System.Reflection; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; @@ -24,7 +25,6 @@ using Umbraco.Cms.Tests.Integration.DependencyInjection; using Umbraco.Cms.Tests.Integration.Testing; using Umbraco.Cms.Web.BackOffice.Controllers; using Umbraco.Cms.Web.Common.Controllers; -using Umbraco.Cms.Web.UI; using Umbraco.Cms.Web.Website.Controllers; using Umbraco.Extensions; @@ -52,17 +52,22 @@ namespace Umbraco.Cms.Tests.Integration.TestServerTest * * See https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests */ - var factory = new UmbracoWebApplicationFactory(CreateHostBuilder, BeforeHostStart); + var factory = new UmbracoWebApplicationFactory(CreateHostBuilder, BeforeHostStart); // additional host configuration for web server integration tests Factory = factory.WithWebHostBuilder(builder => + { + // Otherwise inferred as $(SolutionDir)/Umbraco.Tests.Integration (note lack of src/tests) + builder.UseContentRoot(Assembly.GetExecutingAssembly().GetRootDirectorySafe()); // Executes after the standard ConfigureServices method builder.ConfigureTestServices(services => // Add a test auth scheme with a test auth handler to authn and assign the user services.AddAuthentication(TestAuthHandler.TestAuthenticationScheme) - .AddScheme(TestAuthHandler.TestAuthenticationScheme, options => { }))); + .AddScheme(TestAuthHandler.TestAuthenticationScheme, options => { })); + }); + Client = Factory.CreateClient(new WebApplicationFactoryClientOptions { @@ -141,7 +146,7 @@ namespace Umbraco.Cms.Tests.Integration.TestServerTest protected LinkGenerator LinkGenerator { get; private set; } - protected WebApplicationFactory Factory { get; private set; } + protected WebApplicationFactory Factory { get; private set; } public override void ConfigureServices(IServiceCollection services) { diff --git a/tests/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs b/tests/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs index 3eef3c201f..59ddfe55e8 100644 --- a/tests/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs +++ b/tests/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs @@ -6,6 +6,7 @@ using System.Collections.Concurrent; using System.IO; using System.Linq; using System.Threading; +using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Umbraco.Cms.Infrastructure.Persistence; @@ -118,13 +119,13 @@ namespace Umbraco.Cms.Tests.Integration.Testing string filename = Path.Combine(s_filesPath, DatabaseName).ToUpper(); - foreach (string database in s_localDbInstance.GetDatabases()) + Parallel.ForEach(s_localDbInstance.GetDatabases(), instance => { - if (database.StartsWith(filename)) + if (instance.StartsWith(filename)) { - s_localDbInstance.DropDatabase(database); + s_localDbInstance.DropDatabase(instance); } - } + }); _localDb.StopInstance(InstanceName); diff --git a/tests/Umbraco.Tests.Integration/Testing/SqlDeveloperTestDatabase.cs b/tests/Umbraco.Tests.Integration/Testing/SqlDeveloperTestDatabase.cs index 6192bacb72..b35b6ac0d5 100644 --- a/tests/Umbraco.Tests.Integration/Testing/SqlDeveloperTestDatabase.cs +++ b/tests/Umbraco.Tests.Integration/Testing/SqlDeveloperTestDatabase.cs @@ -6,6 +6,7 @@ using System.Collections.Concurrent; using System.Data.SqlClient; using System.Linq; using System.Threading; +using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Umbraco.Cms.Infrastructure.Persistence; @@ -118,10 +119,7 @@ namespace Umbraco.Cms.Tests.Integration.Testing { } - foreach (TestDbMeta testDatabase in _testDatabases) - { - Drop(testDatabase); - } + Parallel.ForEach(_testDatabases, Drop); } } } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj b/tests/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj index 36d012945f..8ef12b2925 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj +++ b/tests/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj @@ -1,4 +1,4 @@ - + net5.0 @@ -99,7 +99,6 @@ -