Reformat code

This commit is contained in:
Denis-Cosmin Nutiu 2022-04-02 17:33:48 +03:00
parent 6a9a316424
commit 2131edb4c8
5 changed files with 27 additions and 4 deletions

View file

@ -14,7 +14,10 @@ public class TestLocalFileBrowser
public TestLocalFileBrowser() public TestLocalFileBrowser()
{ {
_testsProjectDirectory = Environment.GetEnvironmentVariable("IMAGE_CORE_TESTS"); _testsProjectDirectory = Environment.GetEnvironmentVariable("IMAGE_CORE_TESTS");
if (_testsProjectDirectory == null) throw new Exception("Environment variable IMAGE_CORE_TESTS is not set!"); if (_testsProjectDirectory == null)
{
throw new Exception("Environment variable IMAGE_CORE_TESTS is not set!");
}
} }
[Fact] [Fact]
@ -39,6 +42,8 @@ public class TestLocalFileBrowser
Assert.NotEmpty(filePathsList); Assert.NotEmpty(filePathsList);
for (var i = 0; i < filePathsList.Count; i++) for (var i = 0; i < filePathsList.Count; i++)
{
Assert.Equal(expectedFileNames[i], Path.GetFileName(filePathsList[i])); Assert.Equal(expectedFileNames[i], Path.GetFileName(filePathsList[i]));
}
} }
} }

View file

@ -14,7 +14,10 @@ public class TestSimpleOutputSink
public TestSimpleOutputSink() public TestSimpleOutputSink()
{ {
_testsProjectDirectory = Environment.GetEnvironmentVariable("IMAGE_CORE_TESTS"); _testsProjectDirectory = Environment.GetEnvironmentVariable("IMAGE_CORE_TESTS");
if (_testsProjectDirectory == null) throw new Exception("Environment variable IMAGE_CORE_TESTS is not set!"); if (_testsProjectDirectory == null)
{
throw new Exception("Environment variable IMAGE_CORE_TESTS is not set!");
}
} }
[Theory] [Theory]

View file

@ -14,7 +14,11 @@ namespace ConsoleInterface
/// <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)
{ {
if (Directory.Exists(directoryPath)) return; if (Directory.Exists(directoryPath))
{
return;
}
Logger.LogWarning("Output directory does not exist. Creating."); Logger.LogWarning("Output directory does not exist. Creating.");
Directory.CreateDirectory(directoryPath); Directory.CreateDirectory(directoryPath);
} }

View file

@ -24,9 +24,14 @@ namespace ConsoleInterface
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;
} }
@ -54,7 +59,9 @@ namespace ConsoleInterface
{ {
Logger.LogDebug($"KeepFilenameFormatter - {_outputDirectory} - {initialFilePath}"); Logger.LogDebug($"KeepFilenameFormatter - {_outputDirectory} - {initialFilePath}");
if (string.IsNullOrEmpty(initialFilePath)) if (string.IsNullOrEmpty(initialFilePath))
{
throw new ArgumentException("The output file path cannot be null or empty!"); throw new ArgumentException("The output file path cannot be null or empty!");
}
var fileName = Path.GetFileName(initialFilePath).Split('.')[0]; var fileName = Path.GetFileName(initialFilePath).Split('.')[0];
var path = Path.Combine(_outputDirectory, $"{fileName}.jpg"); var path = Path.Combine(_outputDirectory, $"{fileName}.jpg");

View file

@ -51,7 +51,11 @@ namespace ConsoleInterface
$"Cleaning {filePath}, compression {_options.EnableCompression}, outputFormatter {nameof(_options.OutputSink)}."); $"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);
IMetadataRemover metadataRemover = new ExifRemoverAndCompressor(imageMagick, compressor); IMetadataRemover metadataRemover = new ExifRemoverAndCompressor(imageMagick, compressor);
return outputSink.Save(metadataRemover); return outputSink.Save(metadataRemover);