Implement TestCompressor.cs

This commit is contained in:
Denis-Cosmin Nutiu 2022-01-25 22:19:56 +02:00
parent f3b64e28ed
commit c6f1ec0a37
3 changed files with 60 additions and 6 deletions

View file

@ -0,0 +1,56 @@
using System;
using System.IO;
using System.Security.Cryptography;
using Image;
using Xunit;
namespace ImageCore.Tests
{
public class TestLosslessCompressor
{
private readonly string _testsProjectDirectory;
public TestLosslessCompressor()
{
_testsProjectDirectory = Environment.GetEnvironmentVariable("IMAGE_CORE_TESTS");
}
[Fact]
public void TestLosslessCompressor_Compress()
{
ICompressor compressor = new LosslessCompressor();
var sourceFileName = Path.Join(_testsProjectDirectory, "test_pictures/IMG_0138.HEIC");
var destinationFileName = Path.GetTempFileName();
File.Copy(sourceFileName, destinationFileName, true);
compressor.Compress(destinationFileName);
var originalFile = File.Open(sourceFileName, FileMode.Open);
var compressedFile = File.Open(destinationFileName, FileMode.Open);
Assert.True(compressedFile.Length <= originalFile.Length);
originalFile.Close();
compressedFile.Close();
File.Delete(destinationFileName);
}
[Fact]
public void TestNullCompressor_Compress()
{
ICompressor compressor = new NullCompressor();
var sourceFileName = Path.Join(_testsProjectDirectory, "test_pictures/IMG_0138.HEIC");
var destinationFileName = Path.GetTempFileName();
File.Copy(sourceFileName, destinationFileName, true);
compressor.Compress(destinationFileName);
var originalFile = File.Open(sourceFileName, FileMode.Open);
var compressedFile = File.Open(destinationFileName, FileMode.Open);
Assert.True(compressedFile.Length == originalFile.Length);
originalFile.Close();
compressedFile.Close();
File.Delete(destinationFileName);
}
}
}

View file

@ -4,7 +4,5 @@
&lt;Assembly Path="C:\Users\nutiu\.nuget\packages\magick.net.core\8.6.1\lib\netstandard21\Magick.NET.Core.dll" /&gt;&#xD; &lt;Assembly Path="C:\Users\nutiu\.nuget\packages\magick.net.core\8.6.1\lib\netstandard21\Magick.NET.Core.dll" /&gt;&#xD;
&lt;/AssemblyExplorer&gt;</s:String> &lt;/AssemblyExplorer&gt;</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=761234b5_002D46ba_002D4312_002Dab60_002Dd15d5d83a61a/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="TestGetFilenamesFromPath" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD; <s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=761234b5_002D46ba_002D4312_002Dab60_002Dd15d5d83a61a/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="TestGetFilenamesFromPath" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
&lt;TestAncestor&gt;&#xD; &lt;Project Location="C:\Users\nutiu\RiderProjects\ImgMetadataRemover\ImageCore.Tests" Presentation="&amp;lt;ImageCore.Tests&amp;gt;" /&gt;&#xD;
&lt;TestId&gt;xUnit::8EB81515-E62C-4408-84E0-6C27E0293902::net5.0::ImageCore.Tests.TestLocalSystemFilesRetriever.TestGetFilenamesFromPath&lt;/TestId&gt;&#xD;
&lt;/TestAncestor&gt;&#xD;
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary> &lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>