Implement TestCompressor.cs
This commit is contained in:
parent
f3b64e28ed
commit
c6f1ec0a37
3 changed files with 60 additions and 6 deletions
56
ImageCore.Tests/TestCompressor.cs
Normal file
56
ImageCore.Tests/TestCompressor.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,5 @@
|
||||||
<Assembly Path="C:\Users\nutiu\.nuget\packages\magick.net.core\8.6.1\lib\netstandard21\Magick.NET.Core.dll" />
|
<Assembly Path="C:\Users\nutiu\.nuget\packages\magick.net.core\8.6.1\lib\netstandard21\Magick.NET.Core.dll" />
|
||||||
</AssemblyExplorer></s:String>
|
</AssemblyExplorer></s:String>
|
||||||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=761234b5_002D46ba_002D4312_002Dab60_002Dd15d5d83a61a/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="TestGetFilenamesFromPath" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
|
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=761234b5_002D46ba_002D4312_002Dab60_002Dd15d5d83a61a/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="TestGetFilenamesFromPath" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
|
||||||
<TestAncestor>
|
<Project Location="C:\Users\nutiu\RiderProjects\ImgMetadataRemover\ImageCore.Tests" Presentation="&lt;ImageCore.Tests&gt;" />
|
||||||
<TestId>xUnit::8EB81515-E62C-4408-84E0-6C27E0293902::net5.0::ImageCore.Tests.TestLocalSystemFilesRetriever.TestGetFilenamesFromPath</TestId>
|
|
||||||
</TestAncestor>
|
|
||||||
</SessionState></s:String></wpf:ResourceDictionary>
|
</SessionState></s:String></wpf:ResourceDictionary>
|
Loading…
Reference in a new issue