ImgMetadataRemover/ImageCore.Tests/TestCompressor.cs

56 lines
1.9 KiB
C#
Raw Normal View History

2022-01-25 20:19:56 +00:00
using System;
using System.IO;
using Image;
2022-01-25 20:57:22 +00:00
using Image.Compressor;
2022-01-25 20:19:56 +00:00
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);
}
}
}