* Run code cleanup * Dotnet format benchmarks project * Fix up Test.Common * Run dotnet format + manual cleanup * Run code cleanup for unit tests * Run dotnet format * Fix up errors * Manual cleanup of Unit test project * Update tests/Umbraco.Tests.Benchmarks/HexStringBenchmarks.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Testing/TestDbMeta.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Benchmarks/TypeFinderBenchmarks.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Umbraco.Core/Events/EventAggregatorTests.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Fix according to review * Fix after merge * Fix errors Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk> Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> Co-authored-by: Zeegaan <nge@umbraco.dk>
66 lines
2.1 KiB
C#
66 lines
2.1 KiB
C#
// Copyright (c) Umbraco.
|
|
// See LICENSE for more details.
|
|
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using Umbraco.Cms.Core;
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
|
using Umbraco.Cms.Core.Services;
|
|
using Umbraco.Cms.Core.Sync;
|
|
using Umbraco.Cms.Infrastructure.HostedServices.ServerRegistration;
|
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.HostedServices.ServerRegistration;
|
|
|
|
[TestFixture]
|
|
public class InstructionProcessTaskTests
|
|
{
|
|
private Mock<IServerMessenger> _mockDatabaseServerMessenger;
|
|
|
|
[TestCase(RuntimeLevel.Boot)]
|
|
[TestCase(RuntimeLevel.Install)]
|
|
[TestCase(RuntimeLevel.Unknown)]
|
|
[TestCase(RuntimeLevel.Upgrade)]
|
|
[TestCase(RuntimeLevel.BootFailed)]
|
|
public async Task Does_Not_Execute_When_Runtime_State_Is_Not_Run(RuntimeLevel runtimeLevel)
|
|
{
|
|
var sut = CreateInstructionProcessTask(runtimeLevel);
|
|
await sut.PerformExecuteAsync(null);
|
|
VerifyMessengerNotSynced();
|
|
}
|
|
|
|
[Test]
|
|
public async Task Executes_And_Touches_Server()
|
|
{
|
|
var sut = CreateInstructionProcessTask();
|
|
await sut.PerformExecuteAsync(null);
|
|
VerifyMessengerSynced();
|
|
}
|
|
|
|
private InstructionProcessTask CreateInstructionProcessTask(RuntimeLevel runtimeLevel = RuntimeLevel.Run)
|
|
{
|
|
var mockRunTimeState = new Mock<IRuntimeState>();
|
|
mockRunTimeState.SetupGet(x => x.Level).Returns(runtimeLevel);
|
|
|
|
var mockLogger = new Mock<ILogger<InstructionProcessTask>>();
|
|
|
|
_mockDatabaseServerMessenger = new Mock<IServerMessenger>();
|
|
|
|
var settings = new GlobalSettings();
|
|
|
|
return new InstructionProcessTask(
|
|
mockRunTimeState.Object,
|
|
_mockDatabaseServerMessenger.Object,
|
|
mockLogger.Object,
|
|
Options.Create(settings));
|
|
}
|
|
|
|
private void VerifyMessengerNotSynced() => VerifyMessengerSyncedTimes(Times.Never());
|
|
|
|
private void VerifyMessengerSynced() => VerifyMessengerSyncedTimes(Times.Once());
|
|
|
|
private void VerifyMessengerSyncedTimes(Times times) => _mockDatabaseServerMessenger.Verify(x => x.Sync(), times);
|
|
}
|