Refactor project structure
This commit is contained in:
parent
c0251bfa75
commit
81c4b13f62
19 changed files with 231 additions and 179 deletions
44
ConsoleInterface.Tests/TestLocalFileBrowser.cs
Normal file
44
ConsoleInterface.Tests/TestLocalFileBrowser.cs
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace ConsoleInterface.Tests;
|
||||||
|
|
||||||
|
public class TestLocalFileBrowser
|
||||||
|
{
|
||||||
|
private readonly string? _testsProjectDirectory;
|
||||||
|
|
||||||
|
public TestLocalFileBrowser()
|
||||||
|
{
|
||||||
|
_testsProjectDirectory = Environment.GetEnvironmentVariable("IMAGE_CORE_TESTS");
|
||||||
|
if (_testsProjectDirectory == null) throw new Exception("Environment variable IMAGE_CORE_TESTS is not set!");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestGetFilenamesFromPath_DirectoryNotFound()
|
||||||
|
{
|
||||||
|
var filesRetriever = LocalFileBrowser.Create();
|
||||||
|
Assert.Throws<DirectoryNotFoundException>(() => filesRetriever.GetFilenamesFromPath("a"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestGetFilenamesFromPath()
|
||||||
|
{
|
||||||
|
var filesRetriever = LocalFileBrowser.Create();
|
||||||
|
Debug.Assert(_testsProjectDirectory != null, nameof(_testsProjectDirectory) + " != null");
|
||||||
|
var filePaths = filesRetriever.GetFilenamesFromPath(Path.Combine(_testsProjectDirectory, "test_pictures"));
|
||||||
|
Assert.NotNull(filePaths);
|
||||||
|
var filePathsList = filePaths.ToList();
|
||||||
|
var expectedFileNames = new List<string>
|
||||||
|
{
|
||||||
|
"IMG_0138.HEIC", "IMG_0138.jpg", "IMG_0140.HEIC"
|
||||||
|
};
|
||||||
|
|
||||||
|
Assert.NotEmpty(filePathsList);
|
||||||
|
for (var i = 0; i < filePathsList.Count; i++)
|
||||||
|
Assert.Equal(expectedFileNames[i], Path.GetFileName(filePathsList[i]));
|
||||||
|
}
|
||||||
|
}
|
69
ConsoleInterface.Tests/TestSimpleOutputSink.cs
Normal file
69
ConsoleInterface.Tests/TestSimpleOutputSink.cs
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using Image.Core;
|
||||||
|
using Moq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace ConsoleInterface.Tests;
|
||||||
|
|
||||||
|
public class TestSimpleOutputSink
|
||||||
|
{
|
||||||
|
private readonly string? _testsProjectDirectory;
|
||||||
|
|
||||||
|
public TestSimpleOutputSink()
|
||||||
|
{
|
||||||
|
_testsProjectDirectory = Environment.GetEnvironmentVariable("IMAGE_CORE_TESTS");
|
||||||
|
if (_testsProjectDirectory == null) throw new Exception("Environment variable IMAGE_CORE_TESTS is not set!");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("", "./", @".\.jpg")]
|
||||||
|
[InlineData("", @".\", @".\.jpg")]
|
||||||
|
[InlineData("", "asd", @".\asd.jpg")]
|
||||||
|
[InlineData("dir", "asd", @"dir\asd.jpg")]
|
||||||
|
public void TestGetOutputPath(string directory, string file, string expectedPath)
|
||||||
|
{
|
||||||
|
var sink = SimpleOutputSink.Create(directory);
|
||||||
|
Assert.Equal(expectedPath, sink.GetOutputPath(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestGetOutputPathNull()
|
||||||
|
{
|
||||||
|
var sink = SimpleOutputSink.Create("directory");
|
||||||
|
Assert.Throws<ArgumentException>(() => sink.GetOutputPath(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestSave()
|
||||||
|
{
|
||||||
|
// Setup
|
||||||
|
var sink = SimpleOutputSink.Create("directory");
|
||||||
|
var metadataRemoverMock = new Mock<IMetadataRemover>();
|
||||||
|
metadataRemoverMock.Setup(i => i.GetImagePath()).Returns("alo.wtf");
|
||||||
|
|
||||||
|
// Test
|
||||||
|
sink.Save(metadataRemoverMock.Object);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
metadataRemoverMock.Verify(i => i.CleanImage("directory\\alo.jpg"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestSaveFileExists()
|
||||||
|
{
|
||||||
|
// Setup
|
||||||
|
Debug.Assert(_testsProjectDirectory != null, nameof(_testsProjectDirectory) + " != null");
|
||||||
|
var sink = SimpleOutputSink.Create(Path.Combine(_testsProjectDirectory, "test_pictures"));
|
||||||
|
var metadataRemoverMock = new Mock<IMetadataRemover>();
|
||||||
|
var sourceFileName = Path.Combine(_testsProjectDirectory, "test_pictures\\IMG_0138.HEIC");
|
||||||
|
metadataRemoverMock.Setup(i => i.GetImagePath()).Returns(sourceFileName);
|
||||||
|
|
||||||
|
// Test
|
||||||
|
sink.Save(metadataRemoverMock.Object);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
metadataRemoverMock.Verify(i => i.CleanImage(It.IsAny<string>()), Times.Never);
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,10 +12,10 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CommandLineParser" Version="2.8.0" />
|
<PackageReference Include="CommandLineParser" Version="2.8.0"/>
|
||||||
<ProjectReference Include="..\ImageCore\ImageCore.csproj" />
|
<ProjectReference Include="..\ImageCore\ImageCore.csproj"/>
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0"/>
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -2,14 +2,14 @@
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
|
||||||
namespace Image.Files
|
namespace ConsoleInterface
|
||||||
{
|
{
|
||||||
public static class FileSystemHelpers
|
public static class FileSystemHelpers
|
||||||
{
|
{
|
||||||
public static ILogger Logger = NullLogger.Instance;
|
public static ILogger Logger = NullLogger.Instance;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates the directory if it doesn't exist.
|
/// Creates the directory if it doesn't exist.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="directoryPath">The destination directory's path.</param>
|
/// <param name="directoryPath">The destination directory's path.</param>
|
||||||
public static void CreateDestinationDirectory(string directoryPath)
|
public static void CreateDestinationDirectory(string directoryPath)
|
||||||
|
@ -20,7 +20,7 @@ namespace Image.Files
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// CheckIfFileExists checks if file exists.
|
/// CheckIfFileExists checks if file exists.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filePath">The path of the file to be checked.</param>
|
/// <param name="filePath">The path of the file to be checked.</param>
|
||||||
/// <returns>Returns true if file exists, False otherwise.</returns>
|
/// <returns>Returns true if file exists, False otherwise.</returns>
|
|
@ -1,6 +1,6 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Image.Files
|
namespace ConsoleInterface
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An to interface enabling implementation of file browsers.
|
/// An to interface enabling implementation of file browsers.
|
|
@ -1,6 +1,6 @@
|
||||||
using Image.Core;
|
using Image.Core;
|
||||||
|
|
||||||
namespace Image.Files
|
namespace Image
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// IOutputSink is an interface for generating saving the generated files..
|
/// IOutputSink is an interface for generating saving the generated files..
|
||||||
|
@ -8,7 +8,7 @@ namespace Image.Files
|
||||||
public interface IOutputSink
|
public interface IOutputSink
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Saves the image.
|
/// Saves the image.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="metadataRemover">Metadata remover instance.</param>
|
/// <param name="metadataRemover">Metadata remover instance.</param>
|
||||||
/// <returns>True if the image was saved successfully, false otherwise.</returns>
|
/// <returns>True if the image was saved successfully, false otherwise.</returns>
|
|
@ -3,7 +3,7 @@ using System.IO;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
|
||||||
namespace Image.Files
|
namespace ConsoleInterface
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// LocalFileBrowser reads files from the provided directory on the local system.
|
/// LocalFileBrowser reads files from the provided directory on the local system.
|
|
@ -1,6 +1,4 @@
|
||||||
using CommandLine;
|
using CommandLine;
|
||||||
using Image.Files;
|
|
||||||
using Image.Tasks;
|
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
using System.IO;
|
using System;
|
||||||
using Ardalis.GuardClauses;
|
using System.IO;
|
||||||
|
using Image;
|
||||||
using Image.Core;
|
using Image.Core;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
|
||||||
namespace Image.Files
|
namespace ConsoleInterface
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// SimpleOutputFormatter keeps the original file name of the image when formatting it.
|
/// SimpleOutputFormatter keeps the original file name of the image when formatting it.
|
||||||
|
@ -23,30 +24,12 @@ namespace Image.Files
|
||||||
public SimpleOutputSink(string outputDirectory)
|
public SimpleOutputSink(string outputDirectory)
|
||||||
{
|
{
|
||||||
if (outputDirectory.Equals(""))
|
if (outputDirectory.Equals(""))
|
||||||
{
|
|
||||||
outputDirectory = ".";
|
outputDirectory = ".";
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
FileSystemHelpers.CreateDestinationDirectory(outputDirectory);
|
FileSystemHelpers.CreateDestinationDirectory(outputDirectory);
|
||||||
}
|
|
||||||
_outputDirectory = outputDirectory;
|
_outputDirectory = outputDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns a path containing the file name in the output directory.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="initialFilePath">The initial path of the image.</param>
|
|
||||||
/// <returns>An absolute path of the form output_directory/initialFileName.jpg</returns>
|
|
||||||
public string GetOutputPath(string initialFilePath)
|
|
||||||
{
|
|
||||||
Logger.LogDebug($"KeepFilenameFormatter - {_outputDirectory} - {initialFilePath}");
|
|
||||||
Guard.Against.NullOrEmpty(initialFilePath, nameof(initialFilePath));
|
|
||||||
var fileName = Path.GetFileName(initialFilePath).Split('.')[0];
|
|
||||||
var path = Path.Combine(_outputDirectory, $"{fileName}.jpg");
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Save(IMetadataRemover metadataRemover)
|
public bool Save(IMetadataRemover metadataRemover)
|
||||||
{
|
{
|
||||||
var newFilePath = GetOutputPath(metadataRemover.GetImagePath());
|
var newFilePath = GetOutputPath(metadataRemover.GetImagePath());
|
||||||
|
@ -56,11 +39,28 @@ namespace Image.Files
|
||||||
Logger.LogWarning($"File {newFilePath} exists, skipping");
|
Logger.LogWarning($"File {newFilePath} exists, skipping");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the image under the same name in the new directory.
|
// Save the image under the same name in the new directory.
|
||||||
metadataRemover.CleanImage(newFilePath);
|
metadataRemover.CleanImage(newFilePath);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a path containing the file name in the output directory.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="initialFilePath">The initial path of the image.</param>
|
||||||
|
/// <returns>An absolute path of the form output_directory/initialFileName.jpg</returns>
|
||||||
|
public string GetOutputPath(string initialFilePath)
|
||||||
|
{
|
||||||
|
Logger.LogDebug($"KeepFilenameFormatter - {_outputDirectory} - {initialFilePath}");
|
||||||
|
if (string.IsNullOrEmpty(initialFilePath))
|
||||||
|
throw new ArgumentException("The output file path cannot be null or empty!");
|
||||||
|
|
||||||
|
var fileName = Path.GetFileName(initialFilePath).Split('.')[0];
|
||||||
|
var path = Path.Combine(_outputDirectory, $"{fileName}.jpg");
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates an instance of OriginalFilenameFileOutputPathFormatter.
|
/// Creates an instance of OriginalFilenameFileOutputPathFormatter.
|
||||||
/// </summary>
|
/// </summary>
|
|
@ -2,13 +2,13 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Image;
|
||||||
using Image.Core;
|
using Image.Core;
|
||||||
using Image.Files;
|
|
||||||
using ImageMagick;
|
using ImageMagick;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
|
||||||
namespace Image.Tasks
|
namespace ConsoleInterface
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// TaskExecutor is a helper class for executing tasks in parallel.
|
/// TaskExecutor is a helper class for executing tasks in parallel.
|
||||||
|
@ -47,8 +47,9 @@ namespace Image.Tasks
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Logger.LogDebug($"Cleaning {filePath}, compression {_options.EnableCompression}, outputFormatter {nameof(_options.OutputSink)}.");
|
Logger.LogDebug(
|
||||||
|
$"Cleaning {filePath}, compression {_options.EnableCompression}, outputFormatter {nameof(_options.OutputSink)}.");
|
||||||
|
|
||||||
ICompressor compressor = NullCompressor.Instance;
|
ICompressor compressor = NullCompressor.Instance;
|
||||||
if (_options.EnableCompression) compressor = LosslessCompressor.Instance;
|
if (_options.EnableCompression) compressor = LosslessCompressor.Instance;
|
||||||
var imageMagick = new MagickImage(filePath);
|
var imageMagick = new MagickImage(filePath);
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using Image.Files;
|
using Image;
|
||||||
|
|
||||||
namespace Image.Tasks
|
namespace ConsoleInterface
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// TaskExecutorOptions is a class containing various parameters for the <see cref="TaskExecutor" /> class.
|
/// TaskExecutorOptions is a class containing various parameters for the <see cref="TaskExecutor" /> class.
|
|
@ -8,9 +8,9 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4"/>
|
||||||
<PackageReference Include="Moq" Version="4.16.1" />
|
<PackageReference Include="Moq" Version="4.16.1"/>
|
||||||
<PackageReference Include="xunit" Version="2.4.1" />
|
<PackageReference Include="xunit" Version="2.4.1"/>
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
@ -22,7 +22,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\ImageCore\ImageCore.csproj" />
|
<ProjectReference Include="..\ImageCore\ImageCore.csproj"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -18,35 +18,35 @@ namespace ImageCore.Tests
|
||||||
public void TestLosslessCompressor_Compress()
|
public void TestLosslessCompressor_Compress()
|
||||||
{
|
{
|
||||||
ICompressor compressor = new LosslessCompressor();
|
ICompressor compressor = new LosslessCompressor();
|
||||||
var sourceFileName = Path.Join(_testsProjectDirectory, "test_pictures/IMG_0138.HEIC");
|
var sourceFileName = Path.Combine(_testsProjectDirectory, "test_pictures/IMG_0138.HEIC");
|
||||||
var destinationFileName = Path.GetTempFileName();
|
var destinationFileName = Path.GetTempFileName();
|
||||||
File.Copy(sourceFileName, destinationFileName, true);
|
File.Copy(sourceFileName, destinationFileName, true);
|
||||||
compressor.Compress(destinationFileName);
|
compressor.Compress(destinationFileName);
|
||||||
|
|
||||||
var originalFile = File.Open(sourceFileName, FileMode.Open);
|
var originalFile = File.Open(sourceFileName, FileMode.Open);
|
||||||
var compressedFile = File.Open(destinationFileName, FileMode.Open);
|
var compressedFile = File.Open(destinationFileName, FileMode.Open);
|
||||||
|
|
||||||
Assert.True(compressedFile.Length <= originalFile.Length);
|
Assert.True(compressedFile.Length <= originalFile.Length);
|
||||||
|
|
||||||
originalFile.Close();
|
originalFile.Close();
|
||||||
compressedFile.Close();
|
compressedFile.Close();
|
||||||
File.Delete(destinationFileName);
|
File.Delete(destinationFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TestNullCompressor_Compress()
|
public void TestNullCompressor_Compress()
|
||||||
{
|
{
|
||||||
ICompressor compressor = new NullCompressor();
|
ICompressor compressor = new NullCompressor();
|
||||||
var sourceFileName = Path.Join(_testsProjectDirectory, "test_pictures/IMG_0138.HEIC");
|
var sourceFileName = Path.Combine(_testsProjectDirectory, "test_pictures/IMG_0138.HEIC");
|
||||||
var destinationFileName = Path.GetTempFileName();
|
var destinationFileName = Path.GetTempFileName();
|
||||||
File.Copy(sourceFileName, destinationFileName, true);
|
File.Copy(sourceFileName, destinationFileName, true);
|
||||||
compressor.Compress(destinationFileName);
|
compressor.Compress(destinationFileName);
|
||||||
|
|
||||||
var originalFile = File.Open(sourceFileName, FileMode.Open);
|
var originalFile = File.Open(sourceFileName, FileMode.Open);
|
||||||
var compressedFile = File.Open(destinationFileName, FileMode.Open);
|
var compressedFile = File.Open(destinationFileName, FileMode.Open);
|
||||||
|
|
||||||
Assert.True(compressedFile.Length == originalFile.Length);
|
Assert.True(compressedFile.Length == originalFile.Length);
|
||||||
|
|
||||||
originalFile.Close();
|
originalFile.Close();
|
||||||
compressedFile.Close();
|
compressedFile.Close();
|
||||||
File.Delete(destinationFileName);
|
File.Delete(destinationFileName);
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using Image.Files;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace ImageCore.Tests
|
|
||||||
{
|
|
||||||
public class TestLocalFileBrowser
|
|
||||||
{
|
|
||||||
private readonly string _testsProjectDirectory;
|
|
||||||
|
|
||||||
public TestLocalFileBrowser()
|
|
||||||
{
|
|
||||||
_testsProjectDirectory = Environment.GetEnvironmentVariable("IMAGE_CORE_TESTS");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void TestGetFilenamesFromPath_DirectoryNotFound()
|
|
||||||
{
|
|
||||||
var filesRetriever = LocalFileBrowser.Create();
|
|
||||||
Assert.Throws<DirectoryNotFoundException>(() => filesRetriever.GetFilenamesFromPath("a"));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void TestGetFilenamesFromPath()
|
|
||||||
{
|
|
||||||
var filesRetriever = LocalFileBrowser.Create();
|
|
||||||
var filePaths = filesRetriever.GetFilenamesFromPath(Path.Join(_testsProjectDirectory, "test_pictures"));
|
|
||||||
Assert.NotNull(filePaths);
|
|
||||||
var filePathsList = filePaths.ToList();
|
|
||||||
var expectedFileNames = new List<string>
|
|
||||||
{
|
|
||||||
"IMG_0138.HEIC", "IMG_0138.jpg", "IMG_0140.HEIC",
|
|
||||||
};
|
|
||||||
|
|
||||||
Assert.NotEmpty(filePathsList);
|
|
||||||
for (var i = 0; i < filePathsList.Count; i++)
|
|
||||||
{
|
|
||||||
Assert.Equal(expectedFileNames[i], Path.GetFileName(filePathsList[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -14,14 +14,14 @@ namespace ImageCore.Tests
|
||||||
var magicImageMock = new Mock<IMagickImage>();
|
var magicImageMock = new Mock<IMagickImage>();
|
||||||
var compressorMock = new Mock<ICompressor>();
|
var compressorMock = new Mock<ICompressor>();
|
||||||
var metadataRemover = new ExifRemoverAndCompressor(magicImageMock.Object, compressorMock.Object);
|
var metadataRemover = new ExifRemoverAndCompressor(magicImageMock.Object, compressorMock.Object);
|
||||||
|
|
||||||
// Test
|
// Test
|
||||||
metadataRemover.CleanImage("path");
|
metadataRemover.CleanImage("path");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
magicImageMock.Verify( i => i.RemoveProfile("exif"));
|
magicImageMock.Verify(i => i.RemoveProfile("exif"));
|
||||||
magicImageMock.Verify( i => i.Write("path"));
|
magicImageMock.Verify(i => i.Write("path"));
|
||||||
compressorMock.Verify( i => i.Compress("path"));
|
compressorMock.Verify(i => i.Compress("path"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
@ -30,13 +30,13 @@ namespace ImageCore.Tests
|
||||||
// Setup
|
// Setup
|
||||||
var magicImageMock = new Mock<IMagickImage>();
|
var magicImageMock = new Mock<IMagickImage>();
|
||||||
magicImageMock.Setup(i => i.FileName).Returns("P4th");
|
magicImageMock.Setup(i => i.FileName).Returns("P4th");
|
||||||
|
|
||||||
var compressorMock = new Mock<ICompressor>();
|
var compressorMock = new Mock<ICompressor>();
|
||||||
var metadataRemover = new ExifRemoverAndCompressor(magicImageMock.Object, compressorMock.Object);
|
var metadataRemover = new ExifRemoverAndCompressor(magicImageMock.Object, compressorMock.Object);
|
||||||
|
|
||||||
// Test
|
// Test
|
||||||
var result = metadataRemover.GetImagePath();
|
var result = metadataRemover.GetImagePath();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal("P4th", result);
|
Assert.Equal("P4th", result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,68 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using Image.Core;
|
|
||||||
using Image.Files;
|
|
||||||
using Moq;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace ImageCore.Tests
|
|
||||||
{
|
|
||||||
public class TestSimpleOutputSink
|
|
||||||
{
|
|
||||||
private readonly string _testsProjectDirectory;
|
|
||||||
|
|
||||||
public TestSimpleOutputSink()
|
|
||||||
{
|
|
||||||
_testsProjectDirectory = Environment.GetEnvironmentVariable("IMAGE_CORE_TESTS");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData("", "./", @".\.jpg")]
|
|
||||||
[InlineData("", @".\", @".\.jpg")]
|
|
||||||
[InlineData("", "asd", @".\asd.jpg")]
|
|
||||||
[InlineData("dir", "asd", @"dir\asd.jpg")]
|
|
||||||
public void TestGetOutputPath(string directory, string file, string expectedPath)
|
|
||||||
{
|
|
||||||
var sink = SimpleOutputSink.Create(directory);
|
|
||||||
Assert.Equal(expectedPath, sink.GetOutputPath(file));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void TestGetOutputPathNull()
|
|
||||||
{
|
|
||||||
var sink = SimpleOutputSink.Create("directory");
|
|
||||||
Assert.Throws<ArgumentException>(() => sink.GetOutputPath(""));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void TestSave()
|
|
||||||
{
|
|
||||||
// Setup
|
|
||||||
var sink = SimpleOutputSink.Create("directory");
|
|
||||||
var metadataRemoverMock = new Mock<IMetadataRemover>();
|
|
||||||
metadataRemoverMock.Setup(i => i.GetImagePath()).Returns("alo.wtf");
|
|
||||||
|
|
||||||
// Test
|
|
||||||
sink.Save(metadataRemoverMock.Object);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
metadataRemoverMock.Verify(i => i.CleanImage("directory\\alo.jpg"));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void TestSaveFileExists()
|
|
||||||
{
|
|
||||||
// Setup
|
|
||||||
var sink = SimpleOutputSink.Create(Path.Join(_testsProjectDirectory, "test_pictures"));
|
|
||||||
var metadataRemoverMock = new Mock<IMetadataRemover>();
|
|
||||||
var sourceFileName = Path.Join(_testsProjectDirectory, "test_pictures\\IMG_0138.HEIC");
|
|
||||||
metadataRemoverMock.Setup(i => i.GetImagePath()).Returns(sourceFileName);
|
|
||||||
|
|
||||||
// Test
|
|
||||||
sink.Save(metadataRemoverMock.Object);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
metadataRemoverMock.Verify(i => i.CleanImage(It.IsAny<string>()), Times.Never);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -12,7 +12,7 @@
|
||||||
void CleanImage(string newFilePath);
|
void CleanImage(string newFilePath);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// GetImagePath gets the current image path on the filesystem.
|
/// GetImagePath gets the current image path on the filesystem.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>A string representing the absolute path.</returns>
|
/// <returns>A string representing the absolute path.</returns>
|
||||||
string GetImagePath();
|
string GetImagePath();
|
||||||
|
|
|
@ -2,15 +2,14 @@
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<RootNamespace>Image</RootNamespace>
|
<RootNamespace>Image</RootNamespace>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
|
||||||
<LangVersion>8.0</LangVersion>
|
<LangVersion>8.0</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Ardalis.GuardClauses" Version="4.0.0" />
|
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="8.6.1"/>
|
||||||
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="8.6.1" />
|
<PackageReference Include="Magick.NET.Core" Version="8.6.1"/>
|
||||||
<PackageReference Include="Magick.NET.Core" Version="8.6.1" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0"/>
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -9,6 +9,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleInterface", "Console
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageCore.Tests", "ImageCore.Tests\ImageCore.Tests.csproj", "{8EB81515-E62C-4408-84E0-6C27E0293902}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageCore.Tests", "ImageCore.Tests\ImageCore.Tests.csproj", "{8EB81515-E62C-4408-84E0-6C27E0293902}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UwpApplication", "UwpApplication\UwpApplication.csproj", "{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleInterface.Tests", "ConsoleInterface.Tests\ConsoleInterface.Tests.csproj", "{B915AC83-B6E9-4E0A-BA88-915F629F57C8}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
@ -83,6 +87,56 @@ Global
|
||||||
{8EB81515-E62C-4408-84E0-6C27E0293902}.Release|x64.Build.0 = Release|Any CPU
|
{8EB81515-E62C-4408-84E0-6C27E0293902}.Release|x64.Build.0 = Release|Any CPU
|
||||||
{8EB81515-E62C-4408-84E0-6C27E0293902}.Release|x86.ActiveCfg = Release|Any CPU
|
{8EB81515-E62C-4408-84E0-6C27E0293902}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{8EB81515-E62C-4408-84E0-6C27E0293902}.Release|x86.Build.0 = Release|Any CPU
|
{8EB81515-E62C-4408-84E0-6C27E0293902}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Debug|Any CPU.ActiveCfg = Debug|x64
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Debug|Any CPU.Build.0 = Debug|x64
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Debug|Any CPU.Deploy.0 = Debug|x64
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Debug|ARM.ActiveCfg = Debug|ARM
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Debug|ARM.Build.0 = Debug|ARM
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Debug|ARM.Deploy.0 = Debug|ARM
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Debug|ARM64.ActiveCfg = Debug|ARM64
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Debug|ARM64.Build.0 = Debug|ARM64
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Debug|ARM64.Deploy.0 = Debug|ARM64
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Debug|x64.Deploy.0 = Debug|x64
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Debug|x86.ActiveCfg = Debug|x86
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Debug|x86.Build.0 = Debug|x86
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Debug|x86.Deploy.0 = Debug|x86
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Release|Any CPU.ActiveCfg = Release|x64
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Release|Any CPU.Build.0 = Release|x64
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Release|Any CPU.Deploy.0 = Release|x64
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Release|ARM.ActiveCfg = Release|ARM
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Release|ARM.Build.0 = Release|ARM
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Release|ARM.Deploy.0 = Release|ARM
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Release|ARM64.ActiveCfg = Release|ARM64
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Release|ARM64.Build.0 = Release|ARM64
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Release|ARM64.Deploy.0 = Release|ARM64
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Release|x64.Build.0 = Release|x64
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Release|x64.Deploy.0 = Release|x64
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Release|x86.ActiveCfg = Release|x86
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Release|x86.Build.0 = Release|x86
|
||||||
|
{405DA0B4-AE2F-40A0-B74E-2F42F1049FDB}.Release|x86.Deploy.0 = Release|x86
|
||||||
|
{B915AC83-B6E9-4E0A-BA88-915F629F57C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B915AC83-B6E9-4E0A-BA88-915F629F57C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B915AC83-B6E9-4E0A-BA88-915F629F57C8}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||||
|
{B915AC83-B6E9-4E0A-BA88-915F629F57C8}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||||
|
{B915AC83-B6E9-4E0A-BA88-915F629F57C8}.Debug|ARM64.ActiveCfg = Debug|Any CPU
|
||||||
|
{B915AC83-B6E9-4E0A-BA88-915F629F57C8}.Debug|ARM64.Build.0 = Debug|Any CPU
|
||||||
|
{B915AC83-B6E9-4E0A-BA88-915F629F57C8}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{B915AC83-B6E9-4E0A-BA88-915F629F57C8}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{B915AC83-B6E9-4E0A-BA88-915F629F57C8}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{B915AC83-B6E9-4E0A-BA88-915F629F57C8}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{B915AC83-B6E9-4E0A-BA88-915F629F57C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{B915AC83-B6E9-4E0A-BA88-915F629F57C8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{B915AC83-B6E9-4E0A-BA88-915F629F57C8}.Release|ARM.ActiveCfg = Release|Any CPU
|
||||||
|
{B915AC83-B6E9-4E0A-BA88-915F629F57C8}.Release|ARM.Build.0 = Release|Any CPU
|
||||||
|
{B915AC83-B6E9-4E0A-BA88-915F629F57C8}.Release|ARM64.ActiveCfg = Release|Any CPU
|
||||||
|
{B915AC83-B6E9-4E0A-BA88-915F629F57C8}.Release|ARM64.Build.0 = Release|Any CPU
|
||||||
|
{B915AC83-B6E9-4E0A-BA88-915F629F57C8}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{B915AC83-B6E9-4E0A-BA88-915F629F57C8}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{B915AC83-B6E9-4E0A-BA88-915F629F57C8}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{B915AC83-B6E9-4E0A-BA88-915F629F57C8}.Release|x86.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
Loading…
Reference in a new issue