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;
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<ArgumentException>(() => 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<IMetadataRemover>();
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<IMetadataRemover>();
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<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
{
/// <summary>
/// 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.
/// </summary>
public class SimpleOutputSink : IOutputSink
public class DirectoryOutputSink : IOutputSink
{
public static ILogger Logger = NullLogger.Instance;
private readonly string _outputDirectory;
/// <summary>
/// Creates an instance of SimpleOutputFormatter.
/// Creates an instance of DirectoryOutputSink.
/// </summary>
/// <param name="outputDirectory">The output directory.</param>
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
}
/// <summary>
/// Creates an instance of OriginalFilenameFileOutputPathFormatter.
/// Creates an instance of DirectoryOutputSink.
/// </summary>
/// <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)
{
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");
}