Rename SimpleOutputSink to DirectoryOutputSink

This commit is contained in:
Denis-Cosmin Nutiu 2022-04-03 18:16:17 +03:00
parent b92791f336
commit 8ec5e2cddf
3 changed files with 23 additions and 20 deletions

View file

@ -7,11 +7,11 @@ using Xunit;
namespace ConsoleInterface.Tests; namespace ConsoleInterface.Tests;
public class TestSimpleOutputSink public class TestDirectoryOutputSink
{ {
private readonly string? _testsProjectDirectory; private readonly string? _testsProjectDirectory;
public TestSimpleOutputSink() public TestDirectoryOutputSink()
{ {
_testsProjectDirectory = Environment.GetEnvironmentVariable("IMAGE_CORE_TESTS"); _testsProjectDirectory = Environment.GetEnvironmentVariable("IMAGE_CORE_TESTS");
if (_testsProjectDirectory == null) if (_testsProjectDirectory == null)
@ -27,14 +27,14 @@ public class TestSimpleOutputSink
[InlineData("dir", "asd", @"dir\asd.jpg")] [InlineData("dir", "asd", @"dir\asd.jpg")]
public void TestGetOutputPath(string directory, string file, string expectedPath) public void TestGetOutputPath(string directory, string file, string expectedPath)
{ {
var sink = SimpleOutputSink.Create(directory); var sink = DirectoryOutputSink.Create(directory);
Assert.Equal(expectedPath, sink.GetOutputPath(file)); Assert.Equal(expectedPath, sink.GetOutputPath(file));
} }
[Fact] [Fact]
public void TestGetOutputPathNull() public void TestGetOutputPathNull()
{ {
var sink = SimpleOutputSink.Create("directory"); var sink = DirectoryOutputSink.Create("directory");
Assert.Throws<ArgumentException>(() => sink.GetOutputPath("")); Assert.Throws<ArgumentException>(() => sink.GetOutputPath(""));
} }
@ -42,7 +42,7 @@ public class TestSimpleOutputSink
public void TestSave() public void TestSave()
{ {
// Setup // Setup
var sink = SimpleOutputSink.Create("directory"); var sink = DirectoryOutputSink.Create("directory");
var metadataRemoverMock = new Mock<IMetadataRemover>(); var metadataRemoverMock = new Mock<IMetadataRemover>();
metadataRemoverMock.Setup(i => i.GetImagePath()).Returns("alo.wtf"); metadataRemoverMock.Setup(i => i.GetImagePath()).Returns("alo.wtf");
@ -50,7 +50,8 @@ public class TestSimpleOutputSink
sink.Save(metadataRemoverMock.Object); sink.Save(metadataRemoverMock.Object);
// Assert // Assert
metadataRemoverMock.Verify(i => i.CleanImage("directory\\alo.jpg")); metadataRemoverMock.Verify(i => i.CleanImage());
metadataRemoverMock.Verify(i => i.SaveImage("directory\\alo.jpg"));
} }
[Fact] [Fact]
@ -58,7 +59,7 @@ public class TestSimpleOutputSink
{ {
// Setup // Setup
Debug.Assert(_testsProjectDirectory != null, nameof(_testsProjectDirectory) + " != null"); Debug.Assert(_testsProjectDirectory != null, nameof(_testsProjectDirectory) + " != null");
var sink = SimpleOutputSink.Create(Path.Combine(_testsProjectDirectory, "test_pictures")); var sink = DirectoryOutputSink.Create(Path.Combine(_testsProjectDirectory, "test_pictures"));
var metadataRemoverMock = new Mock<IMetadataRemover>(); var metadataRemoverMock = new Mock<IMetadataRemover>();
var sourceFileName = Path.Combine(_testsProjectDirectory, "test_pictures\\IMG_0138.HEIC"); var sourceFileName = Path.Combine(_testsProjectDirectory, "test_pictures\\IMG_0138.HEIC");
metadataRemoverMock.Setup(i => i.GetImagePath()).Returns(sourceFileName); metadataRemoverMock.Setup(i => i.GetImagePath()).Returns(sourceFileName);
@ -67,6 +68,7 @@ public class TestSimpleOutputSink
sink.Save(metadataRemoverMock.Object); sink.Save(metadataRemoverMock.Object);
// Assert // Assert
metadataRemoverMock.Verify(i => i.CleanImage(It.IsAny<string>()), Times.Never); metadataRemoverMock.Verify(i => i.CleanImage(), Times.Never);
metadataRemoverMock.Verify(i => i.SaveImage(It.IsAny<string>()), Times.Never);
} }
} }

View file

@ -8,20 +8,20 @@ using Microsoft.Extensions.Logging.Abstractions;
namespace ConsoleInterface namespace ConsoleInterface
{ {
/// <summary> /// <summary>
/// SimpleOutputFormatter keeps the original file name of the image when formatting it. /// DirectoryOutputSink keeps the original file name of the image when formatting it.
/// SimpleOutputFormatter also saves all the file names into a new directory. /// DirectoryOutputSink also saves all the file names into a new directory.
/// path. /// path.
/// </summary> /// </summary>
public class SimpleOutputSink : IOutputSink public class DirectoryOutputSink : IOutputSink
{ {
public static ILogger Logger = NullLogger.Instance; public static ILogger Logger = NullLogger.Instance;
private readonly string _outputDirectory; private readonly string _outputDirectory;
/// <summary> /// <summary>
/// Creates an instance of SimpleOutputFormatter. /// Creates an instance of DirectoryOutputSink.
/// </summary> /// </summary>
/// <param name="outputDirectory">The output directory.</param> /// <param name="outputDirectory">The output directory.</param>
public SimpleOutputSink(string outputDirectory) public DirectoryOutputSink(string outputDirectory)
{ {
if (outputDirectory.Equals("")) if (outputDirectory.Equals(""))
{ {
@ -46,7 +46,8 @@ namespace ConsoleInterface
} }
// 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();
metadataRemover.SaveImage(newFilePath);
return true; return true;
} }
@ -69,12 +70,12 @@ namespace ConsoleInterface
} }
/// <summary> /// <summary>
/// Creates an instance of OriginalFilenameFileOutputPathFormatter. /// Creates an instance of DirectoryOutputSink.
/// </summary> /// </summary>
/// <param name="outputDirectory">The output directory.</param> /// <param name="outputDirectory">The output directory.</param>
public static SimpleOutputSink Create(string outputDirectory) public static DirectoryOutputSink Create(string outputDirectory)
{ {
return new SimpleOutputSink(outputDirectory); return new DirectoryOutputSink(outputDirectory);
} }
} }
} }

