Files
Umbraco-CMS/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/HostedServices/ServerRegistration/InstructionProcessTaskTests.cs
Paul Johnson 00133e880d Move test projects from src/ to tests/ (#11357)
* Update gitignore

* Move csproj

* Update project references

* Update solutions

* Update build scripts

* Tests used to share editorconfig with projects in src

* Fix broken tests.

* Stop copying around .editorconfig

merged root one with linting

* csharp_style_expression_bodied -> suggestion

* Move StyleCop rulesets to matching directories and update shared build properties

* Remove legacy build files, update NuGet.cofig and solution files

* Restore myget source

* Clean up .gitignore

* Update .gitignore

* Move new test classes to tests after merge

* Gitignore + nuget config

* Move new test

Co-authored-by: Ronald Barendse <ronald@barend.se>
2021-10-18 08:14:04 +01:00

63 lines
2.3 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)
{
InstructionProcessTask sut = CreateInstructionProcessTask(runtimeLevel: runtimeLevel);
await sut.PerformExecuteAsync(null);
VerifyMessengerNotSynced();
}
[Test]
public async Task Executes_And_Touches_Server()
{
InstructionProcessTask 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);
}
}