Created TestOptionsMonitor.cs and updated tests to use this new class

This commit is contained in:
Nikolaj Geisle
2021-09-23 11:30:25 +02:00
parent 3596d527b2
commit eb01984763
5 changed files with 23 additions and 5 deletions

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Configuration.UmbracoSettings;

View File

@@ -136,7 +136,7 @@ namespace Umbraco.Cms.Core.Events
INotificationService notificationService,
IUserService userService,
ILocalizedTextService textService,
IOptions<GlobalSettings> globalSettings,
IOptionsMonitor<GlobalSettings> globalSettings,
ILogger<Notifier> logger)
{
_backOfficeSecurityAccessor = backOfficeSecurityAccessor;
@@ -144,7 +144,7 @@ namespace Umbraco.Cms.Core.Events
_notificationService = notificationService;
_userService = userService;
_textService = textService;
_globalSettings = globalSettings.Value;
_globalSettings = globalSettings.CurrentValue;
_logger = logger;
}

View File

@@ -0,0 +1,16 @@
using System;
using Microsoft.Extensions.Options;
namespace Umbraco.Cms.Tests.Common
{
public class TestOptionsMonitor<T> : IOptionsMonitor<T> where T : class
{
public TestOptionsMonitor(T currentValue) => CurrentValue = currentValue;
public T Get(string name) => CurrentValue;
public IDisposable OnChange(Action<T, string> listener) => null;
public T CurrentValue { get; }
}
}

View File

@@ -18,6 +18,7 @@ using Umbraco.Cms.Core.Runtime;
using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Core.Sync;
using Umbraco.Cms.Infrastructure.HostedServices;
using Umbraco.Cms.Tests.Common;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.HostedServices
{
@@ -107,7 +108,8 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.HostedServices
return new KeepAlive(
mockHostingEnvironment.Object,
mockMainDom.Object,
Options.Create(settings),
new TestOptionsMonitor<KeepAliveSettings>(settings),
mockLogger.Object,
mockProfilingLogger.Object,
mockServerRegistrar.Object,

View File

@@ -16,6 +16,7 @@ using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;
using Umbraco.Cms.Infrastructure.HostedServices;
using Umbraco.Cms.Tests.Common;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.HostedServices
{
@@ -87,7 +88,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.HostedServices
mockMainDom.Object,
mockServerRegistrar.Object,
_mockAuditService.Object,
Options.Create(settings),
new TestOptionsMonitor<LoggingSettings>(settings),
mockScopeProvider.Object,
mockLogger.Object,
mockProfilingLogger.Object);