From 8ec5e2cddf90c5d3505d764f9591c3c76968ca5b Mon Sep 17 00:00:00 2001 From: Denis-Cosmin Nutiu Date: Sun, 3 Apr 2022 18:16:17 +0300 Subject: [PATCH] Rename SimpleOutputSink to DirectoryOutputSink --- ...tputSink.cs => TestDirectoryOutputSink.cs} | 18 ++++++++++-------- ...leOutputSink.cs => DirectoryOutputSink.cs} | 19 ++++++++++--------- ConsoleInterface/Program.cs | 6 +++--- 3 files changed, 23 insertions(+), 20 deletions(-) rename ConsoleInterface.Tests/{TestSimpleOutputSink.cs => TestDirectoryOutputSink.cs} (72%) rename ConsoleInterface/{SimpleOutputSink.cs => DirectoryOutputSink.cs} (77%) diff --git a/ConsoleInterface.Tests/TestSimpleOutputSink.cs b/ConsoleInterface.Tests/TestDirectoryOutputSink.cs similarity index 72% rename from ConsoleInterface.Tests/TestSimpleOutputSink.cs rename to ConsoleInterface.Tests/TestDirectoryOutputSink.cs index 030c742..3aa7789 100644 --- a/ConsoleInterface.Tests/TestSimpleOutputSink.cs +++ b/ConsoleInterface.Tests/TestDirectoryOutputSink.cs @@ -7,11 +7,11 @@ using Xunit; namespace ConsoleInterface.Tests; -public class TestSimpleOutputSink +public class TestDirectoryOutputSink { private readonly string? _testsProjectDirectory; - public TestSimpleOutputSink() + public TestDirectoryOutputSink() { _testsProjectDirectory = Environment.GetEnvironmentVariable("IMAGE_CORE_TESTS"); if (_testsProjectDirectory == null) @@ -27,14 +27,14 @@ public class TestSimpleOutputSink [InlineData("dir", "asd", @"dir\asd.jpg")] 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)); } [Fact] public void TestGetOutputPathNull() { - var sink = SimpleOutputSink.Create("directory"); + var sink = DirectoryOutputSink.Create("directory"); Assert.Throws(() => sink.GetOutputPath("")); } @@ -42,7 +42,7 @@ public class TestSimpleOutputSink public void TestSave() { // Setup - var sink = SimpleOutputSink.Create("directory"); + var sink = DirectoryOutputSink.Create("directory"); var metadataRemoverMock = new Mock(); metadataRemoverMock.Setup(i => i.GetImagePath()).Returns("alo.wtf"); @@ -50,7 +50,8 @@ public class TestSimpleOutputSink sink.Save(metadataRemoverMock.Object); // Assert - metadataRemoverMock.Verify(i => i.CleanImage("directory\\alo.jpg")); + metadataRemoverMock.Verify(i => i.CleanImage()); + metadataRemoverMock.Verify(i => i.SaveImage("directory\\alo.jpg")); } [Fact] @@ -58,7 +59,7 @@ public class TestSimpleOutputSink { // Setup 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(); var sourceFileName = Path.Combine(_testsProjectDirectory, "test_pictures\\IMG_0138.HEIC"); metadataRemoverMock.Setup(i => i.GetImagePath()).Returns(sourceFileName); @@ -67,6 +68,7 @@ public class TestSimpleOutputSink sink.Save(metadataRemoverMock.Object); // Assert - metadataRemoverMock.Verify(i => i.CleanImage(It.IsAny()), Times.Never); + metadataRemoverMock.Verify(i => i.CleanImage(), Times.Never); + metadataRemoverMock.Verify(i => i.SaveImage(It.IsAny()), Times.Never); } } \ No newline at end of file diff --git a/ConsoleInterface/SimpleOutputSink.cs b/ConsoleInterface/DirectoryOutputSink.cs similarity index 77% rename from ConsoleInterface/SimpleOutputSink.cs rename to ConsoleInterface/DirectoryOutputSink.cs index 3232799..b797b53 100644 --- a/ConsoleInterface/SimpleOutputSink.cs +++ b/ConsoleInterface/DirectoryOutputSink.cs @@ -8,20 +8,20 @@ using Microsoft.Extensions.Logging.Abstractions; namespace ConsoleInterface { /// - /// SimpleOutputFormatter keeps the original file name of the image when formatting it. - /// SimpleOutputFormatter also saves all the file names into a new directory. + /// DirectoryOutputSink keeps the original file name of the image when formatting it. + /// DirectoryOutputSink also saves all the file names into a new directory. /// path. /// - public class SimpleOutputSink : IOutputSink + public class DirectoryOutputSink : IOutputSink { public static ILogger Logger = NullLogger.Instance; private readonly string _outputDirectory; /// - /// Creates an instance of SimpleOutputFormatter. + /// Creates an instance of DirectoryOutputSink. /// /// The output directory. - public SimpleOutputSink(string outputDirectory) + public DirectoryOutputSink(string outputDirectory) { if (outputDirectory.Equals("")) { @@ -46,7 +46,8 @@ namespace ConsoleInterface } // Save the image under the same name in the new directory. - metadataRemover.CleanImage(newFilePath); + metadataRemover.CleanImage(); + metadataRemover.SaveImage(newFilePath); return true; } @@ -69,12 +70,12 @@ namespace ConsoleInterface } /// - /// Creates an instance of OriginalFilenameFileOutputPathFormatter. + /// Creates an instance of DirectoryOutputSink. /// /// The output directory. - public static SimpleOutputSink Create(string outputDirectory) + public static DirectoryOutputSink Create(string outputDirectory) { - return new SimpleOutputSink(outputDirectory); + return new DirectoryOutputSink(outputDirectory); } } } \ No newline at end of file diff --git a/ConsoleInterface/Program.cs b/ConsoleInterface/Program.cs index 2cf899c..4d5b37f 100644 --- a/ConsoleInterface/Program.cs +++ b/ConsoleInterface/Program.cs @@ -29,7 +29,7 @@ namespace ConsoleInterface private static void RunOptions(ProgramOptions options) { SetupLogging(options.LogLevel); - var outputFormatter = SimpleOutputSink.Create(options.DestinationDirectory); + var outputFormatter = DirectoryOutputSink.Create(options.DestinationDirectory); var executor = TaskExecutor.Create(new TaskExecutorOptions { EnableCompression = options.CompressFiles is true, @@ -105,8 +105,8 @@ namespace ConsoleInterface // File Retriever LocalFileBrowser.Logger = _loggerFactory.CreateLogger(nameof(LocalFileBrowser)); // FileName formatter - SimpleOutputSink.Logger = - _loggerFactory.CreateLogger(nameof(SimpleOutputSink)); + DirectoryOutputSink.Logger = + _loggerFactory.CreateLogger(nameof(DirectoryOutputSink)); FileSystemHelpers.Logger = _loggerFactory.CreateLogger(nameof(FileSystemHelpers)); Logger.LogTrace("SetupLogging - exit"); }