Switch ConfigureServices back to protected.

Downstream users may wish to subclass and add their application specific
services.
This commit is contained in:
Paul Johnson
2022-02-12 11:57:28 +00:00
parent fcd4ad17bb
commit a1e562cab6
7 changed files with 29 additions and 13 deletions

View File

@@ -149,7 +149,7 @@ namespace Umbraco.Cms.Tests.Integration.TestServerTest
context.HostingEnvironment = TestHelper.GetWebHostEnvironment(); context.HostingEnvironment = TestHelper.GetWebHostEnvironment();
ConfigureServices(services); ConfigureServices(services);
ConfigureTestSpecificServices(services); ConfigureTestServices(services);
if (!TestOptions.Boot) if (!TestOptions.Boot)
{ {
@@ -179,7 +179,7 @@ namespace Umbraco.Cms.Tests.Integration.TestServerTest
protected virtual T GetRequiredService<T>() => Factory.Services.GetRequiredService<T>(); protected virtual T GetRequiredService<T>() => Factory.Services.GetRequiredService<T>();
private void ConfigureServices(IServiceCollection services) protected void ConfigureServices(IServiceCollection services)
{ {
services.AddUnique(CreateLoggerFactory()); services.AddUnique(CreateLoggerFactory());
services.AddTransient<TestUmbracoDatabaseFactoryProvider>(); services.AddTransient<TestUmbracoDatabaseFactoryProvider>();
@@ -228,7 +228,14 @@ namespace Umbraco.Cms.Tests.Integration.TestServerTest
.Build(); .Build();
} }
private void Configure(IApplicationBuilder app) /// <summary>
/// Hook for registering test doubles.
/// </summary>
protected virtual void ConfigureTestServices(IServiceCollection services)
{
}
protected void Configure(IApplicationBuilder app)
{ {
UseTestDatabase(app); UseTestDatabase(app);

View File

@@ -80,7 +80,7 @@ namespace Umbraco.Cms.Tests.Integration.Testing
.ConfigureServices((_, services) => .ConfigureServices((_, services) =>
{ {
ConfigureServices(services); ConfigureServices(services);
ConfigureTestSpecificServices(services); ConfigureTestServices(services);
if (!TestOptions.Boot) if (!TestOptions.Boot)
{ {
@@ -93,7 +93,7 @@ namespace Umbraco.Cms.Tests.Integration.Testing
return hostBuilder; return hostBuilder;
} }
private void ConfigureServices(IServiceCollection services) protected void ConfigureServices(IServiceCollection services)
{ {
services.AddUnique(CreateLoggerFactory()); services.AddUnique(CreateLoggerFactory());
services.AddSingleton(TestHelper.DbProviderFactoryCreator); services.AddSingleton(TestHelper.DbProviderFactoryCreator);
@@ -143,10 +143,23 @@ namespace Umbraco.Cms.Tests.Integration.Testing
builder.Build(); builder.Build();
} }
/// <summary>
/// Hook for altering UmbracoBuilder setup
/// </summary>
/// <remarks>
/// Can also be used for registering test doubles.
/// </remarks>
protected virtual void CustomTestSetup(IUmbracoBuilder builder) protected virtual void CustomTestSetup(IUmbracoBuilder builder)
{ {
} }
/// <summary>
/// Hook for registering test doubles.
/// </summary>
protected virtual void ConfigureTestServices(IServiceCollection services)
{
}
protected virtual T GetRequiredService<T>() => Services.GetRequiredService<T>(); protected virtual T GetRequiredService<T>() => Services.GetRequiredService<T>();
/// <summary> /// <summary>

View File

@@ -107,10 +107,6 @@ public abstract class UmbracoIntegrationTestBase
return NullLoggerFactory.Instance; return NullLoggerFactory.Instance;
} }
protected virtual void ConfigureTestSpecificServices(IServiceCollection services)
{
}
protected void UseTestDatabase(IApplicationBuilder app) protected void UseTestDatabase(IApplicationBuilder app)
=> UseTestDatabase(app.ApplicationServices); => UseTestDatabase(app.ApplicationServices);

View File

@@ -14,7 +14,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Events
[TestFixture] [TestFixture]
public class EventAggregatorTests : UmbracoTestServerTestBase public class EventAggregatorTests : UmbracoTestServerTestBase
{ {
protected override void ConfigureTestSpecificServices(IServiceCollection services) protected override void ConfigureTestServices(IServiceCollection services)
{ {
services.AddScoped<EventAggregatorTestScopedService>(); services.AddScoped<EventAggregatorTestScopedService>();
services.AddTransient<INotificationHandler<EventAggregatorTestNotification>, EventAggregatorTestNotificationHandler>(); services.AddTransient<INotificationHandler<EventAggregatorTestNotification>, EventAggregatorTestNotificationHandler>();

View File

@@ -29,7 +29,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Examine.Lucene.UmbracoExamine
protected IRuntimeState RunningRuntimeState { get; } = Mock.Of<IRuntimeState>(x => x.Level == RuntimeLevel.Run); protected IRuntimeState RunningRuntimeState { get; } = Mock.Of<IRuntimeState>(x => x.Level == RuntimeLevel.Run);
protected override void ConfigureTestSpecificServices(IServiceCollection services) protected override void ConfigureTestServices(IServiceCollection services)
=> services.AddSingleton<IndexInitializer>(); => services.AddSingleton<IndexInitializer>();
/// <summary> /// <summary>

View File

@@ -31,7 +31,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping
public void SetUp() => Assert.IsNull(ScopeProvider.AmbientScope); // gone 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 // Need to have a mockable request cache for tests
var appCaches = new AppCaches( var appCaches = new AppCaches(

View File

@@ -31,7 +31,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping
private ILocalizationService LocalizationService => GetRequiredService<ILocalizationService>(); private ILocalizationService LocalizationService => GetRequiredService<ILocalizationService>();
protected override void ConfigureTestSpecificServices(IServiceCollection services) protected override void ConfigureTestServices(IServiceCollection services)
{ {
// this is what's created core web runtime // this is what's created core web runtime
var appCaches = new AppCaches( var appCaches = new AppCaches(