* Start work * Introduce dto * Start making repository * Add migrations * Implement fetchable first job * Fix up to also finish tasks * Refactor jobs to distributed background jobs * Filter jobs correctly on LastRun * Hardcode delay * Add settings to configure delay and period * Fix formatting * Add default data * Add update on startup, which will update periods on startup * Refactor service to return job directly * Update src/Umbraco.Infrastructure/Services/Implement/DistributedJobService.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/Umbraco.Infrastructure/BackgroundJobs/DistributedBackgroundJobHostedService.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/Umbraco.Infrastructure/BackgroundJobs/DistributedBackgroundJobHostedService.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Remove unused * Move jobs and make internal * make OpenIddictCleanupJob.cs public, as it is used elsewhere * Minor docstring changes * Update src/Umbraco.Core/Persistence/Constants-Locks.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * ´Throw correct exceptions * Update xml doc * Remove business logic from repository * Remove more business logic from repository into service * Remove adding jobs from migration * fix creation * Rename to ExecuteAsync --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: mole <nikolajlauridsen@protonmail.ch>
68 lines
2.6 KiB
C#
68 lines
2.6 KiB
C#
using System.Threading.Tasks;
|
|
using AutoFixture.NUnit3;
|
|
using Microsoft.Extensions.Options;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using Umbraco.Cms.Core;
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
|
using Umbraco.Cms.Core.Runtime;
|
|
using Umbraco.Cms.Core.Services;
|
|
using Umbraco.Cms.Core.Sync;
|
|
using Umbraco.Cms.Infrastructure.BackgroundJobs.Jobs;
|
|
using Umbraco.Cms.Infrastructure.BackgroundJobs.Jobs.DistributedJobs;
|
|
using Umbraco.Cms.Infrastructure.HostedServices;
|
|
using Umbraco.Cms.Tests.UnitTests.AutoFixture;
|
|
|
|
namespace Umbraco.Tests.Scheduling;
|
|
|
|
[TestFixture]
|
|
internal class ContentVersionCleanupTest
|
|
{
|
|
[Test]
|
|
[AutoMoqData]
|
|
public async Task ContentVersionCleanup_WhenNotEnabled_DoesNotCleanupWillRepeat(
|
|
[Frozen] Mock<IOptionsMonitor<ContentSettings>> settings,
|
|
[Frozen] Mock<IMainDom> mainDom,
|
|
[Frozen] Mock<IServerRoleAccessor> serverRoleAccessor,
|
|
[Frozen] Mock<IRuntimeState> runtimeState,
|
|
[Frozen] Mock<IContentVersionService> cleanupService,
|
|
ContentVersionCleanupJob sut)
|
|
{
|
|
settings.Setup(x => x.CurrentValue).Returns(new ContentSettings
|
|
{
|
|
ContentVersionCleanupPolicy = new ContentVersionCleanupPolicySettings { EnableCleanup = false },
|
|
});
|
|
runtimeState.Setup(x => x.Level).Returns(RuntimeLevel.Run);
|
|
mainDom.Setup(x => x.IsMainDom).Returns(true);
|
|
serverRoleAccessor.Setup(x => x.CurrentServerRole).Returns(ServerRole.SchedulingPublisher);
|
|
|
|
await sut.ExecuteAsync();
|
|
|
|
cleanupService.Verify(x => x.PerformContentVersionCleanup(It.IsAny<DateTime>()), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
[AutoMoqData]
|
|
public async Task ContentVersionCleanup_Enabled_DelegatesToCleanupService(
|
|
[Frozen] Mock<IOptionsMonitor<ContentSettings>> settings,
|
|
[Frozen] Mock<IMainDom> mainDom,
|
|
[Frozen] Mock<IServerRoleAccessor> serverRoleAccessor,
|
|
[Frozen] Mock<IRuntimeState> runtimeState,
|
|
[Frozen] Mock<IContentVersionService> cleanupService,
|
|
ContentVersionCleanupJob sut)
|
|
{
|
|
settings.Setup(x => x.CurrentValue).Returns(new ContentSettings
|
|
{
|
|
ContentVersionCleanupPolicy = new ContentVersionCleanupPolicySettings { EnableCleanup = true },
|
|
});
|
|
|
|
runtimeState.Setup(x => x.Level).Returns(RuntimeLevel.Run);
|
|
mainDom.Setup(x => x.IsMainDom).Returns(true);
|
|
serverRoleAccessor.Setup(x => x.CurrentServerRole).Returns(ServerRole.SchedulingPublisher);
|
|
|
|
await sut.ExecuteAsync();
|
|
|
|
cleanupService.Verify(x => x.PerformContentVersionCleanup(It.IsAny<DateTime>()), Times.Once);
|
|
}
|
|
}
|