* Refactor jobs from HostedServices into BackgroundJobs
* Clean up generics and DI setup
* Add RecurringBackgroundJob Unit Tests
* Add ServiceCollection helper
* Add Obsolete attributes
* Add Notification Classes
* Add UnitTests for RecurringBackgroundJob HostedService
* Add NotificationEvents
* Add state to notifications
* Update UnitTests
* Add Obsolete Attributes to old hosted service classes
* Updated xmldoc in IRecurringBackgroundJob.cs
* Update Obsolete attribute messages to indicate classes will be removed in Umbraco 14
(cherry picked from commit c30ffa9ac3)
51 lines
1.7 KiB
C#
51 lines
1.7 KiB
C#
// Copyright (c) Umbraco.
|
|
// See LICENSE for more details.
|
|
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Logging;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using Umbraco.Cms.Core.IO;
|
|
using Umbraco.Cms.Core.Runtime;
|
|
using Umbraco.Cms.Infrastructure.BackgroundJobs.Jobs;
|
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.BackgroundJobs.Jobs
|
|
{
|
|
[TestFixture]
|
|
public class TempFileCleanupJobTests
|
|
{
|
|
private Mock<IIOHelper> _mockIOHelper;
|
|
private readonly string _testPath = Path.Combine(TestContext.CurrentContext.TestDirectory.Split("bin")[0], "App_Data", "TEMP");
|
|
|
|
|
|
[Test]
|
|
public async Task Executes_And_Cleans_Files()
|
|
{
|
|
TempFileCleanupJob sut = CreateTempFileCleanupJob();
|
|
await sut.RunJobAsync();
|
|
VerifyFilesCleaned();
|
|
}
|
|
|
|
private TempFileCleanupJob CreateTempFileCleanupJob()
|
|
{
|
|
|
|
_mockIOHelper = new Mock<IIOHelper>();
|
|
_mockIOHelper.Setup(x => x.GetTempFolders())
|
|
.Returns(new DirectoryInfo[] { new(_testPath) });
|
|
_mockIOHelper.Setup(x => x.CleanFolder(It.IsAny<DirectoryInfo>(), It.IsAny<TimeSpan>()))
|
|
.Returns(CleanFolderResult.Success());
|
|
|
|
var mockLogger = new Mock<ILogger<TempFileCleanupJob>>();
|
|
|
|
return new TempFileCleanupJob(_mockIOHelper.Object,mockLogger.Object);
|
|
}
|
|
|
|
private void VerifyFilesNotCleaned() => VerifyFilesCleaned(Times.Never());
|
|
|
|
private void VerifyFilesCleaned() => VerifyFilesCleaned(Times.Once());
|
|
|
|
private void VerifyFilesCleaned(Times times) => _mockIOHelper.Verify(x => x.CleanFolder(It.Is<DirectoryInfo>(y => y.FullName == _testPath), It.IsAny<TimeSpan>()), times);
|
|
}
|
|
}
|