diff --git a/CompactGUI.Core.Tests/CompactGUI.Core.Tests.csproj b/CompactGUI.Core.Tests/CompactGUI.Core.Tests.csproj new file mode 100644 index 0000000..2366154 --- /dev/null +++ b/CompactGUI.Core.Tests/CompactGUI.Core.Tests.csproj @@ -0,0 +1,26 @@ + + + + net9.0-windows + enable + false + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/CompactGUI.Core.Tests/CompactorTests.cs b/CompactGUI.Core.Tests/CompactorTests.cs new file mode 100644 index 0000000..0332a5f --- /dev/null +++ b/CompactGUI.Core.Tests/CompactorTests.cs @@ -0,0 +1,38 @@ +using Xunit; +using CompactGUI.Core; +using System.IO; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace CompactGUI.Core.Tests +{ + public class CompactorTests + { + [Fact] + public async Task BuildWorkingFilesList_WithExclusion_ShouldExcludeCorrectFiles() + { + // Arrange + var tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); + Directory.CreateDirectory(tempDir); + var file1 = Path.Combine(tempDir, "test.txt"); + var file2 = Path.Combine(tempDir, "test.log"); + File.WriteAllText(file1, "This is a test file."); + File.WriteAllText(file2, "This is a log file."); + + var analyser = new Analyser(tempDir, null); + var compactor = new Compactor(tempDir, WOFCompressionAlgorithm.XPRESS4K, new[] { ".log" }, analyser, null); + + // Act + var fileDetails = (FileDetails)await compactor.BuildWorkingFilesList(); + var workingFiles = new List(fileDetails); + + // Assert + Assert.Single(workingFiles); + Assert.Equal(file1, workingFiles[0].FileName); + + // Clean up + Directory.Delete(tempDir, true); + } + } +} diff --git a/CompactGUI.Core/Compactor.cs b/CompactGUI.Core/Compactor.cs index 0c6071f..d14627d 100644 --- a/CompactGUI.Core/Compactor.cs +++ b/CompactGUI.Core/Compactor.cs @@ -132,7 +132,7 @@ public async Task> BuildWorkingFilesList() .Where(fl => fl.CompressionMode != wofCompressionAlgorithm && fl.UncompressedSize > clusterSize - && ((fl.FileInfo != null && !excludedFileExtensions.Contains(fl.FileInfo.Extension)) || excludedFileExtensions.Contains(fl.FileName)) + && fl.FileInfo != null && !excludedFileExtensions.Contains(fl.FileInfo.Extension) ) .Select(fl => new FileDetails(fl.FileName, fl.UncompressedSize)) .ToList();