From a1e562cab613ec56ed1cfa2e7c251ee2f5286018 Mon Sep 17 00:00:00 2001 From: Paul Johnson Date: Sat, 12 Feb 2022 11:57:28 +0000 Subject: [PATCH] Switch ConfigureServices back to protected. Downstream users may wish to subclass and add their application specific services. --- .../TestServerTest/UmbracoTestServerTestBase.cs | 13 ++++++++++--- .../Testing/UmbracoIntegrationTest.cs | 17 +++++++++++++++-- .../Testing/UmbracoIntegrationTestBase.cs | 4 ---- .../Umbraco.Core/Events/EventAggregatorTests.cs | 2 +- .../UmbracoExamine/ExamineBaseTest.cs | 2 +- .../Scoping/ScopeTests.cs | 2 +- .../Scoping/ScopedRepositoryTests.cs | 2 +- 7 files changed, 29 insertions(+), 13 deletions(-) diff --git a/tests/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs b/tests/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs index 632bbe87d3..8c7eabadde 100644 --- a/tests/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs +++ b/tests/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs @@ -149,7 +149,7 @@ namespace Umbraco.Cms.Tests.Integration.TestServerTest context.HostingEnvironment = TestHelper.GetWebHostEnvironment(); ConfigureServices(services); - ConfigureTestSpecificServices(services); + ConfigureTestServices(services); if (!TestOptions.Boot) { @@ -179,7 +179,7 @@ namespace Umbraco.Cms.Tests.Integration.TestServerTest protected virtual T GetRequiredService() => Factory.Services.GetRequiredService(); - private void ConfigureServices(IServiceCollection services) + protected void ConfigureServices(IServiceCollection services) { services.AddUnique(CreateLoggerFactory()); services.AddTransient(); @@ -228,7 +228,14 @@ namespace Umbraco.Cms.Tests.Integration.TestServerTest .Build(); } - private void Configure(IApplicationBuilder app) + /// + /// Hook for registering test doubles. + /// + protected virtual void ConfigureTestServices(IServiceCollection services) + { + } + + protected void Configure(IApplicationBuilder app) { UseTestDatabase(app); diff --git a/tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs b/tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs index 1e9ae97474..dd9fd3fe4e 100644 --- a/tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs +++ b/tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs @@ -80,7 +80,7 @@ namespace Umbraco.Cms.Tests.Integration.Testing .ConfigureServices((_, services) => { ConfigureServices(services); - ConfigureTestSpecificServices(services); + ConfigureTestServices(services); if (!TestOptions.Boot) { @@ -93,7 +93,7 @@ namespace Umbraco.Cms.Tests.Integration.Testing return hostBuilder; } - private void ConfigureServices(IServiceCollection services) + protected void ConfigureServices(IServiceCollection services) { services.AddUnique(CreateLoggerFactory()); services.AddSingleton(TestHelper.DbProviderFactoryCreator); @@ -143,10 +143,23 @@ namespace Umbraco.Cms.Tests.Integration.Testing builder.Build(); } + /// + /// Hook for altering UmbracoBuilder setup + /// + /// + /// Can also be used for registering test doubles. + /// protected virtual void CustomTestSetup(IUmbracoBuilder builder) { } + /// + /// Hook for registering test doubles. + /// + protected virtual void ConfigureTestServices(IServiceCollection services) + { + } + protected virtual T GetRequiredService() => Services.GetRequiredService(); /// diff --git a/tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTestBase.cs b/tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTestBase.cs index 439d169c61..b77ec1806f 100644 --- a/tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTestBase.cs +++ b/tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTestBase.cs @@ -107,10 +107,6 @@ public abstract class UmbracoIntegrationTestBase return NullLoggerFactory.Instance; } - protected virtual void ConfigureTestSpecificServices(IServiceCollection services) - { - } - protected void UseTestDatabase(IApplicationBuilder app) => UseTestDatabase(app.ApplicationServices); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Core/Events/EventAggregatorTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Core/Events/EventAggregatorTests.cs index 55429af147..4f7db59791 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Core/Events/EventAggregatorTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Core/Events/EventAggregatorTests.cs @@ -14,7 +14,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Events [TestFixture] public class EventAggregatorTests : UmbracoTestServerTestBase { - protected override void ConfigureTestSpecificServices(IServiceCollection services) + protected override void ConfigureTestServices(IServiceCollection services) { services.AddScoped(); services.AddTransient, EventAggregatorTestNotificationHandler>(); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Examine.Lucene/UmbracoExamine/ExamineBaseTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Examine.Lucene/UmbracoExamine/ExamineBaseTest.cs index 7769f99d83..95b708f167 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Examine.Lucene/UmbracoExamine/ExamineBaseTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Examine.Lucene/UmbracoExamine/ExamineBaseTest.cs @@ -29,7 +29,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Examine.Lucene.UmbracoExamine protected IRuntimeState RunningRuntimeState { get; } = Mock.Of(x => x.Level == RuntimeLevel.Run); - protected override void ConfigureTestSpecificServices(IServiceCollection services) + protected override void ConfigureTestServices(IServiceCollection services) => services.AddSingleton(); /// diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopeTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopeTests.cs index 1fcb14f0f5..c4f2db58fe 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopeTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopeTests.cs @@ -31,7 +31,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping public void SetUp() => Assert.IsNull(ScopeProvider.AmbientScope); // gone - protected override void ConfigureTestSpecificServices(IServiceCollection services) + protected override void ConfigureTestServices(IServiceCollection services) { // Need to have a mockable request cache for tests var appCaches = new AppCaches( diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs index f9a844817e..c228e07178 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs @@ -31,7 +31,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping private ILocalizationService LocalizationService => GetRequiredService(); - protected override void ConfigureTestSpecificServices(IServiceCollection services) + protected override void ConfigureTestServices(IServiceCollection services) { // this is what's created core web runtime var appCaches = new AppCaches(