View file

@ -29,7 +29,7 @@ namespace ConsoleInterface
private static void RunOptions(ProgramOptions options) private static void RunOptions(ProgramOptions options)
{ {
SetupLogging(options.LogLevel); SetupLogging(options.LogLevel);
var outputFormatter = SimpleOutputSink.Create(options.DestinationDirectory); var outputFormatter = DirectoryOutputSink.Create(options.DestinationDirectory);
var executor = TaskExecutor.Create(new TaskExecutorOptions var executor = TaskExecutor.Create(new TaskExecutorOptions
{ {
EnableCompression = options.CompressFiles is true, EnableCompression = options.CompressFiles is true,
@ -105,8 +105,8 @@ namespace ConsoleInterface
// File Retriever // File Retriever
LocalFileBrowser.Logger = _loggerFactory.CreateLogger(nameof(LocalFileBrowser)); LocalFileBrowser.Logger = _loggerFactory.CreateLogger(nameof(LocalFileBrowser));
// FileName formatter // FileName formatter
SimpleOutputSink.Logger = DirectoryOutputSink.Logger =
_loggerFactory.CreateLogger(nameof(SimpleOutputSink)); _loggerFactory.CreateLogger(nameof(DirectoryOutputSink));
FileSystemHelpers.Logger = _loggerFactory.CreateLogger(nameof(FileSystemHelpers)); FileSystemHelpers.Logger = _loggerFactory.CreateLogger(nameof(FileSystemHelpers));
Logger.LogTrace("SetupLogging - exit"); Logger.LogTrace("SetupLogging - exit");
} }