* 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>
61 lines
2.1 KiB
C#
61 lines
2.1 KiB
C#
// Copyright (c) Umbraco.
|
|
// See LICENSE for more details.
|
|
|
|
using System;
|
|
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.HostedServices;
|
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.HostedServices
|
|
{
|
|
[TestFixture]
|
|
public class TempFileCleanupTests
|
|
{
|
|
private Mock<IIOHelper> _mockIOHelper;
|
|
private readonly string _testPath = Path.Combine(TestContext.CurrentContext.TestDirectory.Split("bin")[0], "App_Data", "TEMP");
|
|
|
|
[Test]
|
|
public async Task Does_Not_Execute_When_Not_Main_Dom()
|
|
{
|
|
TempFileCleanup sut = CreateTempFileCleanup(isMainDom: false);
|
|
await sut.PerformExecuteAsync(null);
|
|
VerifyFilesNotCleaned();
|
|
}
|
|
|
|
[Test]
|
|
public async Task Executes_And_Cleans_Files()
|
|
{
|
|
TempFileCleanup sut = CreateTempFileCleanup();
|
|
await sut.PerformExecuteAsync(null);
|
|
VerifyFilesCleaned();
|
|
}
|
|
|
|
private TempFileCleanup CreateTempFileCleanup(bool isMainDom = true)
|
|
{
|
|
var mockMainDom = new Mock<IMainDom>();
|
|
mockMainDom.SetupGet(x => x.IsMainDom).Returns(isMainDom);
|
|
|
|
_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<TempFileCleanup>>();
|
|
|
|
return new TempFileCleanup(_mockIOHelper.Object, mockMainDom.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);
|
|
}
|
|
}
|