diff --git a/src/FrameworkTests/AspNet/Properties/AssemblyInfo.cs b/src/FrameworkTests/AspNet/Properties/AssemblyInfo.cs index 08521cd1..3fdca9a7 100644 --- a/src/FrameworkTests/AspNet/Properties/AssemblyInfo.cs +++ b/src/FrameworkTests/AspNet/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // Allgemeine Informationen über eine Assembly werden über die folgenden diff --git a/src/FrameworkTests/MauiApp/Platforms/Android/MainActivity.cs b/src/FrameworkTests/MauiApp/Platforms/Android/MainActivity.cs index b6eea2e1..2e4d8cf0 100644 --- a/src/FrameworkTests/MauiApp/Platforms/Android/MainActivity.cs +++ b/src/FrameworkTests/MauiApp/Platforms/Android/MainActivity.cs @@ -1,6 +1,5 @@ using Android.App; using Android.Content.PM; -using Android.OS; namespace PDFtoImage.FrameworkTests.MauiApp { diff --git a/src/FrameworkTests/MauiApp/Platforms/Windows/App.xaml.cs b/src/FrameworkTests/MauiApp/Platforms/Windows/App.xaml.cs index 050d3f27..9577dc3b 100644 --- a/src/FrameworkTests/MauiApp/Platforms/Windows/App.xaml.cs +++ b/src/FrameworkTests/MauiApp/Platforms/Windows/App.xaml.cs @@ -1,6 +1,4 @@ -using Microsoft.UI.Xaml; - -// To learn more about WinUI, the WinUI project structure, +// To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. namespace PDFtoImage.FrameworkTests.MauiApp.WinUI diff --git a/src/FrameworkTests/Uwp/Properties/AssemblyInfo.cs b/src/FrameworkTests/Uwp/Properties/AssemblyInfo.cs index b815ec83..b0ea5c12 100644 --- a/src/FrameworkTests/Uwp/Properties/AssemblyInfo.cs +++ b/src/FrameworkTests/Uwp/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // Allgemeine Informationen über eine Assembly werden über die folgenden diff --git a/src/Tests/ApiTests.cs b/src/Tests/ApiTests.cs index 023ef6ad..7556a960 100644 --- a/src/Tests/ApiTests.cs +++ b/src/Tests/ApiTests.cs @@ -9,134 +9,134 @@ namespace Tests { - [TestClass] - public class ApiTests : TestBase - { - [TestMethod] - public void SaveWebpStringNullException() - { - Assert.ThrowsException(() => SaveWebp((string)null!, (string)null!)); - } - - [TestMethod] - public void SaveWebpStreamNullException() - { - Assert.ThrowsException(() => SaveWebp((Stream)null!, (string)null!)); - } - - [TestMethod] - public void SavePngStringNullException() - { - Assert.ThrowsException(() => SavePng((string)null!, (string)null!)); - } - - [TestMethod] - public void SavePngStreamNullException() - { - Assert.ThrowsException(() => SavePng((Stream)null!, (string)null!)); - } - - [TestMethod] - public void SaveJpegStringNullException() - { - Assert.ThrowsException(() => SaveJpeg((string)null!, (string)null!)); - } - - [TestMethod] - public void SaveJpegStreamNullException() - { - Assert.ThrowsException(() => SaveJpeg((Stream)null!, (string)null!)); - } - - [TestMethod] - public void ToImagePdfStringNullException() - { - Assert.ThrowsException(() => ToImage((string)null!)); - } - - [TestMethod] - public void ToImagePdfArrayNullException() - { - Assert.ThrowsException(() => ToImage((byte[])null!)); - } - - [TestMethod] - public void ToImagePdfStreamNullException() - { - Assert.ThrowsException(() => ToImage((Stream)null!)); - } - - [TestMethod] - public void GetPageCountPdfStringNullException() - { - Assert.ThrowsException(() => GetPageCount((string)null!)); - } - - [TestMethod] - public void GetPageCountPdfArrayNullException() - { - Assert.ThrowsException(() => GetPageCount((byte[])null!)); - } - - [TestMethod] - public void GetPageCountPdfStreamNullException() - { - Assert.ThrowsException(() => GetPageCount((Stream)null!)); - } - - [TestMethod] - public void GetPageSizePdfStringNullException() - { - Assert.ThrowsException(() => GetPageSize((string)null!, 0)); - } - - [TestMethod] - public void GetPageSizePdfArrayNullException() - { - Assert.ThrowsException(() => GetPageSize((byte[])null!, 0)); - } - - [TestMethod] - public void GetPageSizePdfStreamNullException() - { - Assert.ThrowsException(() => GetPageSize((Stream)null!, page:0)); - } - - [TestMethod] - public void GetPageSizesPdfStringNullException() - { - Assert.ThrowsException(() => GetPageSizes((string)null!)); - } - - [TestMethod] - public void GetPageSizesPdfArrayNullException() - { - Assert.ThrowsException(() => GetPageSizes((byte[])null!)); - } - - [TestMethod] - public void GetPageSizesPdfStreamNullException() - { - Assert.ThrowsException(() => GetPageSizes((Stream)null!)); - } - - [TestMethod] - public void ToImagesPdfStringNullException() - { - Assert.ThrowsException(() => ToImages((string)null!).ToList()); - } - - [TestMethod] - public void ToImagesPdfArrayNullException() - { - Assert.ThrowsException(() => ToImages((byte[])null!).ToList()); - } - - [TestMethod] - public void ToImagesPdfStreamNullException() - { - Assert.ThrowsException(() => ToImages((Stream)null!).ToList()); - } + [TestClass] + public class ApiTests : TestBase + { + [TestMethod] + public void SaveWebpStringNullException() + { + Assert.ThrowsException(() => SaveWebp((string)null!, (string)null!)); + } + + [TestMethod] + public void SaveWebpStreamNullException() + { + Assert.ThrowsException(() => SaveWebp((Stream)null!, (string)null!)); + } + + [TestMethod] + public void SavePngStringNullException() + { + Assert.ThrowsException(() => SavePng((string)null!, (string)null!)); + } + + [TestMethod] + public void SavePngStreamNullException() + { + Assert.ThrowsException(() => SavePng((Stream)null!, (string)null!)); + } + + [TestMethod] + public void SaveJpegStringNullException() + { + Assert.ThrowsException(() => SaveJpeg((string)null!, (string)null!)); + } + + [TestMethod] + public void SaveJpegStreamNullException() + { + Assert.ThrowsException(() => SaveJpeg((Stream)null!, (string)null!)); + } + + [TestMethod] + public void ToImagePdfStringNullException() + { + Assert.ThrowsException(() => ToImage((string)null!)); + } + + [TestMethod] + public void ToImagePdfArrayNullException() + { + Assert.ThrowsException(() => ToImage((byte[])null!)); + } + + [TestMethod] + public void ToImagePdfStreamNullException() + { + Assert.ThrowsException(() => ToImage((Stream)null!)); + } + + [TestMethod] + public void GetPageCountPdfStringNullException() + { + Assert.ThrowsException(() => GetPageCount((string)null!)); + } + + [TestMethod] + public void GetPageCountPdfArrayNullException() + { + Assert.ThrowsException(() => GetPageCount((byte[])null!)); + } + + [TestMethod] + public void GetPageCountPdfStreamNullException() + { + Assert.ThrowsException(() => GetPageCount((Stream)null!)); + } + + [TestMethod] + public void GetPageSizePdfStringNullException() + { + Assert.ThrowsException(() => GetPageSize((string)null!, 0)); + } + + [TestMethod] + public void GetPageSizePdfArrayNullException() + { + Assert.ThrowsException(() => GetPageSize((byte[])null!, 0)); + } + + [TestMethod] + public void GetPageSizePdfStreamNullException() + { + Assert.ThrowsException(() => GetPageSize((Stream)null!, page: 0)); + } + + [TestMethod] + public void GetPageSizesPdfStringNullException() + { + Assert.ThrowsException(() => GetPageSizes((string)null!)); + } + + [TestMethod] + public void GetPageSizesPdfArrayNullException() + { + Assert.ThrowsException(() => GetPageSizes((byte[])null!)); + } + + [TestMethod] + public void GetPageSizesPdfStreamNullException() + { + Assert.ThrowsException(() => GetPageSizes((Stream)null!)); + } + + [TestMethod] + public void ToImagesPdfStringNullException() + { + Assert.ThrowsException(() => ToImages((string)null!).ToList()); + } + + [TestMethod] + public void ToImagesPdfArrayNullException() + { + Assert.ThrowsException(() => ToImages((byte[])null!).ToList()); + } + + [TestMethod] + public void ToImagesPdfStreamNullException() + { + Assert.ThrowsException(() => ToImages((Stream)null!).ToList()); + } #if NET6_0_OR_GREATER [TestMethod] @@ -173,74 +173,74 @@ await Assert.ThrowsExceptionAsync(async () => } #endif - [TestMethod] - public void ToImageStreamLeaveOpenDefault() - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - Assert.IsTrue(inputStream.CanRead); - - ToImage(inputStream); - Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling the default overload."); - } - - [TestMethod] - public void ToImageStreamLeaveOpenFalse() - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - Assert.IsTrue(inputStream.CanRead); - - ToImage(inputStream, false); - Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling leaveOpen with false."); - } - - [TestMethod] - public void ToImageStreamLeaveOpenTrue() - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - Assert.IsTrue(inputStream.CanRead); - - ToImage(inputStream, true); - Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); - } - - [TestMethod] - public void ToImagesStreamLeaveOpenDefault() - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - Assert.IsTrue(inputStream.CanRead); - - var result = ToImages(inputStream); - Assert.IsTrue(inputStream.CanRead, "The stream should be open as long as the iterator is not used yet."); - - foreach (var _ in result) ; - Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling the default overload."); - } - - [TestMethod] - public void ToImagesStreamLeaveOpenFalse() - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - Assert.IsTrue(inputStream.CanRead); - - var result = ToImages(inputStream, false); - Assert.IsTrue(inputStream.CanRead, "The stream should be open as long as the iterator is not used yet."); - - foreach (var _ in result) ; - Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling leaveOpen with false."); - } - - [TestMethod] - public void ToImagesStreamLeaveOpenTrue() - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - Assert.IsTrue(inputStream.CanRead); - - var result = ToImages(inputStream, true); - Assert.IsTrue(inputStream.CanRead, "The stream should be open as long as the iterator is not used yet."); - - foreach (var _ in result) ; - Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); - } + [TestMethod] + public void ToImageStreamLeaveOpenDefault() + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + Assert.IsTrue(inputStream.CanRead); + + ToImage(inputStream); + Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling the default overload."); + } + + [TestMethod] + public void ToImageStreamLeaveOpenFalse() + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + Assert.IsTrue(inputStream.CanRead); + + ToImage(inputStream, false); + Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling leaveOpen with false."); + } + + [TestMethod] + public void ToImageStreamLeaveOpenTrue() + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + Assert.IsTrue(inputStream.CanRead); + + ToImage(inputStream, true); + Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); + } + + [TestMethod] + public void ToImagesStreamLeaveOpenDefault() + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + Assert.IsTrue(inputStream.CanRead); + + var result = ToImages(inputStream); + Assert.IsTrue(inputStream.CanRead, "The stream should be open as long as the iterator is not used yet."); + + foreach (var _ in result) ; + Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling the default overload."); + } + + [TestMethod] + public void ToImagesStreamLeaveOpenFalse() + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + Assert.IsTrue(inputStream.CanRead); + + var result = ToImages(inputStream, false); + Assert.IsTrue(inputStream.CanRead, "The stream should be open as long as the iterator is not used yet."); + + foreach (var _ in result) ; + Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling leaveOpen with false."); + } + + [TestMethod] + public void ToImagesStreamLeaveOpenTrue() + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + Assert.IsTrue(inputStream.CanRead); + + var result = ToImages(inputStream, true); + Assert.IsTrue(inputStream.CanRead, "The stream should be open as long as the iterator is not used yet."); + + foreach (var _ in result) ; + Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); + } #if NET6_0_OR_GREATER [TestMethod] @@ -283,121 +283,121 @@ public async Task ToImagesAsyncStreamLeaveOpenTrue() } #endif - [TestMethod] - public void GetPageCountStreamLeaveOpenDefault() - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - Assert.IsTrue(inputStream.CanRead); - - GetPageCount(inputStream); - Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling the default overload."); - } - - [TestMethod] - public void GetPageCountStreamLeaveOpenFalse() - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - Assert.IsTrue(inputStream.CanRead); - - GetPageCount(inputStream, false); - Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling leaveOpen with false."); - } - - [TestMethod] - public void GetPageCountStreamLeaveOpenTrue() - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - Assert.IsTrue(inputStream.CanRead); - - GetPageCount(inputStream, true); - Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); - } - - [TestMethod] - public void GetPageSizeStreamLeaveOpenDefault() - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - Assert.IsTrue(inputStream.CanRead); - - GetPageSize(inputStream, page: 0); - Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling the default overload."); - } - - [TestMethod] - public void GetPageSizeStreamLeaveOpenFalse() - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - Assert.IsTrue(inputStream.CanRead); - - GetPageSize(inputStream, false, 0); - Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling leaveOpen with false."); - } - - [TestMethod] - public void GetPageSizeStreamLeaveOpenTrue() - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - Assert.IsTrue(inputStream.CanRead); - - GetPageSize(inputStream, true, 0); - Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); - } - - [TestMethod] - public void GetPageSizesStreamLeaveOpenDefault() - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - Assert.IsTrue(inputStream.CanRead); - - GetPageSizes(inputStream); - Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling the default overload."); - } - - [TestMethod] - public void GetPageSizesStreamLeaveOpenFalse() - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - Assert.IsTrue(inputStream.CanRead); - - GetPageSizes(inputStream, false); - Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling leaveOpen with false."); - } - - [TestMethod] - public void GetPageSizesStreamLeaveOpenTrue() - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - Assert.IsTrue(inputStream.CanRead); - - GetPageSizes(inputStream, true); - Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); - } - - [TestMethod] - public void StreamMultipleCallsLeaveOpen() - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - Assert.IsTrue(inputStream.CanRead); - - GetPageCount(inputStream, true); - Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); - - GetPageSizes(inputStream, true); - Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); - - var image1 = ToImage(inputStream, true); - Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); - - var image2 = ToImage(inputStream, true); - Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); - - Assert.IsTrue(image1.ByteCount > 0, "The rendered image should have content."); - Assert.AreEqual(image1.ByteCount, image2.ByteCount, "Both images should be equal (in byte size)."); - - GetPageSizes(inputStream, false); - Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling leaveOpen with false."); - - Assert.ThrowsException(() => GetPageCount(inputStream, false), "The stream should be closed and throw an exception."); - } - } + [TestMethod] + public void GetPageCountStreamLeaveOpenDefault() + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + Assert.IsTrue(inputStream.CanRead); + + GetPageCount(inputStream); + Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling the default overload."); + } + + [TestMethod] + public void GetPageCountStreamLeaveOpenFalse() + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + Assert.IsTrue(inputStream.CanRead); + + GetPageCount(inputStream, false); + Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling leaveOpen with false."); + } + + [TestMethod] + public void GetPageCountStreamLeaveOpenTrue() + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + Assert.IsTrue(inputStream.CanRead); + + GetPageCount(inputStream, true); + Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); + } + + [TestMethod] + public void GetPageSizeStreamLeaveOpenDefault() + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + Assert.IsTrue(inputStream.CanRead); + + GetPageSize(inputStream, page: 0); + Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling the default overload."); + } + + [TestMethod] + public void GetPageSizeStreamLeaveOpenFalse() + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + Assert.IsTrue(inputStream.CanRead); + + GetPageSize(inputStream, false, 0); + Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling leaveOpen with false."); + } + + [TestMethod] + public void GetPageSizeStreamLeaveOpenTrue() + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + Assert.IsTrue(inputStream.CanRead); + + GetPageSize(inputStream, true, 0); + Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); + } + + [TestMethod] + public void GetPageSizesStreamLeaveOpenDefault() + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + Assert.IsTrue(inputStream.CanRead); + + GetPageSizes(inputStream); + Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling the default overload."); + } + + [TestMethod] + public void GetPageSizesStreamLeaveOpenFalse() + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + Assert.IsTrue(inputStream.CanRead); + + GetPageSizes(inputStream, false); + Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling leaveOpen with false."); + } + + [TestMethod] + public void GetPageSizesStreamLeaveOpenTrue() + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + Assert.IsTrue(inputStream.CanRead); + + GetPageSizes(inputStream, true); + Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); + } + + [TestMethod] + public void StreamMultipleCallsLeaveOpen() + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + Assert.IsTrue(inputStream.CanRead); + + GetPageCount(inputStream, true); + Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); + + GetPageSizes(inputStream, true); + Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); + + var image1 = ToImage(inputStream, true); + Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); + + var image2 = ToImage(inputStream, true); + Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); + + Assert.IsTrue(image1.ByteCount > 0, "The rendered image should have content."); + Assert.AreEqual(image1.ByteCount, image2.ByteCount, "Both images should be equal (in byte size)."); + + GetPageSizes(inputStream, false); + Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling leaveOpen with false."); + + Assert.ThrowsException(() => GetPageCount(inputStream, false), "The stream should be closed and throw an exception."); + } + } } \ No newline at end of file diff --git a/src/Tests/AspectRatioTests.cs b/src/Tests/AspectRatioTests.cs index ea01831d..5dc6ce38 100644 --- a/src/Tests/AspectRatioTests.cs +++ b/src/Tests/AspectRatioTests.cs @@ -6,408 +6,408 @@ namespace Tests { - [TestClass] - public class AspectRatioTests : TestBase - { - [TestMethod] - [DataRow("hundesteuer-anmeldung.pdf")] - [DataRow("hundesteuer-anmeldung.pdf", 100, null, null)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, null, null)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, null, null)] - [DataRow("hundesteuer-anmeldung.pdf", null, 100, null)] - [DataRow("hundesteuer-anmeldung.pdf", null, 1000, null)] - [DataRow("hundesteuer-anmeldung.pdf", null, 2000, null)] - [DataRow("hundesteuer-anmeldung.pdf", 100, 100, null)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, null)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, null)] - [DataRow("hundesteuer-anmeldung.pdf", null, null, 96)] - [DataRow("hundesteuer-anmeldung.pdf", null, null, 300)] - [DataRow("hundesteuer-anmeldung.pdf", null, null, 600)] - [DataRow("hundesteuer-anmeldung.pdf", 100, null, 96)] - [DataRow("hundesteuer-anmeldung.pdf", 100, null, 300)] - [DataRow("hundesteuer-anmeldung.pdf", 100, null, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, null, 96)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, null, 300)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, null, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, null, 96)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, null, 300)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, null, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", null, 100, 96)] - [DataRow("hundesteuer-anmeldung.pdf", null, 100, 300)] - [DataRow("hundesteuer-anmeldung.pdf", null, 100, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", null, 1000, 96)] - [DataRow("hundesteuer-anmeldung.pdf", null, 1000, 300)] - [DataRow("hundesteuer-anmeldung.pdf", null, 1000, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", null, 2000, 96)] - [DataRow("hundesteuer-anmeldung.pdf", null, 2000, 300)] - [DataRow("hundesteuer-anmeldung.pdf", null, 2000, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", 100, 100, 96)] - [DataRow("hundesteuer-anmeldung.pdf", 100, 100, 300)] - [DataRow("hundesteuer-anmeldung.pdf", 100, 100, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, 96)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, 300)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, 96)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, 300)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, 1200)] + [TestClass] + public class AspectRatioTests : TestBase + { + [TestMethod] + [DataRow("hundesteuer-anmeldung.pdf")] + [DataRow("hundesteuer-anmeldung.pdf", 100, null, null)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, null, null)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, null, null)] + [DataRow("hundesteuer-anmeldung.pdf", null, 100, null)] + [DataRow("hundesteuer-anmeldung.pdf", null, 1000, null)] + [DataRow("hundesteuer-anmeldung.pdf", null, 2000, null)] + [DataRow("hundesteuer-anmeldung.pdf", 100, 100, null)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, null)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, null)] + [DataRow("hundesteuer-anmeldung.pdf", null, null, 96)] + [DataRow("hundesteuer-anmeldung.pdf", null, null, 300)] + [DataRow("hundesteuer-anmeldung.pdf", null, null, 600)] + [DataRow("hundesteuer-anmeldung.pdf", 100, null, 96)] + [DataRow("hundesteuer-anmeldung.pdf", 100, null, 300)] + [DataRow("hundesteuer-anmeldung.pdf", 100, null, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, null, 96)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, null, 300)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, null, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, null, 96)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, null, 300)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, null, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", null, 100, 96)] + [DataRow("hundesteuer-anmeldung.pdf", null, 100, 300)] + [DataRow("hundesteuer-anmeldung.pdf", null, 100, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", null, 1000, 96)] + [DataRow("hundesteuer-anmeldung.pdf", null, 1000, 300)] + [DataRow("hundesteuer-anmeldung.pdf", null, 1000, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", null, 2000, 96)] + [DataRow("hundesteuer-anmeldung.pdf", null, 2000, 300)] + [DataRow("hundesteuer-anmeldung.pdf", null, 2000, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", 100, 100, 96)] + [DataRow("hundesteuer-anmeldung.pdf", 100, 100, 300)] + [DataRow("hundesteuer-anmeldung.pdf", 100, 100, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, 96)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, 300)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, 96)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, 300)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, 1200)] - [DataRow("SocialPreview.pdf")] - [DataRow("SocialPreview.pdf", 100, null, null)] - [DataRow("SocialPreview.pdf", 1000, null, null)] - [DataRow("SocialPreview.pdf", 2000, null, null)] - [DataRow("SocialPreview.pdf", null, 100, null)] - [DataRow("SocialPreview.pdf", null, 1000, null)] - [DataRow("SocialPreview.pdf", null, 2000, null)] - [DataRow("SocialPreview.pdf", 100, 100, null)] - [DataRow("SocialPreview.pdf", 1000, 1000, null)] - [DataRow("SocialPreview.pdf", 2000, 2000, null)] - [DataRow("SocialPreview.pdf", null, null, 96)] - [DataRow("SocialPreview.pdf", null, null, 300)] - [DataRow("SocialPreview.pdf", null, null, 600)] - [DataRow("SocialPreview.pdf", 100, null, 96)] - [DataRow("SocialPreview.pdf", 100, null, 300)] - [DataRow("SocialPreview.pdf", 100, null, 1200)] - [DataRow("SocialPreview.pdf", 1000, null, 96)] - [DataRow("SocialPreview.pdf", 1000, null, 300)] - [DataRow("SocialPreview.pdf", 1000, null, 1200)] - [DataRow("SocialPreview.pdf", 2000, null, 96)] - [DataRow("SocialPreview.pdf", 2000, null, 300)] - [DataRow("SocialPreview.pdf", 2000, null, 1200)] - [DataRow("SocialPreview.pdf", null, 100, 96)] - [DataRow("SocialPreview.pdf", null, 100, 300)] - [DataRow("SocialPreview.pdf", null, 100, 1200)] - [DataRow("SocialPreview.pdf", null, 1000, 96)] - [DataRow("SocialPreview.pdf", null, 1000, 300)] - [DataRow("SocialPreview.pdf", null, 1000, 1200)] - [DataRow("SocialPreview.pdf", null, 2000, 96)] - [DataRow("SocialPreview.pdf", null, 2000, 300)] - [DataRow("SocialPreview.pdf", null, 2000, 1200)] - [DataRow("SocialPreview.pdf", 100, 100, 96)] - [DataRow("SocialPreview.pdf", 100, 100, 300)] - [DataRow("SocialPreview.pdf", 100, 100, 1200)] - [DataRow("SocialPreview.pdf", 1000, 1000, 96)] - [DataRow("SocialPreview.pdf", 1000, 1000, 300)] - [DataRow("SocialPreview.pdf", 1000, 1000, 1200)] - [DataRow("SocialPreview.pdf", 2000, 2000, 96)] - [DataRow("SocialPreview.pdf", 2000, 2000, 300)] - [DataRow("SocialPreview.pdf", 2000, 2000, 1200)] + [DataRow("SocialPreview.pdf")] + [DataRow("SocialPreview.pdf", 100, null, null)] + [DataRow("SocialPreview.pdf", 1000, null, null)] + [DataRow("SocialPreview.pdf", 2000, null, null)] + [DataRow("SocialPreview.pdf", null, 100, null)] + [DataRow("SocialPreview.pdf", null, 1000, null)] + [DataRow("SocialPreview.pdf", null, 2000, null)] + [DataRow("SocialPreview.pdf", 100, 100, null)] + [DataRow("SocialPreview.pdf", 1000, 1000, null)] + [DataRow("SocialPreview.pdf", 2000, 2000, null)] + [DataRow("SocialPreview.pdf", null, null, 96)] + [DataRow("SocialPreview.pdf", null, null, 300)] + [DataRow("SocialPreview.pdf", null, null, 600)] + [DataRow("SocialPreview.pdf", 100, null, 96)] + [DataRow("SocialPreview.pdf", 100, null, 300)] + [DataRow("SocialPreview.pdf", 100, null, 1200)] + [DataRow("SocialPreview.pdf", 1000, null, 96)] + [DataRow("SocialPreview.pdf", 1000, null, 300)] + [DataRow("SocialPreview.pdf", 1000, null, 1200)] + [DataRow("SocialPreview.pdf", 2000, null, 96)] + [DataRow("SocialPreview.pdf", 2000, null, 300)] + [DataRow("SocialPreview.pdf", 2000, null, 1200)] + [DataRow("SocialPreview.pdf", null, 100, 96)] + [DataRow("SocialPreview.pdf", null, 100, 300)] + [DataRow("SocialPreview.pdf", null, 100, 1200)] + [DataRow("SocialPreview.pdf", null, 1000, 96)] + [DataRow("SocialPreview.pdf", null, 1000, 300)] + [DataRow("SocialPreview.pdf", null, 1000, 1200)] + [DataRow("SocialPreview.pdf", null, 2000, 96)] + [DataRow("SocialPreview.pdf", null, 2000, 300)] + [DataRow("SocialPreview.pdf", null, 2000, 1200)] + [DataRow("SocialPreview.pdf", 100, 100, 96)] + [DataRow("SocialPreview.pdf", 100, 100, 300)] + [DataRow("SocialPreview.pdf", 100, 100, 1200)] + [DataRow("SocialPreview.pdf", 1000, 1000, 96)] + [DataRow("SocialPreview.pdf", 1000, 1000, 300)] + [DataRow("SocialPreview.pdf", 1000, 1000, 1200)] + [DataRow("SocialPreview.pdf", 2000, 2000, 96)] + [DataRow("SocialPreview.pdf", 2000, 2000, 300)] + [DataRow("SocialPreview.pdf", 2000, 2000, 1200)] - [DataRow("Wikimedia_Commons_web.pdf")] - [DataRow("Wikimedia_Commons_web.pdf", 100, null, null)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, null, null)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, null, null)] - [DataRow("Wikimedia_Commons_web.pdf", null, 100, null)] - [DataRow("Wikimedia_Commons_web.pdf", null, 1000, null)] - [DataRow("Wikimedia_Commons_web.pdf", null, 2000, null)] - [DataRow("Wikimedia_Commons_web.pdf", 100, 100, null)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, null)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, null)] - [DataRow("Wikimedia_Commons_web.pdf", null, null, 96)] - [DataRow("Wikimedia_Commons_web.pdf", null, null, 300)] - [DataRow("Wikimedia_Commons_web.pdf", null, null, 600)] - [DataRow("Wikimedia_Commons_web.pdf", 100, null, 96)] - [DataRow("Wikimedia_Commons_web.pdf", 100, null, 300)] - [DataRow("Wikimedia_Commons_web.pdf", 100, null, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, null, 96)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, null, 300)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, null, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, null, 96)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, null, 300)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, null, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", null, 100, 96)] - [DataRow("Wikimedia_Commons_web.pdf", null, 100, 300)] - [DataRow("Wikimedia_Commons_web.pdf", null, 100, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", null, 1000, 96)] - [DataRow("Wikimedia_Commons_web.pdf", null, 1000, 300)] - [DataRow("Wikimedia_Commons_web.pdf", null, 1000, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", null, 2000, 96)] - [DataRow("Wikimedia_Commons_web.pdf", null, 2000, 300)] - [DataRow("Wikimedia_Commons_web.pdf", null, 2000, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", 100, 100, 96)] - [DataRow("Wikimedia_Commons_web.pdf", 100, 100, 300)] - [DataRow("Wikimedia_Commons_web.pdf", 100, 100, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, 96)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, 300)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, 96)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, 300)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, 1200)] - public void WithoutAspectRatio(string fileName, int? width = null, int? height = null, int? dpi = null) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "AspectRatio", GetExpectedFilename(fileName, "jpg", width, height, dpi, false)); + [DataRow("Wikimedia_Commons_web.pdf")] + [DataRow("Wikimedia_Commons_web.pdf", 100, null, null)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, null, null)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, null, null)] + [DataRow("Wikimedia_Commons_web.pdf", null, 100, null)] + [DataRow("Wikimedia_Commons_web.pdf", null, 1000, null)] + [DataRow("Wikimedia_Commons_web.pdf", null, 2000, null)] + [DataRow("Wikimedia_Commons_web.pdf", 100, 100, null)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, null)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, null)] + [DataRow("Wikimedia_Commons_web.pdf", null, null, 96)] + [DataRow("Wikimedia_Commons_web.pdf", null, null, 300)] + [DataRow("Wikimedia_Commons_web.pdf", null, null, 600)] + [DataRow("Wikimedia_Commons_web.pdf", 100, null, 96)] + [DataRow("Wikimedia_Commons_web.pdf", 100, null, 300)] + [DataRow("Wikimedia_Commons_web.pdf", 100, null, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, null, 96)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, null, 300)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, null, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, null, 96)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, null, 300)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, null, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", null, 100, 96)] + [DataRow("Wikimedia_Commons_web.pdf", null, 100, 300)] + [DataRow("Wikimedia_Commons_web.pdf", null, 100, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", null, 1000, 96)] + [DataRow("Wikimedia_Commons_web.pdf", null, 1000, 300)] + [DataRow("Wikimedia_Commons_web.pdf", null, 1000, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", null, 2000, 96)] + [DataRow("Wikimedia_Commons_web.pdf", null, 2000, 300)] + [DataRow("Wikimedia_Commons_web.pdf", null, 2000, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", 100, 100, 96)] + [DataRow("Wikimedia_Commons_web.pdf", 100, 100, 300)] + [DataRow("Wikimedia_Commons_web.pdf", 100, 100, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, 96)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, 300)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, 96)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, 300)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, 1200)] + public void WithoutAspectRatio(string fileName, int? width = null, int? height = null, int? dpi = null) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "AspectRatio", GetExpectedFilename(fileName, "jpg", width, height, dpi, false)); - using var inputStream = GetInputStream(Path.Combine("..", "Assets", fileName)); - using var outputStream = CreateOutputStream(expectedPath); + using var inputStream = GetInputStream(Path.Combine("..", "Assets", fileName)); + using var outputStream = CreateOutputStream(expectedPath); - if (dpi != null) - SaveJpeg(outputStream, inputStream, options: new (Width: width, Height: height, WithAnnotations: true, WithFormFill: true, WithAspectRatio: false, Dpi: dpi.Value)); - else - SaveJpeg(outputStream, inputStream, options: new(Width: width, Height: height, WithAnnotations: true, WithFormFill: true, WithAspectRatio: false)); + if (dpi != null) + SaveJpeg(outputStream, inputStream, options: new(Width: width, Height: height, WithAnnotations: true, WithFormFill: true, WithAspectRatio: false, Dpi: dpi.Value)); + else + SaveJpeg(outputStream, inputStream, options: new(Width: width, Height: height, WithAnnotations: true, WithFormFill: true, WithAspectRatio: false)); - CompareStreams(expectedPath, outputStream); - } + CompareStreams(expectedPath, outputStream); + } - [TestMethod] - [DataRow("hundesteuer-anmeldung.pdf")] - [DataRow("hundesteuer-anmeldung.pdf", 100, null, null)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, null, null)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, null, null)] - [DataRow("hundesteuer-anmeldung.pdf", null, 100, null)] - [DataRow("hundesteuer-anmeldung.pdf", null, 1000, null)] - [DataRow("hundesteuer-anmeldung.pdf", null, 2000, null)] - [DataRow("hundesteuer-anmeldung.pdf", 100, 100, null)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, null)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, null)] - [DataRow("hundesteuer-anmeldung.pdf", null, null, 96)] - [DataRow("hundesteuer-anmeldung.pdf", null, null, 300)] - [DataRow("hundesteuer-anmeldung.pdf", null, null, 600)] - [DataRow("hundesteuer-anmeldung.pdf", 100, null, 96)] - [DataRow("hundesteuer-anmeldung.pdf", 100, null, 300)] - [DataRow("hundesteuer-anmeldung.pdf", 100, null, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, null, 96)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, null, 300)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, null, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, null, 96)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, null, 300)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, null, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", null, 100, 96)] - [DataRow("hundesteuer-anmeldung.pdf", null, 100, 300)] - [DataRow("hundesteuer-anmeldung.pdf", null, 100, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", null, 1000, 96)] - [DataRow("hundesteuer-anmeldung.pdf", null, 1000, 300)] - [DataRow("hundesteuer-anmeldung.pdf", null, 1000, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", null, 2000, 96)] - [DataRow("hundesteuer-anmeldung.pdf", null, 2000, 300)] - [DataRow("hundesteuer-anmeldung.pdf", null, 2000, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", 100, 100, 96)] - [DataRow("hundesteuer-anmeldung.pdf", 100, 100, 300)] - [DataRow("hundesteuer-anmeldung.pdf", 100, 100, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, 96)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, 300)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, 96)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, 300)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, 1200)] + [TestMethod] + [DataRow("hundesteuer-anmeldung.pdf")] + [DataRow("hundesteuer-anmeldung.pdf", 100, null, null)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, null, null)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, null, null)] + [DataRow("hundesteuer-anmeldung.pdf", null, 100, null)] + [DataRow("hundesteuer-anmeldung.pdf", null, 1000, null)] + [DataRow("hundesteuer-anmeldung.pdf", null, 2000, null)] + [DataRow("hundesteuer-anmeldung.pdf", 100, 100, null)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, null)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, null)] + [DataRow("hundesteuer-anmeldung.pdf", null, null, 96)] + [DataRow("hundesteuer-anmeldung.pdf", null, null, 300)] + [DataRow("hundesteuer-anmeldung.pdf", null, null, 600)] + [DataRow("hundesteuer-anmeldung.pdf", 100, null, 96)] + [DataRow("hundesteuer-anmeldung.pdf", 100, null, 300)] + [DataRow("hundesteuer-anmeldung.pdf", 100, null, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, null, 96)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, null, 300)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, null, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, null, 96)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, null, 300)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, null, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", null, 100, 96)] + [DataRow("hundesteuer-anmeldung.pdf", null, 100, 300)] + [DataRow("hundesteuer-anmeldung.pdf", null, 100, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", null, 1000, 96)] + [DataRow("hundesteuer-anmeldung.pdf", null, 1000, 300)] + [DataRow("hundesteuer-anmeldung.pdf", null, 1000, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", null, 2000, 96)] + [DataRow("hundesteuer-anmeldung.pdf", null, 2000, 300)] + [DataRow("hundesteuer-anmeldung.pdf", null, 2000, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", 100, 100, 96)] + [DataRow("hundesteuer-anmeldung.pdf", 100, 100, 300)] + [DataRow("hundesteuer-anmeldung.pdf", 100, 100, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, 96)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, 300)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, 96)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, 300)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, 1200)] - [DataRow("SocialPreview.pdf")] - [DataRow("SocialPreview.pdf", 100, null, null)] - [DataRow("SocialPreview.pdf", 1000, null, null)] - [DataRow("SocialPreview.pdf", 2000, null, null)] - [DataRow("SocialPreview.pdf", null, 100, null)] - [DataRow("SocialPreview.pdf", null, 1000, null)] - [DataRow("SocialPreview.pdf", null, 2000, null)] - [DataRow("SocialPreview.pdf", 100, 100, null)] - [DataRow("SocialPreview.pdf", 1000, 1000, null)] - [DataRow("SocialPreview.pdf", 2000, 2000, null)] - [DataRow("SocialPreview.pdf", null, null, 96)] - [DataRow("SocialPreview.pdf", null, null, 300)] - [DataRow("SocialPreview.pdf", null, null, 600)] - [DataRow("SocialPreview.pdf", 100, null, 96)] - [DataRow("SocialPreview.pdf", 100, null, 300)] - [DataRow("SocialPreview.pdf", 100, null, 1200)] - [DataRow("SocialPreview.pdf", 1000, null, 96)] - [DataRow("SocialPreview.pdf", 1000, null, 300)] - [DataRow("SocialPreview.pdf", 1000, null, 1200)] - [DataRow("SocialPreview.pdf", 2000, null, 96)] - [DataRow("SocialPreview.pdf", 2000, null, 300)] - [DataRow("SocialPreview.pdf", 2000, null, 1200)] - [DataRow("SocialPreview.pdf", null, 100, 96)] - [DataRow("SocialPreview.pdf", null, 100, 300)] - [DataRow("SocialPreview.pdf", null, 100, 1200)] - [DataRow("SocialPreview.pdf", null, 1000, 96)] - [DataRow("SocialPreview.pdf", null, 1000, 300)] - [DataRow("SocialPreview.pdf", null, 1000, 1200)] - [DataRow("SocialPreview.pdf", null, 2000, 96)] - [DataRow("SocialPreview.pdf", null, 2000, 300)] - [DataRow("SocialPreview.pdf", null, 2000, 1200)] - [DataRow("SocialPreview.pdf", 100, 100, 96)] - [DataRow("SocialPreview.pdf", 100, 100, 300)] - [DataRow("SocialPreview.pdf", 100, 100, 1200)] - [DataRow("SocialPreview.pdf", 1000, 1000, 96)] - [DataRow("SocialPreview.pdf", 1000, 1000, 300)] - [DataRow("SocialPreview.pdf", 1000, 1000, 1200)] - [DataRow("SocialPreview.pdf", 2000, 2000, 96)] - [DataRow("SocialPreview.pdf", 2000, 2000, 300)] - [DataRow("SocialPreview.pdf", 2000, 2000, 1200)] + [DataRow("SocialPreview.pdf")] + [DataRow("SocialPreview.pdf", 100, null, null)] + [DataRow("SocialPreview.pdf", 1000, null, null)] + [DataRow("SocialPreview.pdf", 2000, null, null)] + [DataRow("SocialPreview.pdf", null, 100, null)] + [DataRow("SocialPreview.pdf", null, 1000, null)] + [DataRow("SocialPreview.pdf", null, 2000, null)] + [DataRow("SocialPreview.pdf", 100, 100, null)] + [DataRow("SocialPreview.pdf", 1000, 1000, null)] + [DataRow("SocialPreview.pdf", 2000, 2000, null)] + [DataRow("SocialPreview.pdf", null, null, 96)] + [DataRow("SocialPreview.pdf", null, null, 300)] + [DataRow("SocialPreview.pdf", null, null, 600)] + [DataRow("SocialPreview.pdf", 100, null, 96)] + [DataRow("SocialPreview.pdf", 100, null, 300)] + [DataRow("SocialPreview.pdf", 100, null, 1200)] + [DataRow("SocialPreview.pdf", 1000, null, 96)] + [DataRow("SocialPreview.pdf", 1000, null, 300)] + [DataRow("SocialPreview.pdf", 1000, null, 1200)] + [DataRow("SocialPreview.pdf", 2000, null, 96)] + [DataRow("SocialPreview.pdf", 2000, null, 300)] + [DataRow("SocialPreview.pdf", 2000, null, 1200)] + [DataRow("SocialPreview.pdf", null, 100, 96)] + [DataRow("SocialPreview.pdf", null, 100, 300)] + [DataRow("SocialPreview.pdf", null, 100, 1200)] + [DataRow("SocialPreview.pdf", null, 1000, 96)] + [DataRow("SocialPreview.pdf", null, 1000, 300)] + [DataRow("SocialPreview.pdf", null, 1000, 1200)] + [DataRow("SocialPreview.pdf", null, 2000, 96)] + [DataRow("SocialPreview.pdf", null, 2000, 300)] + [DataRow("SocialPreview.pdf", null, 2000, 1200)] + [DataRow("SocialPreview.pdf", 100, 100, 96)] + [DataRow("SocialPreview.pdf", 100, 100, 300)] + [DataRow("SocialPreview.pdf", 100, 100, 1200)] + [DataRow("SocialPreview.pdf", 1000, 1000, 96)] + [DataRow("SocialPreview.pdf", 1000, 1000, 300)] + [DataRow("SocialPreview.pdf", 1000, 1000, 1200)] + [DataRow("SocialPreview.pdf", 2000, 2000, 96)] + [DataRow("SocialPreview.pdf", 2000, 2000, 300)] + [DataRow("SocialPreview.pdf", 2000, 2000, 1200)] - [DataRow("Wikimedia_Commons_web.pdf")] - [DataRow("Wikimedia_Commons_web.pdf", 100, null, null)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, null, null)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, null, null)] - [DataRow("Wikimedia_Commons_web.pdf", null, 100, null)] - [DataRow("Wikimedia_Commons_web.pdf", null, 1000, null)] - [DataRow("Wikimedia_Commons_web.pdf", null, 2000, null)] - [DataRow("Wikimedia_Commons_web.pdf", 100, 100, null)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, null)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, null)] - [DataRow("Wikimedia_Commons_web.pdf", null, null, 96)] - [DataRow("Wikimedia_Commons_web.pdf", null, null, 300)] - [DataRow("Wikimedia_Commons_web.pdf", null, null, 600)] - [DataRow("Wikimedia_Commons_web.pdf", 100, null, 96)] - [DataRow("Wikimedia_Commons_web.pdf", 100, null, 300)] - [DataRow("Wikimedia_Commons_web.pdf", 100, null, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, null, 96)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, null, 300)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, null, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, null, 96)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, null, 300)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, null, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", null, 100, 96)] - [DataRow("Wikimedia_Commons_web.pdf", null, 100, 300)] - [DataRow("Wikimedia_Commons_web.pdf", null, 100, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", null, 1000, 96)] - [DataRow("Wikimedia_Commons_web.pdf", null, 1000, 300)] - [DataRow("Wikimedia_Commons_web.pdf", null, 1000, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", null, 2000, 96)] - [DataRow("Wikimedia_Commons_web.pdf", null, 2000, 300)] - [DataRow("Wikimedia_Commons_web.pdf", null, 2000, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", 100, 100, 96)] - [DataRow("Wikimedia_Commons_web.pdf", 100, 100, 300)] - [DataRow("Wikimedia_Commons_web.pdf", 100, 100, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, 96)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, 300)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, 96)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, 300)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, 1200)] - public void WithAspectRatio(string fileName, int? width = null, int? height = null, int? dpi = null) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "AspectRatio", GetExpectedFilename(fileName, "jpg", width, height, dpi, true)); + [DataRow("Wikimedia_Commons_web.pdf")] + [DataRow("Wikimedia_Commons_web.pdf", 100, null, null)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, null, null)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, null, null)] + [DataRow("Wikimedia_Commons_web.pdf", null, 100, null)] + [DataRow("Wikimedia_Commons_web.pdf", null, 1000, null)] + [DataRow("Wikimedia_Commons_web.pdf", null, 2000, null)] + [DataRow("Wikimedia_Commons_web.pdf", 100, 100, null)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, null)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, null)] + [DataRow("Wikimedia_Commons_web.pdf", null, null, 96)] + [DataRow("Wikimedia_Commons_web.pdf", null, null, 300)] + [DataRow("Wikimedia_Commons_web.pdf", null, null, 600)] + [DataRow("Wikimedia_Commons_web.pdf", 100, null, 96)] + [DataRow("Wikimedia_Commons_web.pdf", 100, null, 300)] + [DataRow("Wikimedia_Commons_web.pdf", 100, null, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, null, 96)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, null, 300)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, null, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, null, 96)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, null, 300)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, null, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", null, 100, 96)] + [DataRow("Wikimedia_Commons_web.pdf", null, 100, 300)] + [DataRow("Wikimedia_Commons_web.pdf", null, 100, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", null, 1000, 96)] + [DataRow("Wikimedia_Commons_web.pdf", null, 1000, 300)] + [DataRow("Wikimedia_Commons_web.pdf", null, 1000, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", null, 2000, 96)] + [DataRow("Wikimedia_Commons_web.pdf", null, 2000, 300)] + [DataRow("Wikimedia_Commons_web.pdf", null, 2000, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", 100, 100, 96)] + [DataRow("Wikimedia_Commons_web.pdf", 100, 100, 300)] + [DataRow("Wikimedia_Commons_web.pdf", 100, 100, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, 96)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, 300)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, 96)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, 300)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, 1200)] + public void WithAspectRatio(string fileName, int? width = null, int? height = null, int? dpi = null) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "AspectRatio", GetExpectedFilename(fileName, "jpg", width, height, dpi, true)); - using var inputStream = GetInputStream(Path.Combine("..", "Assets", fileName)); - using var outputStream = CreateOutputStream(expectedPath); + using var inputStream = GetInputStream(Path.Combine("..", "Assets", fileName)); + using var outputStream = CreateOutputStream(expectedPath); - if (dpi != null) - SaveJpeg(outputStream, inputStream, options: new(Width: width, Height: height, WithAnnotations: true, WithFormFill: true, WithAspectRatio: true, Dpi: dpi.Value)); - else - SaveJpeg(outputStream, inputStream, options: new(Width: width, Height: height, WithAnnotations: true, WithFormFill: true, WithAspectRatio: true)); + if (dpi != null) + SaveJpeg(outputStream, inputStream, options: new(Width: width, Height: height, WithAnnotations: true, WithFormFill: true, WithAspectRatio: true, Dpi: dpi.Value)); + else + SaveJpeg(outputStream, inputStream, options: new(Width: width, Height: height, WithAnnotations: true, WithFormFill: true, WithAspectRatio: true)); - CompareStreams(expectedPath, outputStream); - } + CompareStreams(expectedPath, outputStream); + } - [TestMethod] - [DataRow("hundesteuer-anmeldung.pdf", 100, null, false)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, null, false)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, null, false)] - [DataRow("hundesteuer-anmeldung.pdf", null, 100, false)] - [DataRow("hundesteuer-anmeldung.pdf", null, 1000, false)] - [DataRow("hundesteuer-anmeldung.pdf", null, 2000, false)] - [DataRow("hundesteuer-anmeldung.pdf", 100, 100, false)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, false)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, false)] - [DataRow("hundesteuer-anmeldung.pdf", 100, null, true)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, null, true)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, null, true)] - [DataRow("hundesteuer-anmeldung.pdf", null, 100, true)] - [DataRow("hundesteuer-anmeldung.pdf", null, 1000, true)] - [DataRow("hundesteuer-anmeldung.pdf", null, 2000, true)] - [DataRow("hundesteuer-anmeldung.pdf", 100, 100, true)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, true)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, true)] + [TestMethod] + [DataRow("hundesteuer-anmeldung.pdf", 100, null, false)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, null, false)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, null, false)] + [DataRow("hundesteuer-anmeldung.pdf", null, 100, false)] + [DataRow("hundesteuer-anmeldung.pdf", null, 1000, false)] + [DataRow("hundesteuer-anmeldung.pdf", null, 2000, false)] + [DataRow("hundesteuer-anmeldung.pdf", 100, 100, false)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, false)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, false)] + [DataRow("hundesteuer-anmeldung.pdf", 100, null, true)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, null, true)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, null, true)] + [DataRow("hundesteuer-anmeldung.pdf", null, 100, true)] + [DataRow("hundesteuer-anmeldung.pdf", null, 1000, true)] + [DataRow("hundesteuer-anmeldung.pdf", null, 2000, true)] + [DataRow("hundesteuer-anmeldung.pdf", 100, 100, true)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, true)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, true)] - [DataRow("SocialPreview.pdf", 100, null, false)] - [DataRow("SocialPreview.pdf", 1000, null, false)] - [DataRow("SocialPreview.pdf", 2000, null, false)] - [DataRow("SocialPreview.pdf", null, 100, false)] - [DataRow("SocialPreview.pdf", null, 1000, false)] - [DataRow("SocialPreview.pdf", null, 2000, false)] - [DataRow("SocialPreview.pdf", 100, 100, false)] - [DataRow("SocialPreview.pdf", 1000, 1000, false)] - [DataRow("SocialPreview.pdf", 2000, 2000, false)] - [DataRow("SocialPreview.pdf", 100, null, true)] - [DataRow("SocialPreview.pdf", 1000, null, true)] - [DataRow("SocialPreview.pdf", 2000, null, true)] - [DataRow("SocialPreview.pdf", null, 100, true)] - [DataRow("SocialPreview.pdf", null, 1000, true)] - [DataRow("SocialPreview.pdf", null, 2000, true)] - [DataRow("SocialPreview.pdf", 100, 100, true)] - [DataRow("SocialPreview.pdf", 1000, 1000, true)] - [DataRow("SocialPreview.pdf", 2000, 2000, true)] + [DataRow("SocialPreview.pdf", 100, null, false)] + [DataRow("SocialPreview.pdf", 1000, null, false)] + [DataRow("SocialPreview.pdf", 2000, null, false)] + [DataRow("SocialPreview.pdf", null, 100, false)] + [DataRow("SocialPreview.pdf", null, 1000, false)] + [DataRow("SocialPreview.pdf", null, 2000, false)] + [DataRow("SocialPreview.pdf", 100, 100, false)] + [DataRow("SocialPreview.pdf", 1000, 1000, false)] + [DataRow("SocialPreview.pdf", 2000, 2000, false)] + [DataRow("SocialPreview.pdf", 100, null, true)] + [DataRow("SocialPreview.pdf", 1000, null, true)] + [DataRow("SocialPreview.pdf", 2000, null, true)] + [DataRow("SocialPreview.pdf", null, 100, true)] + [DataRow("SocialPreview.pdf", null, 1000, true)] + [DataRow("SocialPreview.pdf", null, 2000, true)] + [DataRow("SocialPreview.pdf", 100, 100, true)] + [DataRow("SocialPreview.pdf", 1000, 1000, true)] + [DataRow("SocialPreview.pdf", 2000, 2000, true)] - [DataRow("Wikimedia_Commons_web.pdf", 100, null, false)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, null, false)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, null, false)] - [DataRow("Wikimedia_Commons_web.pdf", null, 100, false)] - [DataRow("Wikimedia_Commons_web.pdf", null, 1000, false)] - [DataRow("Wikimedia_Commons_web.pdf", null, 2000, false)] - [DataRow("Wikimedia_Commons_web.pdf", 100, 100, false)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, false)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, false)] - [DataRow("Wikimedia_Commons_web.pdf", 100, null, true)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, null, true)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, null, true)] - [DataRow("Wikimedia_Commons_web.pdf", null, 100, true)] - [DataRow("Wikimedia_Commons_web.pdf", null, 1000, true)] - [DataRow("Wikimedia_Commons_web.pdf", null, 2000, true)] - [DataRow("Wikimedia_Commons_web.pdf", 100, 100, true)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, true)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, true)] - public void IgnoreDpi(string fileName, int? width = null, int? height = null, bool withAspectRatio = false) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "AspectRatio", GetExpectedFilename(fileName, "jpg", width, height, 300, withAspectRatio)); + [DataRow("Wikimedia_Commons_web.pdf", 100, null, false)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, null, false)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, null, false)] + [DataRow("Wikimedia_Commons_web.pdf", null, 100, false)] + [DataRow("Wikimedia_Commons_web.pdf", null, 1000, false)] + [DataRow("Wikimedia_Commons_web.pdf", null, 2000, false)] + [DataRow("Wikimedia_Commons_web.pdf", 100, 100, false)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, false)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, false)] + [DataRow("Wikimedia_Commons_web.pdf", 100, null, true)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, null, true)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, null, true)] + [DataRow("Wikimedia_Commons_web.pdf", null, 100, true)] + [DataRow("Wikimedia_Commons_web.pdf", null, 1000, true)] + [DataRow("Wikimedia_Commons_web.pdf", null, 2000, true)] + [DataRow("Wikimedia_Commons_web.pdf", 100, 100, true)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, true)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, true)] + public void IgnoreDpi(string fileName, int? width = null, int? height = null, bool withAspectRatio = false) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "AspectRatio", GetExpectedFilename(fileName, "jpg", width, height, 300, withAspectRatio)); - using var inputStream = GetInputStream(Path.Combine("..", "Assets", fileName)); + using var inputStream = GetInputStream(Path.Combine("..", "Assets", fileName)); - for (int i = 72; i < 600; i += 100) - { - using var outputStream = CreateOutputStream(expectedPath); + for (int i = 72; i < 600; i += 100) + { + using var outputStream = CreateOutputStream(expectedPath); - ToImage(inputStream, true, options: new(Dpi: i, Width: width, Height: height, WithAnnotations: true, WithFormFill: true, WithAspectRatio: withAspectRatio)).Encode(outputStream, SkiaSharp.SKEncodedImageFormat.Jpeg, 100); - CompareStreams(expectedPath, outputStream); - } - } + ToImage(inputStream, true, options: new(Dpi: i, Width: width, Height: height, WithAnnotations: true, WithFormFill: true, WithAspectRatio: withAspectRatio)).Encode(outputStream, SkiaSharp.SKEncodedImageFormat.Jpeg, 100); + CompareStreams(expectedPath, outputStream); + } + } - [TestMethod] - [DataRow("hundesteuer-anmeldung.pdf", 100, 100)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000)] - [DataRow("SocialPreview.pdf", 100, 100)] - [DataRow("SocialPreview.pdf", 1000, 1000)] - [DataRow("SocialPreview.pdf", 2000, 2000)] - [DataRow("Wikimedia_Commons_web.pdf", 100, 100)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000)] - public void IgnoreAspectRatio(string fileName, int width, int height) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "AspectRatio", GetExpectedFilename(fileName, "jpg", width, height, 300, true)); + [TestMethod] + [DataRow("hundesteuer-anmeldung.pdf", 100, 100)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000)] + [DataRow("SocialPreview.pdf", 100, 100)] + [DataRow("SocialPreview.pdf", 1000, 1000)] + [DataRow("SocialPreview.pdf", 2000, 2000)] + [DataRow("Wikimedia_Commons_web.pdf", 100, 100)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000)] + public void IgnoreAspectRatio(string fileName, int width, int height) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "AspectRatio", GetExpectedFilename(fileName, "jpg", width, height, 300, true)); - using var inputStream = GetInputStream(Path.Combine("..", "Assets", fileName)); - using var outputStream1 = CreateOutputStream(expectedPath); - using var outputStream2 = CreateOutputStream(expectedPath); + using var inputStream = GetInputStream(Path.Combine("..", "Assets", fileName)); + using var outputStream1 = CreateOutputStream(expectedPath); + using var outputStream2 = CreateOutputStream(expectedPath); - ToImage(inputStream, true, options: new(Width: width, Height: height, WithAnnotations: true, WithFormFill: true, WithAspectRatio: false)).Encode(outputStream1, SkiaSharp.SKEncodedImageFormat.Jpeg, 100); - ToImage(inputStream, true, options: new(Width: width, Height: height, WithAnnotations: true, WithFormFill: true, WithAspectRatio: true)).Encode(outputStream2, SkiaSharp.SKEncodedImageFormat.Jpeg, 100); + ToImage(inputStream, true, options: new(Width: width, Height: height, WithAnnotations: true, WithFormFill: true, WithAspectRatio: false)).Encode(outputStream1, SkiaSharp.SKEncodedImageFormat.Jpeg, 100); + ToImage(inputStream, true, options: new(Width: width, Height: height, WithAnnotations: true, WithFormFill: true, WithAspectRatio: true)).Encode(outputStream2, SkiaSharp.SKEncodedImageFormat.Jpeg, 100); - CompareStreams(expectedPath, outputStream1); - CompareStreams(expectedPath, outputStream2); - } + CompareStreams(expectedPath, outputStream1); + CompareStreams(expectedPath, outputStream2); + } - [TestMethod] - [DataRow("hundesteuer-anmeldung.pdf", 96)] - [DataRow("hundesteuer-anmeldung.pdf", 300)] - [DataRow("hundesteuer-anmeldung.pdf", 600)] - [DataRow("SocialPreview.pdf", 96)] - [DataRow("SocialPreview.pdf", 300)] - [DataRow("SocialPreview.pdf", 600)] - [DataRow("Wikimedia_Commons_web.pdf", 96)] - [DataRow("Wikimedia_Commons_web.pdf", 300)] - [DataRow("Wikimedia_Commons_web.pdf", 600)] - public void IgnoreAspectRatioWithDpi(string fileName, int dpi) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "AspectRatio", GetExpectedFilename(fileName, "jpg", null, null, dpi, true)); + [TestMethod] + [DataRow("hundesteuer-anmeldung.pdf", 96)] + [DataRow("hundesteuer-anmeldung.pdf", 300)] + [DataRow("hundesteuer-anmeldung.pdf", 600)] + [DataRow("SocialPreview.pdf", 96)] + [DataRow("SocialPreview.pdf", 300)] + [DataRow("SocialPreview.pdf", 600)] + [DataRow("Wikimedia_Commons_web.pdf", 96)] + [DataRow("Wikimedia_Commons_web.pdf", 300)] + [DataRow("Wikimedia_Commons_web.pdf", 600)] + public void IgnoreAspectRatioWithDpi(string fileName, int dpi) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "AspectRatio", GetExpectedFilename(fileName, "jpg", null, null, dpi, true)); - using var inputStream = GetInputStream(Path.Combine("..", "Assets", fileName)); - using var outputStream1 = CreateOutputStream(expectedPath); - using var outputStream2 = CreateOutputStream(expectedPath); + using var inputStream = GetInputStream(Path.Combine("..", "Assets", fileName)); + using var outputStream1 = CreateOutputStream(expectedPath); + using var outputStream2 = CreateOutputStream(expectedPath); - ToImage(inputStream, true, options: new(Dpi: dpi, WithAnnotations: true, WithFormFill: true, WithAspectRatio: false)).Encode(outputStream1, SkiaSharp.SKEncodedImageFormat.Jpeg, 100); - ToImage(inputStream, true, options: new(Dpi: dpi, WithAnnotations: true, WithFormFill: true, WithAspectRatio: true)).Encode(outputStream2, SkiaSharp.SKEncodedImageFormat.Jpeg, 100); + ToImage(inputStream, true, options: new(Dpi: dpi, WithAnnotations: true, WithFormFill: true, WithAspectRatio: false)).Encode(outputStream1, SkiaSharp.SKEncodedImageFormat.Jpeg, 100); + ToImage(inputStream, true, options: new(Dpi: dpi, WithAnnotations: true, WithFormFill: true, WithAspectRatio: true)).Encode(outputStream2, SkiaSharp.SKEncodedImageFormat.Jpeg, 100); - CompareStreams(expectedPath, outputStream1); - CompareStreams(expectedPath, outputStream2); - } + CompareStreams(expectedPath, outputStream1); + CompareStreams(expectedPath, outputStream2); + } - private static string GetExpectedFilename(string fileName, string? fileExtension, int? width, int? height, int? dpi, bool withAspectRatio) - => $"{fileName}_w={width?.ToString() ?? "null"}_h={height?.ToString() ?? "null"}_dpi={dpi?.ToString() ?? "null"}_aspectratio={withAspectRatio}{(fileExtension != null ? $".{fileExtension}" : string.Empty)}"; - } + private static string GetExpectedFilename(string fileName, string? fileExtension, int? width, int? height, int? dpi, bool withAspectRatio) + => $"{fileName}_w={width?.ToString() ?? "null"}_h={height?.ToString() ?? "null"}_dpi={dpi?.ToString() ?? "null"}_aspectratio={withAspectRatio}{(fileExtension != null ? $".{fileExtension}" : string.Empty)}"; + } } \ No newline at end of file diff --git a/src/Tests/ComparisonTests.cs b/src/Tests/ComparisonTests.cs index 10af967f..24a0c223 100644 --- a/src/Tests/ComparisonTests.cs +++ b/src/Tests/ComparisonTests.cs @@ -12,83 +12,83 @@ namespace Tests { - [TestClass] - public class ComparisonTests : TestBase - { - [TestMethod] - [DataRow(0, DisplayName = "Page 1")] - [DataRow(1, DisplayName = "Page 2")] - [DataRow(2, DisplayName = "Page 3")] - [DataRow(3, DisplayName = "Page 4")] - [DataRow(4, DisplayName = "Page 5")] - [DataRow(5, DisplayName = "Page 6")] - [DataRow(6, DisplayName = "Page 7")] - [DataRow(7, DisplayName = "Page 8")] - [DataRow(8, DisplayName = "Page 9")] - [DataRow(9, DisplayName = "Page 10")] - [DataRow(10, DisplayName = "Page 11")] - [DataRow(11, DisplayName = "Page 12")] - [DataRow(12, DisplayName = "Page 13")] - [DataRow(13, DisplayName = "Page 14")] - [DataRow(14, DisplayName = "Page 15")] - [DataRow(15, DisplayName = "Page 16")] - [DataRow(16, DisplayName = "Page 17")] - [DataRow(17, DisplayName = "Page 18")] - [DataRow(18, DisplayName = "Page 19")] - [DataRow(19, DisplayName = "Page 20")] - [DataRow(0, true, DisplayName = "Page 1 (with annotations)")] - [DataRow(1, true, DisplayName = "Page 2 (with annotations)")] - [DataRow(2, true, DisplayName = "Page 3 (with annotations)")] - [DataRow(3, true, DisplayName = "Page 4 (with annotations)")] - [DataRow(4, true, DisplayName = "Page 5 (with annotations)")] - [DataRow(5, true, DisplayName = "Page 6 (with annotations)")] - [DataRow(6, true, DisplayName = "Page 7 (with annotations)")] - [DataRow(7, true, DisplayName = "Page 8 (with annotations)")] - [DataRow(8, true, DisplayName = "Page 9 (with annotations)")] - [DataRow(9, true, DisplayName = "Page 10 (with annotations)")] - [DataRow(10, true, DisplayName = "Page 11 (with annotations)")] - [DataRow(11, true, DisplayName = "Page 12 (with annotations)")] - [DataRow(12, true, DisplayName = "Page 13 (with annotations)")] - [DataRow(13, true, DisplayName = "Page 14 (with annotations)")] - [DataRow(14, true, DisplayName = "Page 15 (with annotations)")] - [DataRow(15, true, DisplayName = "Page 16 (with annotations)")] - [DataRow(16, true, DisplayName = "Page 17 (with annotations)")] - [DataRow(17, true, DisplayName = "Page 18 (with annotations)")] - [DataRow(18, true, DisplayName = "Page 19 (with annotations)")] - [DataRow(19, true, DisplayName = "Page 20 (with annotations)")] - public void SaveWebpPageNumber(int page, bool withAnnotations = false) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{page}{(withAnnotations ? "_ANNOT" : string.Empty)}.webp"); - - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "Wikimedia_Commons_web.pdf")); - using var outputStream = CreateOutputStream(expectedPath); - - SaveWebp(outputStream, inputStream, page: page, options: new(Dpi: 40, WithAnnotations: withAnnotations)); - - CompareStreams(expectedPath, outputStream); - } - - [TestMethod] - [DataRow(false, DisplayName = "Without annotations")] - [DataRow(true, DisplayName = "With annotations")] - public void SaveWebpPages(bool withAnnotations = false) - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "Wikimedia_Commons_web.pdf")); - - int page = 0; - - foreach (var image in ToImages(inputStream, options: new(Dpi: 40, WithAnnotations: withAnnotations))) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{page}{(withAnnotations ? "_ANNOT" : string.Empty)}.webp"); - - using var outputStream = CreateOutputStream(expectedPath); - image.Encode(outputStream, SKEncodedImageFormat.Webp, 100); - - CompareStreams(expectedPath, outputStream); - - page++; - } - } + [TestClass] + public class ComparisonTests : TestBase + { + [TestMethod] + [DataRow(0, DisplayName = "Page 1")] + [DataRow(1, DisplayName = "Page 2")] + [DataRow(2, DisplayName = "Page 3")] + [DataRow(3, DisplayName = "Page 4")] + [DataRow(4, DisplayName = "Page 5")] + [DataRow(5, DisplayName = "Page 6")] + [DataRow(6, DisplayName = "Page 7")] + [DataRow(7, DisplayName = "Page 8")] + [DataRow(8, DisplayName = "Page 9")] + [DataRow(9, DisplayName = "Page 10")] + [DataRow(10, DisplayName = "Page 11")] + [DataRow(11, DisplayName = "Page 12")] + [DataRow(12, DisplayName = "Page 13")] + [DataRow(13, DisplayName = "Page 14")] + [DataRow(14, DisplayName = "Page 15")] + [DataRow(15, DisplayName = "Page 16")] + [DataRow(16, DisplayName = "Page 17")] + [DataRow(17, DisplayName = "Page 18")] + [DataRow(18, DisplayName = "Page 19")] + [DataRow(19, DisplayName = "Page 20")] + [DataRow(0, true, DisplayName = "Page 1 (with annotations)")] + [DataRow(1, true, DisplayName = "Page 2 (with annotations)")] + [DataRow(2, true, DisplayName = "Page 3 (with annotations)")] + [DataRow(3, true, DisplayName = "Page 4 (with annotations)")] + [DataRow(4, true, DisplayName = "Page 5 (with annotations)")] + [DataRow(5, true, DisplayName = "Page 6 (with annotations)")] + [DataRow(6, true, DisplayName = "Page 7 (with annotations)")] + [DataRow(7, true, DisplayName = "Page 8 (with annotations)")] + [DataRow(8, true, DisplayName = "Page 9 (with annotations)")] + [DataRow(9, true, DisplayName = "Page 10 (with annotations)")] + [DataRow(10, true, DisplayName = "Page 11 (with annotations)")] + [DataRow(11, true, DisplayName = "Page 12 (with annotations)")] + [DataRow(12, true, DisplayName = "Page 13 (with annotations)")] + [DataRow(13, true, DisplayName = "Page 14 (with annotations)")] + [DataRow(14, true, DisplayName = "Page 15 (with annotations)")] + [DataRow(15, true, DisplayName = "Page 16 (with annotations)")] + [DataRow(16, true, DisplayName = "Page 17 (with annotations)")] + [DataRow(17, true, DisplayName = "Page 18 (with annotations)")] + [DataRow(18, true, DisplayName = "Page 19 (with annotations)")] + [DataRow(19, true, DisplayName = "Page 20 (with annotations)")] + public void SaveWebpPageNumber(int page, bool withAnnotations = false) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{page}{(withAnnotations ? "_ANNOT" : string.Empty)}.webp"); + + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "Wikimedia_Commons_web.pdf")); + using var outputStream = CreateOutputStream(expectedPath); + + SaveWebp(outputStream, inputStream, page: page, options: new(Dpi: 40, WithAnnotations: withAnnotations)); + + CompareStreams(expectedPath, outputStream); + } + + [TestMethod] + [DataRow(false, DisplayName = "Without annotations")] + [DataRow(true, DisplayName = "With annotations")] + public void SaveWebpPages(bool withAnnotations = false) + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "Wikimedia_Commons_web.pdf")); + + int page = 0; + + foreach (var image in ToImages(inputStream, options: new(Dpi: 40, WithAnnotations: withAnnotations))) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{page}{(withAnnotations ? "_ANNOT" : string.Empty)}.webp"); + + using var outputStream = CreateOutputStream(expectedPath); + image.Encode(outputStream, SKEncodedImageFormat.Webp, 100); + + CompareStreams(expectedPath, outputStream); + + page++; + } + } #if NET6_0_OR_GREATER [TestMethod] @@ -114,80 +114,80 @@ public async Task SaveWebpPagesAsync(bool withAnnotations = false) } #endif - [TestMethod] - [DataRow(0, DisplayName = "Page 1")] - [DataRow(1, DisplayName = "Page 2")] - [DataRow(2, DisplayName = "Page 3")] - [DataRow(3, DisplayName = "Page 4")] - [DataRow(4, DisplayName = "Page 5")] - [DataRow(5, DisplayName = "Page 6")] - [DataRow(6, DisplayName = "Page 7")] - [DataRow(7, DisplayName = "Page 8")] - [DataRow(8, DisplayName = "Page 9")] - [DataRow(9, DisplayName = "Page 10")] - [DataRow(10, DisplayName = "Page 11")] - [DataRow(11, DisplayName = "Page 12")] - [DataRow(12, DisplayName = "Page 13")] - [DataRow(13, DisplayName = "Page 14")] - [DataRow(14, DisplayName = "Page 15")] - [DataRow(15, DisplayName = "Page 16")] - [DataRow(16, DisplayName = "Page 17")] - [DataRow(17, DisplayName = "Page 18")] - [DataRow(18, DisplayName = "Page 19")] - [DataRow(19, DisplayName = "Page 20")] - [DataRow(0, true, DisplayName = "Page 1 (with annotations)")] - [DataRow(1, true, DisplayName = "Page 2 (with annotations)")] - [DataRow(2, true, DisplayName = "Page 3 (with annotations)")] - [DataRow(3, true, DisplayName = "Page 4 (with annotations)")] - [DataRow(4, true, DisplayName = "Page 5 (with annotations)")] - [DataRow(5, true, DisplayName = "Page 6 (with annotations)")] - [DataRow(6, true, DisplayName = "Page 7 (with annotations)")] - [DataRow(7, true, DisplayName = "Page 8 (with annotations)")] - [DataRow(8, true, DisplayName = "Page 9 (with annotations)")] - [DataRow(9, true, DisplayName = "Page 10 (with annotations)")] - [DataRow(10, true, DisplayName = "Page 11 (with annotations)")] - [DataRow(11, true, DisplayName = "Page 12 (with annotations)")] - [DataRow(12, true, DisplayName = "Page 13 (with annotations)")] - [DataRow(13, true, DisplayName = "Page 14 (with annotations)")] - [DataRow(14, true, DisplayName = "Page 15 (with annotations)")] - [DataRow(15, true, DisplayName = "Page 16 (with annotations)")] - [DataRow(16, true, DisplayName = "Page 17 (with annotations)")] - [DataRow(17, true, DisplayName = "Page 18 (with annotations)")] - [DataRow(18, true, DisplayName = "Page 19 (with annotations)")] - [DataRow(19, true, DisplayName = "Page 20 (with annotations)")] - public void SavePngPageNumber(int page, bool withAnnotations = false) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{page}{(withAnnotations ? "_ANNOT" : string.Empty)}.png"); - - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "Wikimedia_Commons_web.pdf")); - using var outputStream = CreateOutputStream(expectedPath); - - SavePng(outputStream, inputStream, page: page, options: new(Dpi: 40, WithAnnotations: withAnnotations)); - - CompareStreams(expectedPath, outputStream); - } - - [TestMethod] - [DataRow(false, DisplayName = "Without annotations")] - [DataRow(true, DisplayName = "With annotations")] - public void SavePngPages(bool withAnnotations = false) - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "Wikimedia_Commons_web.pdf")); - - int page = 0; - - foreach (var image in ToImages(inputStream, options: new(Dpi: 40, WithAnnotations: withAnnotations))) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{page}{(withAnnotations ? "_ANNOT" : string.Empty)}.png"); - - using var outputStream = CreateOutputStream(expectedPath); - image.Encode(outputStream, SKEncodedImageFormat.Png, 100); - - CompareStreams(expectedPath, outputStream); - - page++; - } - } + [TestMethod] + [DataRow(0, DisplayName = "Page 1")] + [DataRow(1, DisplayName = "Page 2")] + [DataRow(2, DisplayName = "Page 3")] + [DataRow(3, DisplayName = "Page 4")] + [DataRow(4, DisplayName = "Page 5")] + [DataRow(5, DisplayName = "Page 6")] + [DataRow(6, DisplayName = "Page 7")] + [DataRow(7, DisplayName = "Page 8")] + [DataRow(8, DisplayName = "Page 9")] + [DataRow(9, DisplayName = "Page 10")] + [DataRow(10, DisplayName = "Page 11")] + [DataRow(11, DisplayName = "Page 12")] + [DataRow(12, DisplayName = "Page 13")] + [DataRow(13, DisplayName = "Page 14")] + [DataRow(14, DisplayName = "Page 15")] + [DataRow(15, DisplayName = "Page 16")] + [DataRow(16, DisplayName = "Page 17")] + [DataRow(17, DisplayName = "Page 18")] + [DataRow(18, DisplayName = "Page 19")] + [DataRow(19, DisplayName = "Page 20")] + [DataRow(0, true, DisplayName = "Page 1 (with annotations)")] + [DataRow(1, true, DisplayName = "Page 2 (with annotations)")] + [DataRow(2, true, DisplayName = "Page 3 (with annotations)")] + [DataRow(3, true, DisplayName = "Page 4 (with annotations)")] + [DataRow(4, true, DisplayName = "Page 5 (with annotations)")] + [DataRow(5, true, DisplayName = "Page 6 (with annotations)")] + [DataRow(6, true, DisplayName = "Page 7 (with annotations)")] + [DataRow(7, true, DisplayName = "Page 8 (with annotations)")] + [DataRow(8, true, DisplayName = "Page 9 (with annotations)")] + [DataRow(9, true, DisplayName = "Page 10 (with annotations)")] + [DataRow(10, true, DisplayName = "Page 11 (with annotations)")] + [DataRow(11, true, DisplayName = "Page 12 (with annotations)")] + [DataRow(12, true, DisplayName = "Page 13 (with annotations)")] + [DataRow(13, true, DisplayName = "Page 14 (with annotations)")] + [DataRow(14, true, DisplayName = "Page 15 (with annotations)")] + [DataRow(15, true, DisplayName = "Page 16 (with annotations)")] + [DataRow(16, true, DisplayName = "Page 17 (with annotations)")] + [DataRow(17, true, DisplayName = "Page 18 (with annotations)")] + [DataRow(18, true, DisplayName = "Page 19 (with annotations)")] + [DataRow(19, true, DisplayName = "Page 20 (with annotations)")] + public void SavePngPageNumber(int page, bool withAnnotations = false) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{page}{(withAnnotations ? "_ANNOT" : string.Empty)}.png"); + + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "Wikimedia_Commons_web.pdf")); + using var outputStream = CreateOutputStream(expectedPath); + + SavePng(outputStream, inputStream, page: page, options: new(Dpi: 40, WithAnnotations: withAnnotations)); + + CompareStreams(expectedPath, outputStream); + } + + [TestMethod] + [DataRow(false, DisplayName = "Without annotations")] + [DataRow(true, DisplayName = "With annotations")] + public void SavePngPages(bool withAnnotations = false) + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "Wikimedia_Commons_web.pdf")); + + int page = 0; + + foreach (var image in ToImages(inputStream, options: new(Dpi: 40, WithAnnotations: withAnnotations))) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{page}{(withAnnotations ? "_ANNOT" : string.Empty)}.png"); + + using var outputStream = CreateOutputStream(expectedPath); + image.Encode(outputStream, SKEncodedImageFormat.Png, 100); + + CompareStreams(expectedPath, outputStream); + + page++; + } + } #if NET6_0_OR_GREATER [TestMethod] @@ -213,80 +213,80 @@ public async Task SavePngPagesAsync(bool withAnnotations = false) } #endif - [TestMethod] - [DataRow(0, DisplayName = "Page 1")] - [DataRow(1, DisplayName = "Page 2")] - [DataRow(2, DisplayName = "Page 3")] - [DataRow(3, DisplayName = "Page 4")] - [DataRow(4, DisplayName = "Page 5")] - [DataRow(5, DisplayName = "Page 6")] - [DataRow(6, DisplayName = "Page 7")] - [DataRow(7, DisplayName = "Page 8")] - [DataRow(8, DisplayName = "Page 9")] - [DataRow(9, DisplayName = "Page 10")] - [DataRow(10, DisplayName = "Page 11")] - [DataRow(11, DisplayName = "Page 12")] - [DataRow(12, DisplayName = "Page 13")] - [DataRow(13, DisplayName = "Page 14")] - [DataRow(14, DisplayName = "Page 15")] - [DataRow(15, DisplayName = "Page 16")] - [DataRow(16, DisplayName = "Page 17")] - [DataRow(17, DisplayName = "Page 18")] - [DataRow(18, DisplayName = "Page 19")] - [DataRow(19, DisplayName = "Page 20")] - [DataRow(0, true, DisplayName = "Page 1 (with annotations)")] - [DataRow(1, true, DisplayName = "Page 2 (with annotations)")] - [DataRow(2, true, DisplayName = "Page 3 (with annotations)")] - [DataRow(3, true, DisplayName = "Page 4 (with annotations)")] - [DataRow(4, true, DisplayName = "Page 5 (with annotations)")] - [DataRow(5, true, DisplayName = "Page 6 (with annotations)")] - [DataRow(6, true, DisplayName = "Page 7 (with annotations)")] - [DataRow(7, true, DisplayName = "Page 8 (with annotations)")] - [DataRow(8, true, DisplayName = "Page 9 (with annotations)")] - [DataRow(9, true, DisplayName = "Page 10 (with annotations)")] - [DataRow(10, true, DisplayName = "Page 11 (with annotations)")] - [DataRow(11, true, DisplayName = "Page 12 (with annotations)")] - [DataRow(12, true, DisplayName = "Page 13 (with annotations)")] - [DataRow(13, true, DisplayName = "Page 14 (with annotations)")] - [DataRow(14, true, DisplayName = "Page 15 (with annotations)")] - [DataRow(15, true, DisplayName = "Page 16 (with annotations)")] - [DataRow(16, true, DisplayName = "Page 17 (with annotations)")] - [DataRow(17, true, DisplayName = "Page 18 (with annotations)")] - [DataRow(18, true, DisplayName = "Page 19 (with annotations)")] - [DataRow(19, true, DisplayName = "Page 20 (with annotations)")] - public void SaveJpegPageNumber(int page, bool withAnnotations = false) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{page}{(withAnnotations ? "_ANNOT" : string.Empty)}.jpg"); - - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "Wikimedia_Commons_web.pdf")); - using var outputStream = CreateOutputStream(expectedPath); - - SaveJpeg(outputStream, inputStream, page: page, options: new(Dpi: 40, WithAnnotations: withAnnotations)); - - CompareStreams(expectedPath, outputStream); - } - - [TestMethod] - [DataRow(false, DisplayName = "Without annotations")] - [DataRow(true, DisplayName = "With annotations")] - public void SaveJpegPages(bool withAnnotations = false) - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "Wikimedia_Commons_web.pdf")); - - int page = 0; - - foreach (var image in ToImages(inputStream, options: new(Dpi: 40, WithAnnotations: withAnnotations))) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{page}{(withAnnotations ? "_ANNOT" : string.Empty)}.jpg"); - - using var outputStream = CreateOutputStream(expectedPath); - image.Encode(outputStream, SKEncodedImageFormat.Jpeg, 100); - - CompareStreams(expectedPath, outputStream); - - page++; - } - } + [TestMethod] + [DataRow(0, DisplayName = "Page 1")] + [DataRow(1, DisplayName = "Page 2")] + [DataRow(2, DisplayName = "Page 3")] + [DataRow(3, DisplayName = "Page 4")] + [DataRow(4, DisplayName = "Page 5")] + [DataRow(5, DisplayName = "Page 6")] + [DataRow(6, DisplayName = "Page 7")] + [DataRow(7, DisplayName = "Page 8")] + [DataRow(8, DisplayName = "Page 9")] + [DataRow(9, DisplayName = "Page 10")] + [DataRow(10, DisplayName = "Page 11")] + [DataRow(11, DisplayName = "Page 12")] + [DataRow(12, DisplayName = "Page 13")] + [DataRow(13, DisplayName = "Page 14")] + [DataRow(14, DisplayName = "Page 15")] + [DataRow(15, DisplayName = "Page 16")] + [DataRow(16, DisplayName = "Page 17")] + [DataRow(17, DisplayName = "Page 18")] + [DataRow(18, DisplayName = "Page 19")] + [DataRow(19, DisplayName = "Page 20")] + [DataRow(0, true, DisplayName = "Page 1 (with annotations)")] + [DataRow(1, true, DisplayName = "Page 2 (with annotations)")] + [DataRow(2, true, DisplayName = "Page 3 (with annotations)")] + [DataRow(3, true, DisplayName = "Page 4 (with annotations)")] + [DataRow(4, true, DisplayName = "Page 5 (with annotations)")] + [DataRow(5, true, DisplayName = "Page 6 (with annotations)")] + [DataRow(6, true, DisplayName = "Page 7 (with annotations)")] + [DataRow(7, true, DisplayName = "Page 8 (with annotations)")] + [DataRow(8, true, DisplayName = "Page 9 (with annotations)")] + [DataRow(9, true, DisplayName = "Page 10 (with annotations)")] + [DataRow(10, true, DisplayName = "Page 11 (with annotations)")] + [DataRow(11, true, DisplayName = "Page 12 (with annotations)")] + [DataRow(12, true, DisplayName = "Page 13 (with annotations)")] + [DataRow(13, true, DisplayName = "Page 14 (with annotations)")] + [DataRow(14, true, DisplayName = "Page 15 (with annotations)")] + [DataRow(15, true, DisplayName = "Page 16 (with annotations)")] + [DataRow(16, true, DisplayName = "Page 17 (with annotations)")] + [DataRow(17, true, DisplayName = "Page 18 (with annotations)")] + [DataRow(18, true, DisplayName = "Page 19 (with annotations)")] + [DataRow(19, true, DisplayName = "Page 20 (with annotations)")] + public void SaveJpegPageNumber(int page, bool withAnnotations = false) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{page}{(withAnnotations ? "_ANNOT" : string.Empty)}.jpg"); + + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "Wikimedia_Commons_web.pdf")); + using var outputStream = CreateOutputStream(expectedPath); + + SaveJpeg(outputStream, inputStream, page: page, options: new(Dpi: 40, WithAnnotations: withAnnotations)); + + CompareStreams(expectedPath, outputStream); + } + + [TestMethod] + [DataRow(false, DisplayName = "Without annotations")] + [DataRow(true, DisplayName = "With annotations")] + public void SaveJpegPages(bool withAnnotations = false) + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "Wikimedia_Commons_web.pdf")); + + int page = 0; + + foreach (var image in ToImages(inputStream, options: new(Dpi: 40, WithAnnotations: withAnnotations))) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{page}{(withAnnotations ? "_ANNOT" : string.Empty)}.jpg"); + + using var outputStream = CreateOutputStream(expectedPath); + image.Encode(outputStream, SKEncodedImageFormat.Jpeg, 100); + + CompareStreams(expectedPath, outputStream); + + page++; + } + } #if NET6_0_OR_GREATER [TestMethod] @@ -312,57 +312,57 @@ public async Task SaveJpegPagesAsync(bool withAnnotations = false) } #endif - [TestMethod] - [DataRow(10, DisplayName = "10 DPI")] - [DataRow(30, DisplayName = "30 DPI")] - [DataRow(100, DisplayName = "100 DPI")] - [DataRow(300, DisplayName = "300 DPI")] - [DataRow(600, DisplayName = "600 DPI")] - [DataRow(1200, DisplayName = "1200 DPI")] - [DataRow(10, true, DisplayName = "10 DPI (with annotations)")] - [DataRow(30, true, DisplayName = "30 DPI (with annotations)")] - [DataRow(100, true, DisplayName = "100 DPI (with annotations)")] - [DataRow(300, true, DisplayName = "300 DPI (with annotations)")] - [DataRow(600, true, DisplayName = "600 DPI (with annotations)")] - [DataRow(1200, true, DisplayName = "1200 DPI (with annotations)")] - public void SavePngDpi(int dpi, bool withAnnotations = false) - { - using var pdfStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - using var image = ToImage(pdfStream, options: new(Dpi: dpi, WithAnnotations: withAnnotations)); - - using var pdfStream2 = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - using var image2 = ToImage(pdfStream2, options: new(Dpi: 300, WithAnnotations: withAnnotations)); - - Assert.IsNotNull(image); - Assert.IsTrue(Math.Abs(image.Width - image2.Width * (dpi / 300.0)) < 3); - Assert.IsTrue(Math.Abs(image.Height - image2.Height * (dpi / 300.0)) < 3); - } - - [TestMethod] - [DataRow(10, DisplayName = "10 DPI")] - [DataRow(30, DisplayName = "30 DPI")] - [DataRow(100, DisplayName = "100 DPI")] - [DataRow(300, DisplayName = "300 DPI")] - [DataRow(600, DisplayName = "600 DPI")] - [DataRow(1200, DisplayName = "1200 DPI")] - [DataRow(10, true, DisplayName = "10 DPI (with annotations)")] - [DataRow(30, true, DisplayName = "30 DPI (with annotations)")] - [DataRow(100, true, DisplayName = "100 DPI (with annotations)")] - [DataRow(300, true, DisplayName = "300 DPI (with annotations)")] - [DataRow(600, true, DisplayName = "600 DPI (with annotations)")] - [DataRow(1200, true, DisplayName = "1200 DPI (with annotations)")] - public void SavePngDpiImages(int dpi, bool withAnnotations = false) - { - using var pdfStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - using var image = ToImages(pdfStream, options: new(Dpi: dpi, WithAnnotations: withAnnotations)).Single(); - - using var pdfStream2 = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - using var image2 = ToImages(pdfStream2, options: new(Dpi: 300, WithAnnotations: withAnnotations)).Single(); - - Assert.IsNotNull(image); - Assert.IsTrue(Math.Abs(image.Width - image2.Width * (dpi / 300.0)) < 3); - Assert.IsTrue(Math.Abs(image.Height - image2.Height * (dpi / 300.0)) < 3); - } + [TestMethod] + [DataRow(10, DisplayName = "10 DPI")] + [DataRow(30, DisplayName = "30 DPI")] + [DataRow(100, DisplayName = "100 DPI")] + [DataRow(300, DisplayName = "300 DPI")] + [DataRow(600, DisplayName = "600 DPI")] + [DataRow(1200, DisplayName = "1200 DPI")] + [DataRow(10, true, DisplayName = "10 DPI (with annotations)")] + [DataRow(30, true, DisplayName = "30 DPI (with annotations)")] + [DataRow(100, true, DisplayName = "100 DPI (with annotations)")] + [DataRow(300, true, DisplayName = "300 DPI (with annotations)")] + [DataRow(600, true, DisplayName = "600 DPI (with annotations)")] + [DataRow(1200, true, DisplayName = "1200 DPI (with annotations)")] + public void SavePngDpi(int dpi, bool withAnnotations = false) + { + using var pdfStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + using var image = ToImage(pdfStream, options: new(Dpi: dpi, WithAnnotations: withAnnotations)); + + using var pdfStream2 = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + using var image2 = ToImage(pdfStream2, options: new(Dpi: 300, WithAnnotations: withAnnotations)); + + Assert.IsNotNull(image); + Assert.IsTrue(Math.Abs(image.Width - image2.Width * (dpi / 300.0)) < 3); + Assert.IsTrue(Math.Abs(image.Height - image2.Height * (dpi / 300.0)) < 3); + } + + [TestMethod] + [DataRow(10, DisplayName = "10 DPI")] + [DataRow(30, DisplayName = "30 DPI")] + [DataRow(100, DisplayName = "100 DPI")] + [DataRow(300, DisplayName = "300 DPI")] + [DataRow(600, DisplayName = "600 DPI")] + [DataRow(1200, DisplayName = "1200 DPI")] + [DataRow(10, true, DisplayName = "10 DPI (with annotations)")] + [DataRow(30, true, DisplayName = "30 DPI (with annotations)")] + [DataRow(100, true, DisplayName = "100 DPI (with annotations)")] + [DataRow(300, true, DisplayName = "300 DPI (with annotations)")] + [DataRow(600, true, DisplayName = "600 DPI (with annotations)")] + [DataRow(1200, true, DisplayName = "1200 DPI (with annotations)")] + public void SavePngDpiImages(int dpi, bool withAnnotations = false) + { + using var pdfStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + using var image = ToImages(pdfStream, options: new(Dpi: dpi, WithAnnotations: withAnnotations)).Single(); + + using var pdfStream2 = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + using var image2 = ToImages(pdfStream2, options: new(Dpi: 300, WithAnnotations: withAnnotations)).Single(); + + Assert.IsNotNull(image); + Assert.IsTrue(Math.Abs(image.Width - image2.Width * (dpi / 300.0)) < 3); + Assert.IsTrue(Math.Abs(image.Height - image2.Height * (dpi / 300.0)) < 3); + } #if NET6_0_OR_GREATER [TestMethod] @@ -389,15 +389,15 @@ public async Task SavePngDpiImagesAsync(int dpi, bool withAnnotations = false) } #endif - [TestMethod] - [DataRow("SocialPreview.pdf", 1)] - [DataRow("hundesteuer-anmeldung.pdf", 3)] - [DataRow("Wikimedia_Commons_web.pdf", 20)] - public void GetPageCountTest(string pdfFileName, int expectedPageCount) - { - using var pdfStream = GetInputStream(Path.Combine("..", "Assets", pdfFileName)); - Assert.AreEqual(expectedPageCount, GetPageCount(pdfStream), $"The expected and actual page count for the file {pdfFileName} are not equal."); - } + [TestMethod] + [DataRow("SocialPreview.pdf", 1)] + [DataRow("hundesteuer-anmeldung.pdf", 3)] + [DataRow("Wikimedia_Commons_web.pdf", 20)] + public void GetPageCountTest(string pdfFileName, int expectedPageCount) + { + using var pdfStream = GetInputStream(Path.Combine("..", "Assets", pdfFileName)); + Assert.AreEqual(expectedPageCount, GetPageCount(pdfStream), $"The expected and actual page count for the file {pdfFileName} are not equal."); + } #if NET6_0_OR_GREATER [TestMethod] @@ -451,5 +451,5 @@ await Assert.ThrowsExceptionAsync(async () => }); } #endif - } + } } \ No newline at end of file diff --git a/src/Tests/Compatibility/ApiTests.cs b/src/Tests/Compatibility/ApiTests.cs index 58521503..c9f0da72 100644 --- a/src/Tests/Compatibility/ApiTests.cs +++ b/src/Tests/Compatibility/ApiTests.cs @@ -9,80 +9,80 @@ namespace Tests.Compatibility { - [TestClass] - public class ApiTests : TestBase - { - [TestMethod] - public void SaveWebpStringNullException() - { + [TestClass] + public class ApiTests : TestBase + { + [TestMethod] + public void SaveWebpStringNullException() + { Assert.ThrowsException(() => SaveWebp((string)null!, (string)null!)); } - [TestMethod] - public void SaveWebpStreamNullException() - { - Assert.ThrowsException(() => SaveWebp((Stream)null!, (string)null!)); - } - - [TestMethod] - public void SavePngStringNullException() - { - Assert.ThrowsException(() => SavePng((string)null!, (string)null!)); - } - - [TestMethod] - public void SavePngStreamNullException() - { - Assert.ThrowsException(() => SavePng((Stream)null!, (string)null!)); - } - - [TestMethod] - public void SaveJpegStringNullException() - { - Assert.ThrowsException(() => SaveJpeg((string)null!, (string)null!)); - } - - [TestMethod] - public void SaveJpegStreamNullException() - { - Assert.ThrowsException(() => SaveJpeg((Stream)null!, (string)null!)); - } - - [TestMethod] - public void ToImagePdfStringNullException() - { - Assert.ThrowsException(() => ToImage((string)null!)); - } - - [TestMethod] - public void ToImagePdfArrayNullException() - { - Assert.ThrowsException(() => ToImage((byte[])null!)); - } - - [TestMethod] - public void ToImagePdfStreamNullException() - { - Assert.ThrowsException(() => ToImage((Stream)null!)); - } - - [TestMethod] - public void ToImagesPdfStringNullException() - { - Assert.ThrowsException(() => ToImages((string)null!).ToList()); - } - - [TestMethod] - public void ToImagesPdfArrayNullException() - { - Assert.ThrowsException(() => ToImages((byte[])null!).ToList()); - } - - [TestMethod] - public void ToImagesPdfStreamNullException() - { - Assert.ThrowsException(() => ToImages((Stream)null!).ToList()); - } + [TestMethod] + public void SaveWebpStreamNullException() + { + Assert.ThrowsException(() => SaveWebp((Stream)null!, (string)null!)); + } + + [TestMethod] + public void SavePngStringNullException() + { + Assert.ThrowsException(() => SavePng((string)null!, (string)null!)); + } + + [TestMethod] + public void SavePngStreamNullException() + { + Assert.ThrowsException(() => SavePng((Stream)null!, (string)null!)); + } + + [TestMethod] + public void SaveJpegStringNullException() + { + Assert.ThrowsException(() => SaveJpeg((string)null!, (string)null!)); + } + + [TestMethod] + public void SaveJpegStreamNullException() + { + Assert.ThrowsException(() => SaveJpeg((Stream)null!, (string)null!)); + } + + [TestMethod] + public void ToImagePdfStringNullException() + { + Assert.ThrowsException(() => ToImage((string)null!)); + } + + [TestMethod] + public void ToImagePdfArrayNullException() + { + Assert.ThrowsException(() => ToImage((byte[])null!)); + } + + [TestMethod] + public void ToImagePdfStreamNullException() + { + Assert.ThrowsException(() => ToImage((Stream)null!)); + } + + [TestMethod] + public void ToImagesPdfStringNullException() + { + Assert.ThrowsException(() => ToImages((string)null!).ToList()); + } + + [TestMethod] + public void ToImagesPdfArrayNullException() + { + Assert.ThrowsException(() => ToImages((byte[])null!).ToList()); + } + + [TestMethod] + public void ToImagesPdfStreamNullException() + { + Assert.ThrowsException(() => ToImages((Stream)null!).ToList()); + } #if NET6_0_OR_GREATER [TestMethod] @@ -119,74 +119,74 @@ await Assert.ThrowsExceptionAsync(async () => } #endif - [TestMethod] - public void ToImageStreamLeaveOpenDefault() - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - Assert.IsTrue(inputStream.CanRead); - - ToImage(inputStream); - Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling the default overload."); - } - - [TestMethod] - public void ToImageStreamLeaveOpenFalse() - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - Assert.IsTrue(inputStream.CanRead); - - ToImage(inputStream, false); - Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling leaveOpen with false."); - } - - [TestMethod] - public void ToImageStreamLeaveOpenTrue() - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - Assert.IsTrue(inputStream.CanRead); - - ToImage(inputStream, true); - Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); - } - - [TestMethod] - public void ToImagesStreamLeaveOpenDefault() - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - Assert.IsTrue(inputStream.CanRead); - - var result = ToImages(inputStream); - Assert.IsTrue(inputStream.CanRead, "The stream should be open as long as the iterator is not used yet."); - - foreach (var _ in result) ; - Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling the default overload."); - } - - [TestMethod] - public void ToImagesStreamLeaveOpenFalse() - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - Assert.IsTrue(inputStream.CanRead); - - var result = ToImages(inputStream, false); - Assert.IsTrue(inputStream.CanRead, "The stream should be open as long as the iterator is not used yet."); - - foreach (var _ in result) ; - Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling leaveOpen with false."); - } - - [TestMethod] - public void ToImagesStreamLeaveOpenTrue() - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - Assert.IsTrue(inputStream.CanRead); - - var result = ToImages(inputStream, true); - Assert.IsTrue(inputStream.CanRead, "The stream should be open as long as the iterator is not used yet."); - - foreach (var _ in result) ; - Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); - } + [TestMethod] + public void ToImageStreamLeaveOpenDefault() + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + Assert.IsTrue(inputStream.CanRead); + + ToImage(inputStream); + Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling the default overload."); + } + + [TestMethod] + public void ToImageStreamLeaveOpenFalse() + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + Assert.IsTrue(inputStream.CanRead); + + ToImage(inputStream, false); + Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling leaveOpen with false."); + } + + [TestMethod] + public void ToImageStreamLeaveOpenTrue() + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + Assert.IsTrue(inputStream.CanRead); + + ToImage(inputStream, true); + Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); + } + + [TestMethod] + public void ToImagesStreamLeaveOpenDefault() + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + Assert.IsTrue(inputStream.CanRead); + + var result = ToImages(inputStream); + Assert.IsTrue(inputStream.CanRead, "The stream should be open as long as the iterator is not used yet."); + + foreach (var _ in result) ; + Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling the default overload."); + } + + [TestMethod] + public void ToImagesStreamLeaveOpenFalse() + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + Assert.IsTrue(inputStream.CanRead); + + var result = ToImages(inputStream, false); + Assert.IsTrue(inputStream.CanRead, "The stream should be open as long as the iterator is not used yet."); + + foreach (var _ in result) ; + Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling leaveOpen with false."); + } + + [TestMethod] + public void ToImagesStreamLeaveOpenTrue() + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + Assert.IsTrue(inputStream.CanRead); + + var result = ToImages(inputStream, true); + Assert.IsTrue(inputStream.CanRead, "The stream should be open as long as the iterator is not used yet."); + + foreach (var _ in result) ; + Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); + } #if NET6_0_OR_GREATER [TestMethod] @@ -229,31 +229,31 @@ public async Task ToImagesAsyncStreamLeaveOpenTrue() } #endif - [TestMethod] - public void StreamMultipleCallsLeaveOpen() - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); - Assert.IsTrue(inputStream.CanRead); + [TestMethod] + public void StreamMultipleCallsLeaveOpen() + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "SocialPreview.pdf")); + Assert.IsTrue(inputStream.CanRead); PDFtoImage.Conversion.GetPageCount(inputStream, true); - Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); + Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); PDFtoImage.Conversion.GetPageSizes(inputStream, true); - Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); + Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); - var image1 = ToImage(inputStream, true); - Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); + var image1 = ToImage(inputStream, true); + Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); - var image2 = ToImage(inputStream, true); - Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); + var image2 = ToImage(inputStream, true); + Assert.IsTrue(inputStream.CanRead, "The stream should be open when calling leaveOpen with true."); - Assert.IsTrue(image1.ByteCount > 0, "The rendered image should have content."); - Assert.AreEqual(image1.ByteCount, image2.ByteCount, "Both images should be equal (in byte size)."); + Assert.IsTrue(image1.ByteCount > 0, "The rendered image should have content."); + Assert.AreEqual(image1.ByteCount, image2.ByteCount, "Both images should be equal (in byte size)."); PDFtoImage.Conversion.GetPageSizes(inputStream, false); - Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling leaveOpen with false."); + Assert.IsFalse(inputStream.CanRead, "The stream should be closed when calling leaveOpen with false."); - Assert.ThrowsException(() => PDFtoImage.Conversion.GetPageCount(inputStream, false), "The stream should be closed and throw an exception."); - } - } + Assert.ThrowsException(() => PDFtoImage.Conversion.GetPageCount(inputStream, false), "The stream should be closed and throw an exception."); + } + } } \ No newline at end of file diff --git a/src/Tests/Compatibility/AspectRatioTests.cs b/src/Tests/Compatibility/AspectRatioTests.cs index 08e062f2..f9c70cb7 100644 --- a/src/Tests/Compatibility/AspectRatioTests.cs +++ b/src/Tests/Compatibility/AspectRatioTests.cs @@ -6,408 +6,408 @@ namespace Tests.Compatibility { - [TestClass] - public class AspectRatioTests : TestBase - { - [TestMethod] - [DataRow("hundesteuer-anmeldung.pdf")] - [DataRow("hundesteuer-anmeldung.pdf", 100, null, null)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, null, null)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, null, null)] - [DataRow("hundesteuer-anmeldung.pdf", null, 100, null)] - [DataRow("hundesteuer-anmeldung.pdf", null, 1000, null)] - [DataRow("hundesteuer-anmeldung.pdf", null, 2000, null)] - [DataRow("hundesteuer-anmeldung.pdf", 100, 100, null)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, null)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, null)] - [DataRow("hundesteuer-anmeldung.pdf", null, null, 96)] - [DataRow("hundesteuer-anmeldung.pdf", null, null, 300)] - [DataRow("hundesteuer-anmeldung.pdf", null, null, 600)] - [DataRow("hundesteuer-anmeldung.pdf", 100, null, 96)] - [DataRow("hundesteuer-anmeldung.pdf", 100, null, 300)] - [DataRow("hundesteuer-anmeldung.pdf", 100, null, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, null, 96)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, null, 300)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, null, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, null, 96)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, null, 300)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, null, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", null, 100, 96)] - [DataRow("hundesteuer-anmeldung.pdf", null, 100, 300)] - [DataRow("hundesteuer-anmeldung.pdf", null, 100, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", null, 1000, 96)] - [DataRow("hundesteuer-anmeldung.pdf", null, 1000, 300)] - [DataRow("hundesteuer-anmeldung.pdf", null, 1000, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", null, 2000, 96)] - [DataRow("hundesteuer-anmeldung.pdf", null, 2000, 300)] - [DataRow("hundesteuer-anmeldung.pdf", null, 2000, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", 100, 100, 96)] - [DataRow("hundesteuer-anmeldung.pdf", 100, 100, 300)] - [DataRow("hundesteuer-anmeldung.pdf", 100, 100, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, 96)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, 300)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, 96)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, 300)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, 1200)] + [TestClass] + public class AspectRatioTests : TestBase + { + [TestMethod] + [DataRow("hundesteuer-anmeldung.pdf")] + [DataRow("hundesteuer-anmeldung.pdf", 100, null, null)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, null, null)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, null, null)] + [DataRow("hundesteuer-anmeldung.pdf", null, 100, null)] + [DataRow("hundesteuer-anmeldung.pdf", null, 1000, null)] + [DataRow("hundesteuer-anmeldung.pdf", null, 2000, null)] + [DataRow("hundesteuer-anmeldung.pdf", 100, 100, null)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, null)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, null)] + [DataRow("hundesteuer-anmeldung.pdf", null, null, 96)] + [DataRow("hundesteuer-anmeldung.pdf", null, null, 300)] + [DataRow("hundesteuer-anmeldung.pdf", null, null, 600)] + [DataRow("hundesteuer-anmeldung.pdf", 100, null, 96)] + [DataRow("hundesteuer-anmeldung.pdf", 100, null, 300)] + [DataRow("hundesteuer-anmeldung.pdf", 100, null, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, null, 96)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, null, 300)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, null, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, null, 96)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, null, 300)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, null, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", null, 100, 96)] + [DataRow("hundesteuer-anmeldung.pdf", null, 100, 300)] + [DataRow("hundesteuer-anmeldung.pdf", null, 100, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", null, 1000, 96)] + [DataRow("hundesteuer-anmeldung.pdf", null, 1000, 300)] + [DataRow("hundesteuer-anmeldung.pdf", null, 1000, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", null, 2000, 96)] + [DataRow("hundesteuer-anmeldung.pdf", null, 2000, 300)] + [DataRow("hundesteuer-anmeldung.pdf", null, 2000, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", 100, 100, 96)] + [DataRow("hundesteuer-anmeldung.pdf", 100, 100, 300)] + [DataRow("hundesteuer-anmeldung.pdf", 100, 100, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, 96)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, 300)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, 96)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, 300)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, 1200)] - [DataRow("SocialPreview.pdf")] - [DataRow("SocialPreview.pdf", 100, null, null)] - [DataRow("SocialPreview.pdf", 1000, null, null)] - [DataRow("SocialPreview.pdf", 2000, null, null)] - [DataRow("SocialPreview.pdf", null, 100, null)] - [DataRow("SocialPreview.pdf", null, 1000, null)] - [DataRow("SocialPreview.pdf", null, 2000, null)] - [DataRow("SocialPreview.pdf", 100, 100, null)] - [DataRow("SocialPreview.pdf", 1000, 1000, null)] - [DataRow("SocialPreview.pdf", 2000, 2000, null)] - [DataRow("SocialPreview.pdf", null, null, 96)] - [DataRow("SocialPreview.pdf", null, null, 300)] - [DataRow("SocialPreview.pdf", null, null, 600)] - [DataRow("SocialPreview.pdf", 100, null, 96)] - [DataRow("SocialPreview.pdf", 100, null, 300)] - [DataRow("SocialPreview.pdf", 100, null, 1200)] - [DataRow("SocialPreview.pdf", 1000, null, 96)] - [DataRow("SocialPreview.pdf", 1000, null, 300)] - [DataRow("SocialPreview.pdf", 1000, null, 1200)] - [DataRow("SocialPreview.pdf", 2000, null, 96)] - [DataRow("SocialPreview.pdf", 2000, null, 300)] - [DataRow("SocialPreview.pdf", 2000, null, 1200)] - [DataRow("SocialPreview.pdf", null, 100, 96)] - [DataRow("SocialPreview.pdf", null, 100, 300)] - [DataRow("SocialPreview.pdf", null, 100, 1200)] - [DataRow("SocialPreview.pdf", null, 1000, 96)] - [DataRow("SocialPreview.pdf", null, 1000, 300)] - [DataRow("SocialPreview.pdf", null, 1000, 1200)] - [DataRow("SocialPreview.pdf", null, 2000, 96)] - [DataRow("SocialPreview.pdf", null, 2000, 300)] - [DataRow("SocialPreview.pdf", null, 2000, 1200)] - [DataRow("SocialPreview.pdf", 100, 100, 96)] - [DataRow("SocialPreview.pdf", 100, 100, 300)] - [DataRow("SocialPreview.pdf", 100, 100, 1200)] - [DataRow("SocialPreview.pdf", 1000, 1000, 96)] - [DataRow("SocialPreview.pdf", 1000, 1000, 300)] - [DataRow("SocialPreview.pdf", 1000, 1000, 1200)] - [DataRow("SocialPreview.pdf", 2000, 2000, 96)] - [DataRow("SocialPreview.pdf", 2000, 2000, 300)] - [DataRow("SocialPreview.pdf", 2000, 2000, 1200)] + [DataRow("SocialPreview.pdf")] + [DataRow("SocialPreview.pdf", 100, null, null)] + [DataRow("SocialPreview.pdf", 1000, null, null)] + [DataRow("SocialPreview.pdf", 2000, null, null)] + [DataRow("SocialPreview.pdf", null, 100, null)] + [DataRow("SocialPreview.pdf", null, 1000, null)] + [DataRow("SocialPreview.pdf", null, 2000, null)] + [DataRow("SocialPreview.pdf", 100, 100, null)] + [DataRow("SocialPreview.pdf", 1000, 1000, null)] + [DataRow("SocialPreview.pdf", 2000, 2000, null)] + [DataRow("SocialPreview.pdf", null, null, 96)] + [DataRow("SocialPreview.pdf", null, null, 300)] + [DataRow("SocialPreview.pdf", null, null, 600)] + [DataRow("SocialPreview.pdf", 100, null, 96)] + [DataRow("SocialPreview.pdf", 100, null, 300)] + [DataRow("SocialPreview.pdf", 100, null, 1200)] + [DataRow("SocialPreview.pdf", 1000, null, 96)] + [DataRow("SocialPreview.pdf", 1000, null, 300)] + [DataRow("SocialPreview.pdf", 1000, null, 1200)] + [DataRow("SocialPreview.pdf", 2000, null, 96)] + [DataRow("SocialPreview.pdf", 2000, null, 300)] + [DataRow("SocialPreview.pdf", 2000, null, 1200)] + [DataRow("SocialPreview.pdf", null, 100, 96)] + [DataRow("SocialPreview.pdf", null, 100, 300)] + [DataRow("SocialPreview.pdf", null, 100, 1200)] + [DataRow("SocialPreview.pdf", null, 1000, 96)] + [DataRow("SocialPreview.pdf", null, 1000, 300)] + [DataRow("SocialPreview.pdf", null, 1000, 1200)] + [DataRow("SocialPreview.pdf", null, 2000, 96)] + [DataRow("SocialPreview.pdf", null, 2000, 300)] + [DataRow("SocialPreview.pdf", null, 2000, 1200)] + [DataRow("SocialPreview.pdf", 100, 100, 96)] + [DataRow("SocialPreview.pdf", 100, 100, 300)] + [DataRow("SocialPreview.pdf", 100, 100, 1200)] + [DataRow("SocialPreview.pdf", 1000, 1000, 96)] + [DataRow("SocialPreview.pdf", 1000, 1000, 300)] + [DataRow("SocialPreview.pdf", 1000, 1000, 1200)] + [DataRow("SocialPreview.pdf", 2000, 2000, 96)] + [DataRow("SocialPreview.pdf", 2000, 2000, 300)] + [DataRow("SocialPreview.pdf", 2000, 2000, 1200)] - [DataRow("Wikimedia_Commons_web.pdf")] - [DataRow("Wikimedia_Commons_web.pdf", 100, null, null)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, null, null)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, null, null)] - [DataRow("Wikimedia_Commons_web.pdf", null, 100, null)] - [DataRow("Wikimedia_Commons_web.pdf", null, 1000, null)] - [DataRow("Wikimedia_Commons_web.pdf", null, 2000, null)] - [DataRow("Wikimedia_Commons_web.pdf", 100, 100, null)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, null)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, null)] - [DataRow("Wikimedia_Commons_web.pdf", null, null, 96)] - [DataRow("Wikimedia_Commons_web.pdf", null, null, 300)] - [DataRow("Wikimedia_Commons_web.pdf", null, null, 600)] - [DataRow("Wikimedia_Commons_web.pdf", 100, null, 96)] - [DataRow("Wikimedia_Commons_web.pdf", 100, null, 300)] - [DataRow("Wikimedia_Commons_web.pdf", 100, null, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, null, 96)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, null, 300)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, null, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, null, 96)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, null, 300)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, null, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", null, 100, 96)] - [DataRow("Wikimedia_Commons_web.pdf", null, 100, 300)] - [DataRow("Wikimedia_Commons_web.pdf", null, 100, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", null, 1000, 96)] - [DataRow("Wikimedia_Commons_web.pdf", null, 1000, 300)] - [DataRow("Wikimedia_Commons_web.pdf", null, 1000, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", null, 2000, 96)] - [DataRow("Wikimedia_Commons_web.pdf", null, 2000, 300)] - [DataRow("Wikimedia_Commons_web.pdf", null, 2000, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", 100, 100, 96)] - [DataRow("Wikimedia_Commons_web.pdf", 100, 100, 300)] - [DataRow("Wikimedia_Commons_web.pdf", 100, 100, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, 96)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, 300)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, 96)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, 300)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, 1200)] - public void WithoutAspectRatio(string fileName, int? width = null, int? height = null, int? dpi = null) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "AspectRatio", GetExpectedFilename(fileName, "jpg", width, height, dpi, false)); + [DataRow("Wikimedia_Commons_web.pdf")] + [DataRow("Wikimedia_Commons_web.pdf", 100, null, null)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, null, null)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, null, null)] + [DataRow("Wikimedia_Commons_web.pdf", null, 100, null)] + [DataRow("Wikimedia_Commons_web.pdf", null, 1000, null)] + [DataRow("Wikimedia_Commons_web.pdf", null, 2000, null)] + [DataRow("Wikimedia_Commons_web.pdf", 100, 100, null)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, null)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, null)] + [DataRow("Wikimedia_Commons_web.pdf", null, null, 96)] + [DataRow("Wikimedia_Commons_web.pdf", null, null, 300)] + [DataRow("Wikimedia_Commons_web.pdf", null, null, 600)] + [DataRow("Wikimedia_Commons_web.pdf", 100, null, 96)] + [DataRow("Wikimedia_Commons_web.pdf", 100, null, 300)] + [DataRow("Wikimedia_Commons_web.pdf", 100, null, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, null, 96)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, null, 300)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, null, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, null, 96)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, null, 300)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, null, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", null, 100, 96)] + [DataRow("Wikimedia_Commons_web.pdf", null, 100, 300)] + [DataRow("Wikimedia_Commons_web.pdf", null, 100, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", null, 1000, 96)] + [DataRow("Wikimedia_Commons_web.pdf", null, 1000, 300)] + [DataRow("Wikimedia_Commons_web.pdf", null, 1000, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", null, 2000, 96)] + [DataRow("Wikimedia_Commons_web.pdf", null, 2000, 300)] + [DataRow("Wikimedia_Commons_web.pdf", null, 2000, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", 100, 100, 96)] + [DataRow("Wikimedia_Commons_web.pdf", 100, 100, 300)] + [DataRow("Wikimedia_Commons_web.pdf", 100, 100, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, 96)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, 300)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, 96)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, 300)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, 1200)] + public void WithoutAspectRatio(string fileName, int? width = null, int? height = null, int? dpi = null) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "AspectRatio", GetExpectedFilename(fileName, "jpg", width, height, dpi, false)); - using var inputStream = GetInputStream(Path.Combine("..", "Assets", fileName)); - using var outputStream = CreateOutputStream(expectedPath); + using var inputStream = GetInputStream(Path.Combine("..", "Assets", fileName)); + using var outputStream = CreateOutputStream(expectedPath); - if (dpi != null) - SaveJpeg(outputStream, inputStream, width: width, height: height, withAnnotations: true, withFormFill: true, withAspectRatio: false, dpi: dpi.Value); - else - SaveJpeg(outputStream, inputStream, width: width, height: height, withAnnotations: true, withFormFill: true, withAspectRatio: false); + if (dpi != null) + SaveJpeg(outputStream, inputStream, width: width, height: height, withAnnotations: true, withFormFill: true, withAspectRatio: false, dpi: dpi.Value); + else + SaveJpeg(outputStream, inputStream, width: width, height: height, withAnnotations: true, withFormFill: true, withAspectRatio: false); - CompareStreams(expectedPath, outputStream); - } + CompareStreams(expectedPath, outputStream); + } - [TestMethod] - [DataRow("hundesteuer-anmeldung.pdf")] - [DataRow("hundesteuer-anmeldung.pdf", 100, null, null)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, null, null)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, null, null)] - [DataRow("hundesteuer-anmeldung.pdf", null, 100, null)] - [DataRow("hundesteuer-anmeldung.pdf", null, 1000, null)] - [DataRow("hundesteuer-anmeldung.pdf", null, 2000, null)] - [DataRow("hundesteuer-anmeldung.pdf", 100, 100, null)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, null)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, null)] - [DataRow("hundesteuer-anmeldung.pdf", null, null, 96)] - [DataRow("hundesteuer-anmeldung.pdf", null, null, 300)] - [DataRow("hundesteuer-anmeldung.pdf", null, null, 600)] - [DataRow("hundesteuer-anmeldung.pdf", 100, null, 96)] - [DataRow("hundesteuer-anmeldung.pdf", 100, null, 300)] - [DataRow("hundesteuer-anmeldung.pdf", 100, null, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, null, 96)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, null, 300)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, null, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, null, 96)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, null, 300)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, null, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", null, 100, 96)] - [DataRow("hundesteuer-anmeldung.pdf", null, 100, 300)] - [DataRow("hundesteuer-anmeldung.pdf", null, 100, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", null, 1000, 96)] - [DataRow("hundesteuer-anmeldung.pdf", null, 1000, 300)] - [DataRow("hundesteuer-anmeldung.pdf", null, 1000, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", null, 2000, 96)] - [DataRow("hundesteuer-anmeldung.pdf", null, 2000, 300)] - [DataRow("hundesteuer-anmeldung.pdf", null, 2000, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", 100, 100, 96)] - [DataRow("hundesteuer-anmeldung.pdf", 100, 100, 300)] - [DataRow("hundesteuer-anmeldung.pdf", 100, 100, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, 96)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, 300)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, 1200)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, 96)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, 300)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, 1200)] + [TestMethod] + [DataRow("hundesteuer-anmeldung.pdf")] + [DataRow("hundesteuer-anmeldung.pdf", 100, null, null)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, null, null)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, null, null)] + [DataRow("hundesteuer-anmeldung.pdf", null, 100, null)] + [DataRow("hundesteuer-anmeldung.pdf", null, 1000, null)] + [DataRow("hundesteuer-anmeldung.pdf", null, 2000, null)] + [DataRow("hundesteuer-anmeldung.pdf", 100, 100, null)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, null)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, null)] + [DataRow("hundesteuer-anmeldung.pdf", null, null, 96)] + [DataRow("hundesteuer-anmeldung.pdf", null, null, 300)] + [DataRow("hundesteuer-anmeldung.pdf", null, null, 600)] + [DataRow("hundesteuer-anmeldung.pdf", 100, null, 96)] + [DataRow("hundesteuer-anmeldung.pdf", 100, null, 300)] + [DataRow("hundesteuer-anmeldung.pdf", 100, null, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, null, 96)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, null, 300)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, null, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, null, 96)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, null, 300)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, null, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", null, 100, 96)] + [DataRow("hundesteuer-anmeldung.pdf", null, 100, 300)] + [DataRow("hundesteuer-anmeldung.pdf", null, 100, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", null, 1000, 96)] + [DataRow("hundesteuer-anmeldung.pdf", null, 1000, 300)] + [DataRow("hundesteuer-anmeldung.pdf", null, 1000, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", null, 2000, 96)] + [DataRow("hundesteuer-anmeldung.pdf", null, 2000, 300)] + [DataRow("hundesteuer-anmeldung.pdf", null, 2000, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", 100, 100, 96)] + [DataRow("hundesteuer-anmeldung.pdf", 100, 100, 300)] + [DataRow("hundesteuer-anmeldung.pdf", 100, 100, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, 96)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, 300)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, 1200)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, 96)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, 300)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, 1200)] - [DataRow("SocialPreview.pdf")] - [DataRow("SocialPreview.pdf", 100, null, null)] - [DataRow("SocialPreview.pdf", 1000, null, null)] - [DataRow("SocialPreview.pdf", 2000, null, null)] - [DataRow("SocialPreview.pdf", null, 100, null)] - [DataRow("SocialPreview.pdf", null, 1000, null)] - [DataRow("SocialPreview.pdf", null, 2000, null)] - [DataRow("SocialPreview.pdf", 100, 100, null)] - [DataRow("SocialPreview.pdf", 1000, 1000, null)] - [DataRow("SocialPreview.pdf", 2000, 2000, null)] - [DataRow("SocialPreview.pdf", null, null, 96)] - [DataRow("SocialPreview.pdf", null, null, 300)] - [DataRow("SocialPreview.pdf", null, null, 600)] - [DataRow("SocialPreview.pdf", 100, null, 96)] - [DataRow("SocialPreview.pdf", 100, null, 300)] - [DataRow("SocialPreview.pdf", 100, null, 1200)] - [DataRow("SocialPreview.pdf", 1000, null, 96)] - [DataRow("SocialPreview.pdf", 1000, null, 300)] - [DataRow("SocialPreview.pdf", 1000, null, 1200)] - [DataRow("SocialPreview.pdf", 2000, null, 96)] - [DataRow("SocialPreview.pdf", 2000, null, 300)] - [DataRow("SocialPreview.pdf", 2000, null, 1200)] - [DataRow("SocialPreview.pdf", null, 100, 96)] - [DataRow("SocialPreview.pdf", null, 100, 300)] - [DataRow("SocialPreview.pdf", null, 100, 1200)] - [DataRow("SocialPreview.pdf", null, 1000, 96)] - [DataRow("SocialPreview.pdf", null, 1000, 300)] - [DataRow("SocialPreview.pdf", null, 1000, 1200)] - [DataRow("SocialPreview.pdf", null, 2000, 96)] - [DataRow("SocialPreview.pdf", null, 2000, 300)] - [DataRow("SocialPreview.pdf", null, 2000, 1200)] - [DataRow("SocialPreview.pdf", 100, 100, 96)] - [DataRow("SocialPreview.pdf", 100, 100, 300)] - [DataRow("SocialPreview.pdf", 100, 100, 1200)] - [DataRow("SocialPreview.pdf", 1000, 1000, 96)] - [DataRow("SocialPreview.pdf", 1000, 1000, 300)] - [DataRow("SocialPreview.pdf", 1000, 1000, 1200)] - [DataRow("SocialPreview.pdf", 2000, 2000, 96)] - [DataRow("SocialPreview.pdf", 2000, 2000, 300)] - [DataRow("SocialPreview.pdf", 2000, 2000, 1200)] + [DataRow("SocialPreview.pdf")] + [DataRow("SocialPreview.pdf", 100, null, null)] + [DataRow("SocialPreview.pdf", 1000, null, null)] + [DataRow("SocialPreview.pdf", 2000, null, null)] + [DataRow("SocialPreview.pdf", null, 100, null)] + [DataRow("SocialPreview.pdf", null, 1000, null)] + [DataRow("SocialPreview.pdf", null, 2000, null)] + [DataRow("SocialPreview.pdf", 100, 100, null)] + [DataRow("SocialPreview.pdf", 1000, 1000, null)] + [DataRow("SocialPreview.pdf", 2000, 2000, null)] + [DataRow("SocialPreview.pdf", null, null, 96)] + [DataRow("SocialPreview.pdf", null, null, 300)] + [DataRow("SocialPreview.pdf", null, null, 600)] + [DataRow("SocialPreview.pdf", 100, null, 96)] + [DataRow("SocialPreview.pdf", 100, null, 300)] + [DataRow("SocialPreview.pdf", 100, null, 1200)] + [DataRow("SocialPreview.pdf", 1000, null, 96)] + [DataRow("SocialPreview.pdf", 1000, null, 300)] + [DataRow("SocialPreview.pdf", 1000, null, 1200)] + [DataRow("SocialPreview.pdf", 2000, null, 96)] + [DataRow("SocialPreview.pdf", 2000, null, 300)] + [DataRow("SocialPreview.pdf", 2000, null, 1200)] + [DataRow("SocialPreview.pdf", null, 100, 96)] + [DataRow("SocialPreview.pdf", null, 100, 300)] + [DataRow("SocialPreview.pdf", null, 100, 1200)] + [DataRow("SocialPreview.pdf", null, 1000, 96)] + [DataRow("SocialPreview.pdf", null, 1000, 300)] + [DataRow("SocialPreview.pdf", null, 1000, 1200)] + [DataRow("SocialPreview.pdf", null, 2000, 96)] + [DataRow("SocialPreview.pdf", null, 2000, 300)] + [DataRow("SocialPreview.pdf", null, 2000, 1200)] + [DataRow("SocialPreview.pdf", 100, 100, 96)] + [DataRow("SocialPreview.pdf", 100, 100, 300)] + [DataRow("SocialPreview.pdf", 100, 100, 1200)] + [DataRow("SocialPreview.pdf", 1000, 1000, 96)] + [DataRow("SocialPreview.pdf", 1000, 1000, 300)] + [DataRow("SocialPreview.pdf", 1000, 1000, 1200)] + [DataRow("SocialPreview.pdf", 2000, 2000, 96)] + [DataRow("SocialPreview.pdf", 2000, 2000, 300)] + [DataRow("SocialPreview.pdf", 2000, 2000, 1200)] - [DataRow("Wikimedia_Commons_web.pdf")] - [DataRow("Wikimedia_Commons_web.pdf", 100, null, null)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, null, null)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, null, null)] - [DataRow("Wikimedia_Commons_web.pdf", null, 100, null)] - [DataRow("Wikimedia_Commons_web.pdf", null, 1000, null)] - [DataRow("Wikimedia_Commons_web.pdf", null, 2000, null)] - [DataRow("Wikimedia_Commons_web.pdf", 100, 100, null)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, null)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, null)] - [DataRow("Wikimedia_Commons_web.pdf", null, null, 96)] - [DataRow("Wikimedia_Commons_web.pdf", null, null, 300)] - [DataRow("Wikimedia_Commons_web.pdf", null, null, 600)] - [DataRow("Wikimedia_Commons_web.pdf", 100, null, 96)] - [DataRow("Wikimedia_Commons_web.pdf", 100, null, 300)] - [DataRow("Wikimedia_Commons_web.pdf", 100, null, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, null, 96)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, null, 300)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, null, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, null, 96)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, null, 300)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, null, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", null, 100, 96)] - [DataRow("Wikimedia_Commons_web.pdf", null, 100, 300)] - [DataRow("Wikimedia_Commons_web.pdf", null, 100, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", null, 1000, 96)] - [DataRow("Wikimedia_Commons_web.pdf", null, 1000, 300)] - [DataRow("Wikimedia_Commons_web.pdf", null, 1000, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", null, 2000, 96)] - [DataRow("Wikimedia_Commons_web.pdf", null, 2000, 300)] - [DataRow("Wikimedia_Commons_web.pdf", null, 2000, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", 100, 100, 96)] - [DataRow("Wikimedia_Commons_web.pdf", 100, 100, 300)] - [DataRow("Wikimedia_Commons_web.pdf", 100, 100, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, 96)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, 300)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, 1200)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, 96)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, 300)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, 1200)] - public void WithAspectRatio(string fileName, int? width = null, int? height = null, int? dpi = null) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "AspectRatio", GetExpectedFilename(fileName, "jpg", width, height, dpi, true)); + [DataRow("Wikimedia_Commons_web.pdf")] + [DataRow("Wikimedia_Commons_web.pdf", 100, null, null)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, null, null)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, null, null)] + [DataRow("Wikimedia_Commons_web.pdf", null, 100, null)] + [DataRow("Wikimedia_Commons_web.pdf", null, 1000, null)] + [DataRow("Wikimedia_Commons_web.pdf", null, 2000, null)] + [DataRow("Wikimedia_Commons_web.pdf", 100, 100, null)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, null)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, null)] + [DataRow("Wikimedia_Commons_web.pdf", null, null, 96)] + [DataRow("Wikimedia_Commons_web.pdf", null, null, 300)] + [DataRow("Wikimedia_Commons_web.pdf", null, null, 600)] + [DataRow("Wikimedia_Commons_web.pdf", 100, null, 96)] + [DataRow("Wikimedia_Commons_web.pdf", 100, null, 300)] + [DataRow("Wikimedia_Commons_web.pdf", 100, null, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, null, 96)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, null, 300)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, null, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, null, 96)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, null, 300)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, null, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", null, 100, 96)] + [DataRow("Wikimedia_Commons_web.pdf", null, 100, 300)] + [DataRow("Wikimedia_Commons_web.pdf", null, 100, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", null, 1000, 96)] + [DataRow("Wikimedia_Commons_web.pdf", null, 1000, 300)] + [DataRow("Wikimedia_Commons_web.pdf", null, 1000, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", null, 2000, 96)] + [DataRow("Wikimedia_Commons_web.pdf", null, 2000, 300)] + [DataRow("Wikimedia_Commons_web.pdf", null, 2000, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", 100, 100, 96)] + [DataRow("Wikimedia_Commons_web.pdf", 100, 100, 300)] + [DataRow("Wikimedia_Commons_web.pdf", 100, 100, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, 96)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, 300)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, 1200)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, 96)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, 300)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, 1200)] + public void WithAspectRatio(string fileName, int? width = null, int? height = null, int? dpi = null) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "AspectRatio", GetExpectedFilename(fileName, "jpg", width, height, dpi, true)); - using var inputStream = GetInputStream(Path.Combine("..", "Assets", fileName)); - using var outputStream = CreateOutputStream(expectedPath); + using var inputStream = GetInputStream(Path.Combine("..", "Assets", fileName)); + using var outputStream = CreateOutputStream(expectedPath); - if (dpi != null) - SaveJpeg(outputStream, inputStream, width: width, height: height, withAnnotations: true, withFormFill: true, withAspectRatio: true, dpi: dpi.Value); - else - SaveJpeg(outputStream, inputStream, width: width, height: height, withAnnotations: true, withFormFill: true, withAspectRatio: true); + if (dpi != null) + SaveJpeg(outputStream, inputStream, width: width, height: height, withAnnotations: true, withFormFill: true, withAspectRatio: true, dpi: dpi.Value); + else + SaveJpeg(outputStream, inputStream, width: width, height: height, withAnnotations: true, withFormFill: true, withAspectRatio: true); - CompareStreams(expectedPath, outputStream); - } + CompareStreams(expectedPath, outputStream); + } - [TestMethod] - [DataRow("hundesteuer-anmeldung.pdf", 100, null, false)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, null, false)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, null, false)] - [DataRow("hundesteuer-anmeldung.pdf", null, 100, false)] - [DataRow("hundesteuer-anmeldung.pdf", null, 1000, false)] - [DataRow("hundesteuer-anmeldung.pdf", null, 2000, false)] - [DataRow("hundesteuer-anmeldung.pdf", 100, 100, false)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, false)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, false)] - [DataRow("hundesteuer-anmeldung.pdf", 100, null, true)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, null, true)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, null, true)] - [DataRow("hundesteuer-anmeldung.pdf", null, 100, true)] - [DataRow("hundesteuer-anmeldung.pdf", null, 1000, true)] - [DataRow("hundesteuer-anmeldung.pdf", null, 2000, true)] - [DataRow("hundesteuer-anmeldung.pdf", 100, 100, true)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, true)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, true)] + [TestMethod] + [DataRow("hundesteuer-anmeldung.pdf", 100, null, false)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, null, false)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, null, false)] + [DataRow("hundesteuer-anmeldung.pdf", null, 100, false)] + [DataRow("hundesteuer-anmeldung.pdf", null, 1000, false)] + [DataRow("hundesteuer-anmeldung.pdf", null, 2000, false)] + [DataRow("hundesteuer-anmeldung.pdf", 100, 100, false)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, false)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, false)] + [DataRow("hundesteuer-anmeldung.pdf", 100, null, true)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, null, true)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, null, true)] + [DataRow("hundesteuer-anmeldung.pdf", null, 100, true)] + [DataRow("hundesteuer-anmeldung.pdf", null, 1000, true)] + [DataRow("hundesteuer-anmeldung.pdf", null, 2000, true)] + [DataRow("hundesteuer-anmeldung.pdf", 100, 100, true)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000, true)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000, true)] - [DataRow("SocialPreview.pdf", 100, null, false)] - [DataRow("SocialPreview.pdf", 1000, null, false)] - [DataRow("SocialPreview.pdf", 2000, null, false)] - [DataRow("SocialPreview.pdf", null, 100, false)] - [DataRow("SocialPreview.pdf", null, 1000, false)] - [DataRow("SocialPreview.pdf", null, 2000, false)] - [DataRow("SocialPreview.pdf", 100, 100, false)] - [DataRow("SocialPreview.pdf", 1000, 1000, false)] - [DataRow("SocialPreview.pdf", 2000, 2000, false)] - [DataRow("SocialPreview.pdf", 100, null, true)] - [DataRow("SocialPreview.pdf", 1000, null, true)] - [DataRow("SocialPreview.pdf", 2000, null, true)] - [DataRow("SocialPreview.pdf", null, 100, true)] - [DataRow("SocialPreview.pdf", null, 1000, true)] - [DataRow("SocialPreview.pdf", null, 2000, true)] - [DataRow("SocialPreview.pdf", 100, 100, true)] - [DataRow("SocialPreview.pdf", 1000, 1000, true)] - [DataRow("SocialPreview.pdf", 2000, 2000, true)] + [DataRow("SocialPreview.pdf", 100, null, false)] + [DataRow("SocialPreview.pdf", 1000, null, false)] + [DataRow("SocialPreview.pdf", 2000, null, false)] + [DataRow("SocialPreview.pdf", null, 100, false)] + [DataRow("SocialPreview.pdf", null, 1000, false)] + [DataRow("SocialPreview.pdf", null, 2000, false)] + [DataRow("SocialPreview.pdf", 100, 100, false)] + [DataRow("SocialPreview.pdf", 1000, 1000, false)] + [DataRow("SocialPreview.pdf", 2000, 2000, false)] + [DataRow("SocialPreview.pdf", 100, null, true)] + [DataRow("SocialPreview.pdf", 1000, null, true)] + [DataRow("SocialPreview.pdf", 2000, null, true)] + [DataRow("SocialPreview.pdf", null, 100, true)] + [DataRow("SocialPreview.pdf", null, 1000, true)] + [DataRow("SocialPreview.pdf", null, 2000, true)] + [DataRow("SocialPreview.pdf", 100, 100, true)] + [DataRow("SocialPreview.pdf", 1000, 1000, true)] + [DataRow("SocialPreview.pdf", 2000, 2000, true)] - [DataRow("Wikimedia_Commons_web.pdf", 100, null, false)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, null, false)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, null, false)] - [DataRow("Wikimedia_Commons_web.pdf", null, 100, false)] - [DataRow("Wikimedia_Commons_web.pdf", null, 1000, false)] - [DataRow("Wikimedia_Commons_web.pdf", null, 2000, false)] - [DataRow("Wikimedia_Commons_web.pdf", 100, 100, false)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, false)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, false)] - [DataRow("Wikimedia_Commons_web.pdf", 100, null, true)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, null, true)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, null, true)] - [DataRow("Wikimedia_Commons_web.pdf", null, 100, true)] - [DataRow("Wikimedia_Commons_web.pdf", null, 1000, true)] - [DataRow("Wikimedia_Commons_web.pdf", null, 2000, true)] - [DataRow("Wikimedia_Commons_web.pdf", 100, 100, true)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, true)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, true)] - public void IgnoreDpi(string fileName, int? width = null, int? height = null, bool withAspectRatio = false) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "AspectRatio", GetExpectedFilename(fileName, "jpg", width, height, 300, withAspectRatio)); + [DataRow("Wikimedia_Commons_web.pdf", 100, null, false)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, null, false)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, null, false)] + [DataRow("Wikimedia_Commons_web.pdf", null, 100, false)] + [DataRow("Wikimedia_Commons_web.pdf", null, 1000, false)] + [DataRow("Wikimedia_Commons_web.pdf", null, 2000, false)] + [DataRow("Wikimedia_Commons_web.pdf", 100, 100, false)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, false)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, false)] + [DataRow("Wikimedia_Commons_web.pdf", 100, null, true)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, null, true)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, null, true)] + [DataRow("Wikimedia_Commons_web.pdf", null, 100, true)] + [DataRow("Wikimedia_Commons_web.pdf", null, 1000, true)] + [DataRow("Wikimedia_Commons_web.pdf", null, 2000, true)] + [DataRow("Wikimedia_Commons_web.pdf", 100, 100, true)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000, true)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000, true)] + public void IgnoreDpi(string fileName, int? width = null, int? height = null, bool withAspectRatio = false) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "AspectRatio", GetExpectedFilename(fileName, "jpg", width, height, 300, withAspectRatio)); - using var inputStream = GetInputStream(Path.Combine("..", "Assets", fileName)); + using var inputStream = GetInputStream(Path.Combine("..", "Assets", fileName)); - for (int i = 72; i < 600; i += 100) - { - using var outputStream = CreateOutputStream(expectedPath); + for (int i = 72; i < 600; i += 100) + { + using var outputStream = CreateOutputStream(expectedPath); - ToImage(inputStream, true, dpi: i, width: width, height: height, withAnnotations: true, withFormFill: true, withAspectRatio: withAspectRatio).Encode(outputStream, SkiaSharp.SKEncodedImageFormat.Jpeg, 100); - CompareStreams(expectedPath, outputStream); - } - } + ToImage(inputStream, true, dpi: i, width: width, height: height, withAnnotations: true, withFormFill: true, withAspectRatio: withAspectRatio).Encode(outputStream, SkiaSharp.SKEncodedImageFormat.Jpeg, 100); + CompareStreams(expectedPath, outputStream); + } + } - [TestMethod] - [DataRow("hundesteuer-anmeldung.pdf", 100, 100)] - [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000)] - [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000)] - [DataRow("SocialPreview.pdf", 100, 100)] - [DataRow("SocialPreview.pdf", 1000, 1000)] - [DataRow("SocialPreview.pdf", 2000, 2000)] - [DataRow("Wikimedia_Commons_web.pdf", 100, 100)] - [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000)] - [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000)] - public void IgnoreAspectRatio(string fileName, int width, int height) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "AspectRatio", GetExpectedFilename(fileName, "jpg", width, height, 300, true)); + [TestMethod] + [DataRow("hundesteuer-anmeldung.pdf", 100, 100)] + [DataRow("hundesteuer-anmeldung.pdf", 1000, 1000)] + [DataRow("hundesteuer-anmeldung.pdf", 2000, 2000)] + [DataRow("SocialPreview.pdf", 100, 100)] + [DataRow("SocialPreview.pdf", 1000, 1000)] + [DataRow("SocialPreview.pdf", 2000, 2000)] + [DataRow("Wikimedia_Commons_web.pdf", 100, 100)] + [DataRow("Wikimedia_Commons_web.pdf", 1000, 1000)] + [DataRow("Wikimedia_Commons_web.pdf", 2000, 2000)] + public void IgnoreAspectRatio(string fileName, int width, int height) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "AspectRatio", GetExpectedFilename(fileName, "jpg", width, height, 300, true)); - using var inputStream = GetInputStream(Path.Combine("..", "Assets", fileName)); - using var outputStream1 = CreateOutputStream(expectedPath); - using var outputStream2 = CreateOutputStream(expectedPath); + using var inputStream = GetInputStream(Path.Combine("..", "Assets", fileName)); + using var outputStream1 = CreateOutputStream(expectedPath); + using var outputStream2 = CreateOutputStream(expectedPath); - ToImage(inputStream, true, width: width, height: height, withAnnotations: true, withFormFill: true, withAspectRatio: false).Encode(outputStream1, SkiaSharp.SKEncodedImageFormat.Jpeg, 100); - ToImage(inputStream, true, width: width, height: height, withAnnotations: true, withFormFill: true, withAspectRatio: true).Encode(outputStream2, SkiaSharp.SKEncodedImageFormat.Jpeg, 100); + ToImage(inputStream, true, width: width, height: height, withAnnotations: true, withFormFill: true, withAspectRatio: false).Encode(outputStream1, SkiaSharp.SKEncodedImageFormat.Jpeg, 100); + ToImage(inputStream, true, width: width, height: height, withAnnotations: true, withFormFill: true, withAspectRatio: true).Encode(outputStream2, SkiaSharp.SKEncodedImageFormat.Jpeg, 100); - CompareStreams(expectedPath, outputStream1); - CompareStreams(expectedPath, outputStream2); - } + CompareStreams(expectedPath, outputStream1); + CompareStreams(expectedPath, outputStream2); + } - [TestMethod] - [DataRow("hundesteuer-anmeldung.pdf", 96)] - [DataRow("hundesteuer-anmeldung.pdf", 300)] - [DataRow("hundesteuer-anmeldung.pdf", 600)] - [DataRow("SocialPreview.pdf", 96)] - [DataRow("SocialPreview.pdf", 300)] - [DataRow("SocialPreview.pdf", 600)] - [DataRow("Wikimedia_Commons_web.pdf", 96)] - [DataRow("Wikimedia_Commons_web.pdf", 300)] - [DataRow("Wikimedia_Commons_web.pdf", 600)] - public void IgnoreAspectRatioWithDpi(string fileName, int dpi) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "AspectRatio", GetExpectedFilename(fileName, "jpg", null, null, dpi, true)); + [TestMethod] + [DataRow("hundesteuer-anmeldung.pdf", 96)] + [DataRow("hundesteuer-anmeldung.pdf", 300)] + [DataRow("hundesteuer-anmeldung.pdf", 600)] + [DataRow("SocialPreview.pdf", 96)] + [DataRow("SocialPreview.pdf", 300)] + [DataRow("SocialPreview.pdf", 600)] + [DataRow("Wikimedia_Commons_web.pdf", 96)] + [DataRow("Wikimedia_Commons_web.pdf", 300)] + [DataRow("Wikimedia_Commons_web.pdf", 600)] + public void IgnoreAspectRatioWithDpi(string fileName, int dpi) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "AspectRatio", GetExpectedFilename(fileName, "jpg", null, null, dpi, true)); - using var inputStream = GetInputStream(Path.Combine("..", "Assets", fileName)); - using var outputStream1 = CreateOutputStream(expectedPath); - using var outputStream2 = CreateOutputStream(expectedPath); + using var inputStream = GetInputStream(Path.Combine("..", "Assets", fileName)); + using var outputStream1 = CreateOutputStream(expectedPath); + using var outputStream2 = CreateOutputStream(expectedPath); - ToImage(inputStream, true, dpi: dpi, withAnnotations: true, withFormFill: true, withAspectRatio: false).Encode(outputStream1, SkiaSharp.SKEncodedImageFormat.Jpeg, 100); - ToImage(inputStream, true, dpi: dpi, withAnnotations: true, withFormFill: true, withAspectRatio: true).Encode(outputStream2, SkiaSharp.SKEncodedImageFormat.Jpeg, 100); + ToImage(inputStream, true, dpi: dpi, withAnnotations: true, withFormFill: true, withAspectRatio: false).Encode(outputStream1, SkiaSharp.SKEncodedImageFormat.Jpeg, 100); + ToImage(inputStream, true, dpi: dpi, withAnnotations: true, withFormFill: true, withAspectRatio: true).Encode(outputStream2, SkiaSharp.SKEncodedImageFormat.Jpeg, 100); - CompareStreams(expectedPath, outputStream1); - CompareStreams(expectedPath, outputStream2); - } + CompareStreams(expectedPath, outputStream1); + CompareStreams(expectedPath, outputStream2); + } - private static string GetExpectedFilename(string fileName, string? fileExtension, int? width, int? height, int? dpi, bool withAspectRatio) - => $"{fileName}_w={width?.ToString() ?? "null"}_h={height?.ToString() ?? "null"}_dpi={dpi?.ToString() ?? "null"}_aspectratio={withAspectRatio}{(fileExtension != null ? $".{fileExtension}" : string.Empty)}"; - } + private static string GetExpectedFilename(string fileName, string? fileExtension, int? width, int? height, int? dpi, bool withAspectRatio) + => $"{fileName}_w={width?.ToString() ?? "null"}_h={height?.ToString() ?? "null"}_dpi={dpi?.ToString() ?? "null"}_aspectratio={withAspectRatio}{(fileExtension != null ? $".{fileExtension}" : string.Empty)}"; + } } \ No newline at end of file diff --git a/src/Tests/Compatibility/ExceptionTests.cs b/src/Tests/Compatibility/ExceptionTests.cs index c857fe41..cc08ef23 100644 --- a/src/Tests/Compatibility/ExceptionTests.cs +++ b/src/Tests/Compatibility/ExceptionTests.cs @@ -1,5 +1,4 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using PDFtoImage.Exceptions; using PDFtoImage.Tests; using System; using System.IO; @@ -8,17 +7,17 @@ namespace Tests.Compatibility { - [TestClass] - public class ExceptionTests : TestBase - { - [TestMethod] - [DataRow("hundesteuer-anmeldung.pdf")] - [DataRow("SocialPreview.pdf")] - [DataRow("Wikimedia_Commons_web.pdf")] - public void ThrowsPageNotFound(string inputFile) - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", inputFile)); - Assert.ThrowsException(() => ToImage(inputStream, page: 80085)); - } - } + [TestClass] + public class ExceptionTests : TestBase + { + [TestMethod] + [DataRow("hundesteuer-anmeldung.pdf")] + [DataRow("SocialPreview.pdf")] + [DataRow("Wikimedia_Commons_web.pdf")] + public void ThrowsPageNotFound(string inputFile) + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", inputFile)); + Assert.ThrowsException(() => ToImage(inputStream, page: 80085)); + } + } } \ No newline at end of file diff --git a/src/Tests/Compatibility/FormFillTests.cs b/src/Tests/Compatibility/FormFillTests.cs index 08b41863..1fd06112 100644 --- a/src/Tests/Compatibility/FormFillTests.cs +++ b/src/Tests/Compatibility/FormFillTests.cs @@ -6,12 +6,12 @@ namespace Tests.Compatibility { - [TestClass] - public class FormFillTests - { - [TestInitialize] - public void Initialize() - { + [TestClass] + public class FormFillTests + { + [TestInitialize] + public void Initialize() + { #if NET6_0_OR_GREATER if (!OperatingSystem.IsWindows() && !OperatingSystem.IsLinux() && !OperatingSystem.IsMacOS()) Assert.Inconclusive("This test must run on Windows, Linux or macOS."); @@ -19,60 +19,60 @@ public void Initialize() } [TestMethod] - [DataRow(null, DisplayName = "Default (no form fill)")] - [DataRow(true, DisplayName = "Form fill")] - [DataRow(false, DisplayName = "No form fill")] - public void SaveWebpPageNumber(bool? withFormFill) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"hundesteuer-anmeldung_{withFormFill ?? false}.webp"); + [DataRow(null, DisplayName = "Default (no form fill)")] + [DataRow(true, DisplayName = "Form fill")] + [DataRow(false, DisplayName = "No form fill")] + public void SaveWebpPageNumber(bool? withFormFill) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"hundesteuer-anmeldung_{withFormFill ?? false}.webp"); - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); - using var outputStream = CreateOutputStream(expectedPath); + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); + using var outputStream = CreateOutputStream(expectedPath); - if (withFormFill == null) - SaveWebp(outputStream, inputStream, dpi: 40); - else - SaveWebp(outputStream, inputStream, dpi: 40, withFormFill: withFormFill.Value); + if (withFormFill == null) + SaveWebp(outputStream, inputStream, dpi: 40); + else + SaveWebp(outputStream, inputStream, dpi: 40, withFormFill: withFormFill.Value); - CompareStreams(expectedPath, outputStream); - } + CompareStreams(expectedPath, outputStream); + } - [TestMethod] - [DataRow(null, DisplayName = "Default (no form fill)")] - [DataRow(true, DisplayName = "Form fill")] - [DataRow(false, DisplayName = "No form fill")] - public void SavePngPageNumber(bool? withFormFill) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"hundesteuer-anmeldung_{withFormFill ?? false}.png"); + [TestMethod] + [DataRow(null, DisplayName = "Default (no form fill)")] + [DataRow(true, DisplayName = "Form fill")] + [DataRow(false, DisplayName = "No form fill")] + public void SavePngPageNumber(bool? withFormFill) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"hundesteuer-anmeldung_{withFormFill ?? false}.png"); - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); - using var outputStream = CreateOutputStream(expectedPath); + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); + using var outputStream = CreateOutputStream(expectedPath); - if (withFormFill == null) - SavePng(outputStream, inputStream, dpi: 40); - else - SavePng(outputStream, inputStream, dpi: 40, withFormFill: withFormFill.Value); + if (withFormFill == null) + SavePng(outputStream, inputStream, dpi: 40); + else + SavePng(outputStream, inputStream, dpi: 40, withFormFill: withFormFill.Value); - CompareStreams(expectedPath, outputStream); - } + CompareStreams(expectedPath, outputStream); + } - [TestMethod] - [DataRow(null, DisplayName = "Default (no form fill)")] - [DataRow(true, DisplayName = "Form fill")] - [DataRow(false, DisplayName = "No form fill")] - public void SaveJpegPageNumber(bool? withFormFill) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"hundesteuer-anmeldung_{withFormFill ?? false}.jpg"); + [TestMethod] + [DataRow(null, DisplayName = "Default (no form fill)")] + [DataRow(true, DisplayName = "Form fill")] + [DataRow(false, DisplayName = "No form fill")] + public void SaveJpegPageNumber(bool? withFormFill) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"hundesteuer-anmeldung_{withFormFill ?? false}.jpg"); - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); - using var outputStream = CreateOutputStream(expectedPath); + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); + using var outputStream = CreateOutputStream(expectedPath); - if (withFormFill == null) - SaveJpeg(outputStream, inputStream, dpi: 40); - else - SaveJpeg(outputStream, inputStream, dpi: 40, withFormFill: withFormFill.Value); + if (withFormFill == null) + SaveJpeg(outputStream, inputStream, dpi: 40); + else + SaveJpeg(outputStream, inputStream, dpi: 40, withFormFill: withFormFill.Value); - CompareStreams(expectedPath, outputStream); - } - } + CompareStreams(expectedPath, outputStream); + } + } } \ No newline at end of file diff --git a/src/Tests/Compatibility/RotationTests.cs b/src/Tests/Compatibility/RotationTests.cs index 62014d59..28c544fd 100644 --- a/src/Tests/Compatibility/RotationTests.cs +++ b/src/Tests/Compatibility/RotationTests.cs @@ -8,126 +8,126 @@ namespace Tests.Compatibility { - [TestClass] - public class RotationTests : TestBase - { - [TestMethod] - [DataRow(null, DisplayName = "Default (no rotation)")] - [DataRow(PdfRotation.Rotate0, DisplayName = "No rotation")] - [DataRow(PdfRotation.Rotate90, DisplayName = "Rotated 90 degrees clockwise")] - [DataRow(PdfRotation.Rotate180, DisplayName = "Rotated 180 degrees")] - [DataRow(PdfRotation.Rotate270, DisplayName = "Rotated 90 degrees counter-clockwise")] - public void SaveWebpPageNumber(PdfRotation? rotation) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "Rotation", $"hundesteuer-anmeldung_{Enum.GetName(typeof(PdfRotation), rotation ?? PdfRotation.Rotate0)}.webp"); - - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); - using var outputStream = CreateOutputStream(expectedPath); - - if (rotation == null) - SaveWebp(outputStream, inputStream, dpi: 40); - else - SaveWebp(outputStream, inputStream, dpi: 40, rotation: rotation.Value); - - CompareStreams(expectedPath, outputStream); - } - - [TestMethod] - [DataRow(null, DisplayName = "Default (no rotation)")] - [DataRow(PdfRotation.Rotate0, DisplayName = "No rotation")] - [DataRow(PdfRotation.Rotate90, DisplayName = "Rotated 90 degrees clockwise")] - [DataRow(PdfRotation.Rotate180, DisplayName = "Rotated 180 degrees")] - [DataRow(PdfRotation.Rotate270, DisplayName = "Rotated 90 degrees counter-clockwise")] - public void SavePngPageNumber(PdfRotation? rotation) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "Rotation", $"hundesteuer-anmeldung_{Enum.GetName(typeof(PdfRotation), rotation ?? PdfRotation.Rotate0)}.png"); - - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); - using var outputStream = CreateOutputStream(expectedPath); - - if (rotation == null) - SavePng(outputStream, inputStream, dpi: 40); - else - SavePng(outputStream, inputStream, dpi: 40, rotation: rotation.Value); - - CompareStreams(expectedPath, outputStream); - } - - [TestMethod] - [DataRow(null, DisplayName = "Default (no rotation)")] - [DataRow(PdfRotation.Rotate0, DisplayName = "No rotation")] - [DataRow(PdfRotation.Rotate90, DisplayName = "Rotated 90 degrees clockwise")] - [DataRow(PdfRotation.Rotate180, DisplayName = "Rotated 180 degrees")] - [DataRow(PdfRotation.Rotate270, DisplayName = "Rotated 90 degrees counter-clockwise")] - public void SaveJpegPageNumber(PdfRotation? rotation) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "Rotation", $"hundesteuer-anmeldung_{Enum.GetName(typeof(PdfRotation), rotation ?? PdfRotation.Rotate0)}.jpg"); - - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); - using var outputStream = CreateOutputStream(expectedPath); - - if (rotation == null) - SaveJpeg(outputStream, inputStream, dpi: 40); - else - SaveJpeg(outputStream, inputStream, dpi: 40, rotation: rotation.Value); - - CompareStreams(expectedPath, outputStream); - } - - [TestMethod] - [DataRow(null, null, null, false)] - [DataRow(PdfRotation.Rotate0, null, null, false)] - [DataRow(PdfRotation.Rotate90, null, null, false)] - [DataRow(PdfRotation.Rotate180, null, null, false)] - [DataRow(PdfRotation.Rotate270, null, null, false)] - [DataRow(null, null, null, true)] - [DataRow(PdfRotation.Rotate0, null, null, true)] - [DataRow(PdfRotation.Rotate90, null, null, true)] - [DataRow(PdfRotation.Rotate180, null, null, true)] - [DataRow(PdfRotation.Rotate270, null, null, true)] - [DataRow(null, 200, null, false)] - [DataRow(PdfRotation.Rotate0, 200, null, false)] - [DataRow(PdfRotation.Rotate90, 200, null, false)] - [DataRow(PdfRotation.Rotate180, 200, null, false)] - [DataRow(PdfRotation.Rotate270, 200, null, false)] - [DataRow(null, 200, null, true)] - [DataRow(PdfRotation.Rotate0, 200, null, true)] - [DataRow(PdfRotation.Rotate90, 200, null, true)] - [DataRow(PdfRotation.Rotate180, 200, null, true)] - [DataRow(PdfRotation.Rotate270, 200, null, true)] - [DataRow(null, null, 200, false)] - [DataRow(PdfRotation.Rotate0, null, 200, false)] - [DataRow(PdfRotation.Rotate90, null, 200, false)] - [DataRow(PdfRotation.Rotate180, null, 200, false)] - [DataRow(PdfRotation.Rotate270, 200, null, false)] - [DataRow(null, null, 200, true)] - [DataRow(PdfRotation.Rotate0, null, 200, true)] - [DataRow(PdfRotation.Rotate90, null, 200, true)] - [DataRow(PdfRotation.Rotate180, null, 200, true)] - [DataRow(PdfRotation.Rotate270, null, 200, true)] - [DataRow(null, 200, 200, false)] - [DataRow(PdfRotation.Rotate0, 200, 200, false)] - [DataRow(PdfRotation.Rotate90, 200, 200, false)] - [DataRow(PdfRotation.Rotate180, 200, 200, false)] - [DataRow(PdfRotation.Rotate270, 200, 200, false)] - [DataRow(null, 200, 200, true)] - [DataRow(PdfRotation.Rotate0, 200, 200, true)] - [DataRow(PdfRotation.Rotate90, 200, 200, true)] - [DataRow(PdfRotation.Rotate180, 200, 200, true)] - [DataRow(PdfRotation.Rotate270, 200, 200, true)] - public void WithWidthHeightAspect(PdfRotation? rotation, int? width, int? height, bool withAspectRatio) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "Rotation", $"hundesteuer-anmeldung_{Enum.GetName(typeof(PdfRotation), rotation ?? PdfRotation.Rotate0)}_{width?.ToString() ?? "null"}x{height?.ToString() ?? "null"}_{withAspectRatio}.png"); - - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); - using var outputStream = CreateOutputStream(expectedPath); - - if (rotation == null) - SavePng(outputStream, inputStream, dpi: 40, width: width, height: height, withAspectRatio: withAspectRatio); - else - SavePng(outputStream, inputStream, dpi: 40, width: width, height: height, withAspectRatio: withAspectRatio, rotation: rotation.Value); - - CompareStreams(expectedPath, outputStream); - } - } + [TestClass] + public class RotationTests : TestBase + { + [TestMethod] + [DataRow(null, DisplayName = "Default (no rotation)")] + [DataRow(PdfRotation.Rotate0, DisplayName = "No rotation")] + [DataRow(PdfRotation.Rotate90, DisplayName = "Rotated 90 degrees clockwise")] + [DataRow(PdfRotation.Rotate180, DisplayName = "Rotated 180 degrees")] + [DataRow(PdfRotation.Rotate270, DisplayName = "Rotated 90 degrees counter-clockwise")] + public void SaveWebpPageNumber(PdfRotation? rotation) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "Rotation", $"hundesteuer-anmeldung_{Enum.GetName(typeof(PdfRotation), rotation ?? PdfRotation.Rotate0)}.webp"); + + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); + using var outputStream = CreateOutputStream(expectedPath); + + if (rotation == null) + SaveWebp(outputStream, inputStream, dpi: 40); + else + SaveWebp(outputStream, inputStream, dpi: 40, rotation: rotation.Value); + + CompareStreams(expectedPath, outputStream); + } + + [TestMethod] + [DataRow(null, DisplayName = "Default (no rotation)")] + [DataRow(PdfRotation.Rotate0, DisplayName = "No rotation")] + [DataRow(PdfRotation.Rotate90, DisplayName = "Rotated 90 degrees clockwise")] + [DataRow(PdfRotation.Rotate180, DisplayName = "Rotated 180 degrees")] + [DataRow(PdfRotation.Rotate270, DisplayName = "Rotated 90 degrees counter-clockwise")] + public void SavePngPageNumber(PdfRotation? rotation) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "Rotation", $"hundesteuer-anmeldung_{Enum.GetName(typeof(PdfRotation), rotation ?? PdfRotation.Rotate0)}.png"); + + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); + using var outputStream = CreateOutputStream(expectedPath); + + if (rotation == null) + SavePng(outputStream, inputStream, dpi: 40); + else + SavePng(outputStream, inputStream, dpi: 40, rotation: rotation.Value); + + CompareStreams(expectedPath, outputStream); + } + + [TestMethod] + [DataRow(null, DisplayName = "Default (no rotation)")] + [DataRow(PdfRotation.Rotate0, DisplayName = "No rotation")] + [DataRow(PdfRotation.Rotate90, DisplayName = "Rotated 90 degrees clockwise")] + [DataRow(PdfRotation.Rotate180, DisplayName = "Rotated 180 degrees")] + [DataRow(PdfRotation.Rotate270, DisplayName = "Rotated 90 degrees counter-clockwise")] + public void SaveJpegPageNumber(PdfRotation? rotation) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "Rotation", $"hundesteuer-anmeldung_{Enum.GetName(typeof(PdfRotation), rotation ?? PdfRotation.Rotate0)}.jpg"); + + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); + using var outputStream = CreateOutputStream(expectedPath); + + if (rotation == null) + SaveJpeg(outputStream, inputStream, dpi: 40); + else + SaveJpeg(outputStream, inputStream, dpi: 40, rotation: rotation.Value); + + CompareStreams(expectedPath, outputStream); + } + + [TestMethod] + [DataRow(null, null, null, false)] + [DataRow(PdfRotation.Rotate0, null, null, false)] + [DataRow(PdfRotation.Rotate90, null, null, false)] + [DataRow(PdfRotation.Rotate180, null, null, false)] + [DataRow(PdfRotation.Rotate270, null, null, false)] + [DataRow(null, null, null, true)] + [DataRow(PdfRotation.Rotate0, null, null, true)] + [DataRow(PdfRotation.Rotate90, null, null, true)] + [DataRow(PdfRotation.Rotate180, null, null, true)] + [DataRow(PdfRotation.Rotate270, null, null, true)] + [DataRow(null, 200, null, false)] + [DataRow(PdfRotation.Rotate0, 200, null, false)] + [DataRow(PdfRotation.Rotate90, 200, null, false)] + [DataRow(PdfRotation.Rotate180, 200, null, false)] + [DataRow(PdfRotation.Rotate270, 200, null, false)] + [DataRow(null, 200, null, true)] + [DataRow(PdfRotation.Rotate0, 200, null, true)] + [DataRow(PdfRotation.Rotate90, 200, null, true)] + [DataRow(PdfRotation.Rotate180, 200, null, true)] + [DataRow(PdfRotation.Rotate270, 200, null, true)] + [DataRow(null, null, 200, false)] + [DataRow(PdfRotation.Rotate0, null, 200, false)] + [DataRow(PdfRotation.Rotate90, null, 200, false)] + [DataRow(PdfRotation.Rotate180, null, 200, false)] + [DataRow(PdfRotation.Rotate270, 200, null, false)] + [DataRow(null, null, 200, true)] + [DataRow(PdfRotation.Rotate0, null, 200, true)] + [DataRow(PdfRotation.Rotate90, null, 200, true)] + [DataRow(PdfRotation.Rotate180, null, 200, true)] + [DataRow(PdfRotation.Rotate270, null, 200, true)] + [DataRow(null, 200, 200, false)] + [DataRow(PdfRotation.Rotate0, 200, 200, false)] + [DataRow(PdfRotation.Rotate90, 200, 200, false)] + [DataRow(PdfRotation.Rotate180, 200, 200, false)] + [DataRow(PdfRotation.Rotate270, 200, 200, false)] + [DataRow(null, 200, 200, true)] + [DataRow(PdfRotation.Rotate0, 200, 200, true)] + [DataRow(PdfRotation.Rotate90, 200, 200, true)] + [DataRow(PdfRotation.Rotate180, 200, 200, true)] + [DataRow(PdfRotation.Rotate270, 200, 200, true)] + public void WithWidthHeightAspect(PdfRotation? rotation, int? width, int? height, bool withAspectRatio) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "Rotation", $"hundesteuer-anmeldung_{Enum.GetName(typeof(PdfRotation), rotation ?? PdfRotation.Rotate0)}_{width?.ToString() ?? "null"}x{height?.ToString() ?? "null"}_{withAspectRatio}.png"); + + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); + using var outputStream = CreateOutputStream(expectedPath); + + if (rotation == null) + SavePng(outputStream, inputStream, dpi: 40, width: width, height: height, withAspectRatio: withAspectRatio); + else + SavePng(outputStream, inputStream, dpi: 40, width: width, height: height, withAspectRatio: withAspectRatio, rotation: rotation.Value); + + CompareStreams(expectedPath, outputStream); + } + } } \ No newline at end of file diff --git a/src/Tests/ExceptionTests.cs b/src/Tests/ExceptionTests.cs index 87a5b4f8..89df444f 100644 --- a/src/Tests/ExceptionTests.cs +++ b/src/Tests/ExceptionTests.cs @@ -8,24 +8,24 @@ namespace Tests { - [TestClass] - public class ExceptionTests : TestBase - { - [TestMethod] - public void ThrowsInvalidFormat() - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "DummyImage.png")); - Assert.ThrowsException(() => GetPageCount(inputStream)); - } + [TestClass] + public class ExceptionTests : TestBase + { + [TestMethod] + public void ThrowsInvalidFormat() + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "DummyImage.png")); + Assert.ThrowsException(() => GetPageCount(inputStream)); + } - [TestMethod] - [DataRow("hundesteuer-anmeldung.pdf")] - [DataRow("SocialPreview.pdf")] - [DataRow("Wikimedia_Commons_web.pdf")] - public void ThrowsPageNotFound(string inputFile) - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", inputFile)); - Assert.ThrowsException(() => ToImage(inputStream, page: 80085)); - } - } + [TestMethod] + [DataRow("hundesteuer-anmeldung.pdf")] + [DataRow("SocialPreview.pdf")] + [DataRow("Wikimedia_Commons_web.pdf")] + public void ThrowsPageNotFound(string inputFile) + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", inputFile)); + Assert.ThrowsException(() => ToImage(inputStream, page: 80085)); + } + } } \ No newline at end of file diff --git a/src/Tests/FormFillTests.cs b/src/Tests/FormFillTests.cs index 684869f5..19eca5c2 100644 --- a/src/Tests/FormFillTests.cs +++ b/src/Tests/FormFillTests.cs @@ -6,73 +6,73 @@ namespace Tests { - [TestClass] - public class FormFillTests - { - [TestInitialize] - public void Initialize() - { + [TestClass] + public class FormFillTests + { + [TestInitialize] + public void Initialize() + { #if NET6_0_OR_GREATER if (!OperatingSystem.IsWindows() && !OperatingSystem.IsLinux() && !OperatingSystem.IsMacOS()) Assert.Inconclusive("This test must run on Windows, Linux or macOS."); #endif - } + } - [TestMethod] - [DataRow(null, DisplayName = "Default (no form fill)")] - [DataRow(true, DisplayName = "Form fill")] - [DataRow(false, DisplayName = "No form fill")] - public void SaveWebpPageNumber(bool? withFormFill) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"hundesteuer-anmeldung_{withFormFill ?? false}.webp"); + [TestMethod] + [DataRow(null, DisplayName = "Default (no form fill)")] + [DataRow(true, DisplayName = "Form fill")] + [DataRow(false, DisplayName = "No form fill")] + public void SaveWebpPageNumber(bool? withFormFill) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"hundesteuer-anmeldung_{withFormFill ?? false}.webp"); - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); - using var outputStream = CreateOutputStream(expectedPath); + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); + using var outputStream = CreateOutputStream(expectedPath); - if (withFormFill == null) - SaveWebp(outputStream, inputStream, options: new(Dpi: 40)); - else - SaveWebp(outputStream, inputStream, options: new(Dpi: 40, WithFormFill: withFormFill.Value)); + if (withFormFill == null) + SaveWebp(outputStream, inputStream, options: new(Dpi: 40)); + else + SaveWebp(outputStream, inputStream, options: new(Dpi: 40, WithFormFill: withFormFill.Value)); - CompareStreams(expectedPath, outputStream); - } + CompareStreams(expectedPath, outputStream); + } - [TestMethod] - [DataRow(null, DisplayName = "Default (no form fill)")] - [DataRow(true, DisplayName = "Form fill")] - [DataRow(false, DisplayName = "No form fill")] - public void SavePngPageNumber(bool? withFormFill) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"hundesteuer-anmeldung_{withFormFill ?? false}.png"); + [TestMethod] + [DataRow(null, DisplayName = "Default (no form fill)")] + [DataRow(true, DisplayName = "Form fill")] + [DataRow(false, DisplayName = "No form fill")] + public void SavePngPageNumber(bool? withFormFill) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"hundesteuer-anmeldung_{withFormFill ?? false}.png"); - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); - using var outputStream = CreateOutputStream(expectedPath); + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); + using var outputStream = CreateOutputStream(expectedPath); - if (withFormFill == null) - SavePng(outputStream, inputStream, options: new(Dpi: 40)); - else - SavePng(outputStream, inputStream, options: new(Dpi: 40, WithFormFill: withFormFill.Value)); + if (withFormFill == null) + SavePng(outputStream, inputStream, options: new(Dpi: 40)); + else + SavePng(outputStream, inputStream, options: new(Dpi: 40, WithFormFill: withFormFill.Value)); - CompareStreams(expectedPath, outputStream); - } + CompareStreams(expectedPath, outputStream); + } - [TestMethod] - [DataRow(null, DisplayName = "Default (no form fill)")] - [DataRow(true, DisplayName = "Form fill")] - [DataRow(false, DisplayName = "No form fill")] - public void SaveJpegPageNumber(bool? withFormFill) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"hundesteuer-anmeldung_{withFormFill ?? false}.jpg"); + [TestMethod] + [DataRow(null, DisplayName = "Default (no form fill)")] + [DataRow(true, DisplayName = "Form fill")] + [DataRow(false, DisplayName = "No form fill")] + public void SaveJpegPageNumber(bool? withFormFill) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"hundesteuer-anmeldung_{withFormFill ?? false}.jpg"); - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); - using var outputStream = CreateOutputStream(expectedPath); + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); + using var outputStream = CreateOutputStream(expectedPath); - if (withFormFill == null) - SaveJpeg(outputStream, inputStream, options: new(Dpi: 40)); - else - SaveJpeg(outputStream, inputStream, options: new(Dpi: 40, WithFormFill: withFormFill.Value)); + if (withFormFill == null) + SaveJpeg(outputStream, inputStream, options: new(Dpi: 40)); + else + SaveJpeg(outputStream, inputStream, options: new(Dpi: 40, WithFormFill: withFormFill.Value)); - CompareStreams(expectedPath, outputStream); - } - } + CompareStreams(expectedPath, outputStream); + } + } } \ No newline at end of file diff --git a/src/Tests/PasswordTests.cs b/src/Tests/PasswordTests.cs index 10212cb3..c4b26e78 100644 --- a/src/Tests/PasswordTests.cs +++ b/src/Tests/PasswordTests.cs @@ -7,33 +7,33 @@ namespace Tests { - [TestClass] - public class PasswordTests : TestBase - { - [TestMethod] - [DataRow("SocialPreview.pdf", null)] - [DataRow("SocialPreview.pdf", "")] - [DataRow("SocialPreview.pdf", "this doc needs no password")] - [DataRow("SocialPreview with password 123456 (RC4-40).pdf", "123456")] - [DataRow("SocialPreview with password 123456 (RC4-128).pdf", "123456")] - [DataRow("SocialPreview with password 123456 (AES-128).pdf", "123456")] - [DataRow("SocialPreview with password 123456 (AES-256).pdf", "123456")] - public void WithCorrectPassword(string inputFile, string? password = null) - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", inputFile)); - var output = GetPageCount(inputStream, password: password); - Assert.AreEqual(1, output, "Page count should be 1, if the password was correct."); - } + [TestClass] + public class PasswordTests : TestBase + { + [TestMethod] + [DataRow("SocialPreview.pdf", null)] + [DataRow("SocialPreview.pdf", "")] + [DataRow("SocialPreview.pdf", "this doc needs no password")] + [DataRow("SocialPreview with password 123456 (RC4-40).pdf", "123456")] + [DataRow("SocialPreview with password 123456 (RC4-128).pdf", "123456")] + [DataRow("SocialPreview with password 123456 (AES-128).pdf", "123456")] + [DataRow("SocialPreview with password 123456 (AES-256).pdf", "123456")] + public void WithCorrectPassword(string inputFile, string? password = null) + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", inputFile)); + var output = GetPageCount(inputStream, password: password); + Assert.AreEqual(1, output, "Page count should be 1, if the password was correct."); + } - [TestMethod] - [DataRow("SocialPreview with password 123456 (RC4-40).pdf", "In noreni per ipe")] - [DataRow("SocialPreview with password 123456 (RC4-128).pdf", "In noreni cora")] - [DataRow("SocialPreview with password 123456 (AES-128).pdf", "Tira mine per ito")] - [DataRow("SocialPreview with password 123456 (AES-256).pdf", "Ne domina")] - public void ThrowsIncorrectPassword(string inputFile, string? password = null) - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", inputFile)); - Assert.ThrowsException(() => GetPageCount(inputStream, password: password)); - } - } + [TestMethod] + [DataRow("SocialPreview with password 123456 (RC4-40).pdf", "In noreni per ipe")] + [DataRow("SocialPreview with password 123456 (RC4-128).pdf", "In noreni cora")] + [DataRow("SocialPreview with password 123456 (AES-128).pdf", "Tira mine per ito")] + [DataRow("SocialPreview with password 123456 (AES-256).pdf", "Ne domina")] + public void ThrowsIncorrectPassword(string inputFile, string? password = null) + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", inputFile)); + Assert.ThrowsException(() => GetPageCount(inputStream, password: password)); + } + } } \ No newline at end of file diff --git a/src/Tests/QueryTests.cs b/src/Tests/QueryTests.cs index 650f97fb..1939ed7f 100644 --- a/src/Tests/QueryTests.cs +++ b/src/Tests/QueryTests.cs @@ -5,71 +5,71 @@ namespace Tests { - [TestClass] - public class QueryTests : TestBase - { - [TestMethod] - [DataRow("hundesteuer-anmeldung.pdf", 3)] - [DataRow("SocialPreview.pdf", 1)] - [DataRow("Wikimedia_Commons_web.pdf", 20)] - public void GetPageCount(string pdfFileName, int expectedPageCount) - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", pdfFileName)); + [TestClass] + public class QueryTests : TestBase + { + [TestMethod] + [DataRow("hundesteuer-anmeldung.pdf", 3)] + [DataRow("SocialPreview.pdf", 1)] + [DataRow("Wikimedia_Commons_web.pdf", 20)] + public void GetPageCount(string pdfFileName, int expectedPageCount) + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", pdfFileName)); - Assert.AreEqual(expectedPageCount, PDFtoImage.Conversion.GetPageCount(inputStream), "Expected and actual PDF page count differs."); - } + Assert.AreEqual(expectedPageCount, PDFtoImage.Conversion.GetPageCount(inputStream), "Expected and actual PDF page count differs."); + } - [TestMethod] - [DataRow("hundesteuer-anmeldung.pdf", 0, 595.56f, 842.04f)] - [DataRow("hundesteuer-anmeldung.pdf", 1, 595.56f, 842.04f)] - [DataRow("hundesteuer-anmeldung.pdf", 2, 595.56f, 842.04f)] - [DataRow("SocialPreview.pdf", 0, 1280f, 640f)] - [DataRow("Wikimedia_Commons_web.pdf", 0, 419.528f, 595.276f)] - [DataRow("Wikimedia_Commons_web.pdf", 1, 419.528f, 595.276f)] - [DataRow("Wikimedia_Commons_web.pdf", 2, 419.528f, 595.276f)] - [DataRow("Wikimedia_Commons_web.pdf", 3, 419.528f, 595.276f)] - [DataRow("Wikimedia_Commons_web.pdf", 4, 419.528f, 595.276f)] - [DataRow("Wikimedia_Commons_web.pdf", 5, 419.528f, 595.276f)] - [DataRow("Wikimedia_Commons_web.pdf", 6, 419.528f, 595.276f)] - [DataRow("Wikimedia_Commons_web.pdf", 7, 419.528f, 595.276f)] - [DataRow("Wikimedia_Commons_web.pdf", 8, 419.528f, 595.276f)] - [DataRow("Wikimedia_Commons_web.pdf", 9, 419.528f, 595.276f)] - [DataRow("Wikimedia_Commons_web.pdf", 10, 419.528f, 595.276f)] - [DataRow("Wikimedia_Commons_web.pdf", 11, 419.528f, 595.276f)] - [DataRow("Wikimedia_Commons_web.pdf", 12, 419.528f, 595.276f)] - [DataRow("Wikimedia_Commons_web.pdf", 13, 419.528f, 595.276f)] - [DataRow("Wikimedia_Commons_web.pdf", 14, 419.528f, 595.276f)] - [DataRow("Wikimedia_Commons_web.pdf", 15, 419.528f, 595.276f)] - [DataRow("Wikimedia_Commons_web.pdf", 16, 419.528f, 595.276f)] - [DataRow("Wikimedia_Commons_web.pdf", 17, 419.528f, 595.276f)] - [DataRow("Wikimedia_Commons_web.pdf", 18, 419.528f, 595.276f)] - [DataRow("Wikimedia_Commons_web.pdf", 19, 419.528f, 595.276f)] - public void GetPageSize(string pdfFileName, int page, float expectedPageWidth, float expectedPageHeight) - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", pdfFileName)); + [TestMethod] + [DataRow("hundesteuer-anmeldung.pdf", 0, 595.56f, 842.04f)] + [DataRow("hundesteuer-anmeldung.pdf", 1, 595.56f, 842.04f)] + [DataRow("hundesteuer-anmeldung.pdf", 2, 595.56f, 842.04f)] + [DataRow("SocialPreview.pdf", 0, 1280f, 640f)] + [DataRow("Wikimedia_Commons_web.pdf", 0, 419.528f, 595.276f)] + [DataRow("Wikimedia_Commons_web.pdf", 1, 419.528f, 595.276f)] + [DataRow("Wikimedia_Commons_web.pdf", 2, 419.528f, 595.276f)] + [DataRow("Wikimedia_Commons_web.pdf", 3, 419.528f, 595.276f)] + [DataRow("Wikimedia_Commons_web.pdf", 4, 419.528f, 595.276f)] + [DataRow("Wikimedia_Commons_web.pdf", 5, 419.528f, 595.276f)] + [DataRow("Wikimedia_Commons_web.pdf", 6, 419.528f, 595.276f)] + [DataRow("Wikimedia_Commons_web.pdf", 7, 419.528f, 595.276f)] + [DataRow("Wikimedia_Commons_web.pdf", 8, 419.528f, 595.276f)] + [DataRow("Wikimedia_Commons_web.pdf", 9, 419.528f, 595.276f)] + [DataRow("Wikimedia_Commons_web.pdf", 10, 419.528f, 595.276f)] + [DataRow("Wikimedia_Commons_web.pdf", 11, 419.528f, 595.276f)] + [DataRow("Wikimedia_Commons_web.pdf", 12, 419.528f, 595.276f)] + [DataRow("Wikimedia_Commons_web.pdf", 13, 419.528f, 595.276f)] + [DataRow("Wikimedia_Commons_web.pdf", 14, 419.528f, 595.276f)] + [DataRow("Wikimedia_Commons_web.pdf", 15, 419.528f, 595.276f)] + [DataRow("Wikimedia_Commons_web.pdf", 16, 419.528f, 595.276f)] + [DataRow("Wikimedia_Commons_web.pdf", 17, 419.528f, 595.276f)] + [DataRow("Wikimedia_Commons_web.pdf", 18, 419.528f, 595.276f)] + [DataRow("Wikimedia_Commons_web.pdf", 19, 419.528f, 595.276f)] + public void GetPageSize(string pdfFileName, int page, float expectedPageWidth, float expectedPageHeight) + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", pdfFileName)); - var result = PDFtoImage.Conversion.GetPageSize(inputStream, page: page); + var result = PDFtoImage.Conversion.GetPageSize(inputStream, page: page); - Assert.AreEqual(expectedPageWidth, result.Width, 0.0001f, "Expected and actual PDF page width differs."); - Assert.AreEqual(expectedPageHeight, result.Height, 0.0001f, "Expected and actual PDF page height differs."); - } + Assert.AreEqual(expectedPageWidth, result.Width, 0.0001f, "Expected and actual PDF page width differs."); + Assert.AreEqual(expectedPageHeight, result.Height, 0.0001f, "Expected and actual PDF page height differs."); + } - [TestMethod] - [DataRow("hundesteuer-anmeldung.pdf", 3)] - [DataRow("SocialPreview.pdf", 1)] - [DataRow("Wikimedia_Commons_web.pdf", 20)] - public void GetPageSizes(string pdfFileName, int expectedSizeCount) - { - using var inputStream = GetInputStream(Path.Combine("..", "Assets", pdfFileName)); + [TestMethod] + [DataRow("hundesteuer-anmeldung.pdf", 3)] + [DataRow("SocialPreview.pdf", 1)] + [DataRow("Wikimedia_Commons_web.pdf", 20)] + public void GetPageSizes(string pdfFileName, int expectedSizeCount) + { + using var inputStream = GetInputStream(Path.Combine("..", "Assets", pdfFileName)); - var result = PDFtoImage.Conversion.GetPageSizes(inputStream); + var result = PDFtoImage.Conversion.GetPageSizes(inputStream); - foreach (var size in result) - { - Assert.IsFalse(size.IsEmpty, "PDF page size cannot be empty."); - } + foreach (var size in result) + { + Assert.IsFalse(size.IsEmpty, "PDF page size cannot be empty."); + } - Assert.AreEqual(expectedSizeCount, result.Count, "Expected and actual PDF size count differs."); - } - } + Assert.AreEqual(expectedSizeCount, result.Count, "Expected and actual PDF size count differs."); + } + } } \ No newline at end of file diff --git a/src/Tests/RotationTests.cs b/src/Tests/RotationTests.cs index 4b6438fb..e11a2aad 100644 --- a/src/Tests/RotationTests.cs +++ b/src/Tests/RotationTests.cs @@ -8,126 +8,126 @@ namespace Tests { - [TestClass] - public class RotationTests : TestBase - { - [TestMethod] - [DataRow(null, DisplayName = "Default (no rotation)")] - [DataRow(PdfRotation.Rotate0, DisplayName = "No rotation")] - [DataRow(PdfRotation.Rotate90, DisplayName = "Rotated 90 degrees clockwise")] - [DataRow(PdfRotation.Rotate180, DisplayName = "Rotated 180 degrees")] - [DataRow(PdfRotation.Rotate270, DisplayName = "Rotated 90 degrees counter-clockwise")] - public void SaveWebpPageNumber(PdfRotation? rotation) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "Rotation", $"hundesteuer-anmeldung_{Enum.GetName(typeof(PdfRotation), rotation ?? PdfRotation.Rotate0)}.webp"); - - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); - using var outputStream = CreateOutputStream(expectedPath); - - if (rotation == null) - SaveWebp(outputStream, inputStream, options: new(Dpi: 40)); - else - SaveWebp(outputStream, inputStream, options: new(Dpi: 40, Rotation: rotation.Value)); - - CompareStreams(expectedPath, outputStream); - } - - [TestMethod] - [DataRow(null, DisplayName = "Default (no rotation)")] - [DataRow(PdfRotation.Rotate0, DisplayName = "No rotation")] - [DataRow(PdfRotation.Rotate90, DisplayName = "Rotated 90 degrees clockwise")] - [DataRow(PdfRotation.Rotate180, DisplayName = "Rotated 180 degrees")] - [DataRow(PdfRotation.Rotate270, DisplayName = "Rotated 90 degrees counter-clockwise")] - public void SavePngPageNumber(PdfRotation? rotation) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "Rotation", $"hundesteuer-anmeldung_{Enum.GetName(typeof(PdfRotation), rotation ?? PdfRotation.Rotate0)}.png"); - - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); - using var outputStream = CreateOutputStream(expectedPath); - - if (rotation == null) - SavePng(outputStream, inputStream, options: new(Dpi: 40)); - else - SavePng(outputStream, inputStream, options: new(Dpi: 40, Rotation: rotation.Value)); - - CompareStreams(expectedPath, outputStream); - } - - [TestMethod] - [DataRow(null, DisplayName = "Default (no rotation)")] - [DataRow(PdfRotation.Rotate0, DisplayName = "No rotation")] - [DataRow(PdfRotation.Rotate90, DisplayName = "Rotated 90 degrees clockwise")] - [DataRow(PdfRotation.Rotate180, DisplayName = "Rotated 180 degrees")] - [DataRow(PdfRotation.Rotate270, DisplayName = "Rotated 90 degrees counter-clockwise")] - public void SaveJpegPageNumber(PdfRotation? rotation) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "Rotation", $"hundesteuer-anmeldung_{Enum.GetName(typeof(PdfRotation), rotation ?? PdfRotation.Rotate0)}.jpg"); - - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); - using var outputStream = CreateOutputStream(expectedPath); - - if (rotation == null) - SaveJpeg(outputStream, inputStream, options: new(Dpi: 40)); - else - SaveJpeg(outputStream, inputStream, options: new(Dpi: 40, Rotation: rotation.Value)); - - CompareStreams(expectedPath, outputStream); - } - - [TestMethod] - [DataRow(null, null, null, false)] - [DataRow(PdfRotation.Rotate0, null, null, false)] - [DataRow(PdfRotation.Rotate90, null, null, false)] - [DataRow(PdfRotation.Rotate180, null, null, false)] - [DataRow(PdfRotation.Rotate270, null, null, false)] - [DataRow(null, null, null, true)] - [DataRow(PdfRotation.Rotate0, null, null, true)] - [DataRow(PdfRotation.Rotate90, null, null, true)] - [DataRow(PdfRotation.Rotate180, null, null, true)] - [DataRow(PdfRotation.Rotate270, null, null, true)] - [DataRow(null, 200, null, false)] - [DataRow(PdfRotation.Rotate0, 200, null, false)] - [DataRow(PdfRotation.Rotate90, 200, null, false)] - [DataRow(PdfRotation.Rotate180, 200, null, false)] - [DataRow(PdfRotation.Rotate270, 200, null, false)] - [DataRow(null, 200, null, true)] - [DataRow(PdfRotation.Rotate0, 200, null, true)] - [DataRow(PdfRotation.Rotate90, 200, null, true)] - [DataRow(PdfRotation.Rotate180, 200, null, true)] - [DataRow(PdfRotation.Rotate270, 200, null, true)] - [DataRow(null, null, 200, false)] - [DataRow(PdfRotation.Rotate0, null, 200, false)] - [DataRow(PdfRotation.Rotate90, null, 200, false)] - [DataRow(PdfRotation.Rotate180, null, 200, false)] - [DataRow(PdfRotation.Rotate270, 200, null, false)] - [DataRow(null, null, 200, true)] - [DataRow(PdfRotation.Rotate0, null, 200, true)] - [DataRow(PdfRotation.Rotate90, null, 200, true)] - [DataRow(PdfRotation.Rotate180, null, 200, true)] - [DataRow(PdfRotation.Rotate270, null, 200, true)] - [DataRow(null, 200, 200, false)] - [DataRow(PdfRotation.Rotate0, 200, 200, false)] - [DataRow(PdfRotation.Rotate90, 200, 200, false)] - [DataRow(PdfRotation.Rotate180, 200, 200, false)] - [DataRow(PdfRotation.Rotate270, 200, 200, false)] - [DataRow(null, 200, 200, true)] - [DataRow(PdfRotation.Rotate0, 200, 200, true)] - [DataRow(PdfRotation.Rotate90, 200, 200, true)] - [DataRow(PdfRotation.Rotate180, 200, 200, true)] - [DataRow(PdfRotation.Rotate270, 200, 200, true)] - public void WithWidthHeightAspect(PdfRotation? rotation, int? width, int? height, bool withAspectRatio) - { - var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "Rotation", $"hundesteuer-anmeldung_{Enum.GetName(typeof(PdfRotation), rotation ?? PdfRotation.Rotate0)}_{width?.ToString() ?? "null"}x{height?.ToString() ?? "null"}_{withAspectRatio}.png"); - - using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); - using var outputStream = CreateOutputStream(expectedPath); - - if (rotation == null) - SavePng(outputStream, inputStream, options: new(Dpi: 40, Width: width, Height: height, WithAspectRatio: withAspectRatio)); - else - SavePng(outputStream, inputStream, options: new(Dpi: 40, Width: width, Height: height, WithAspectRatio: withAspectRatio, Rotation: rotation.Value)); - - CompareStreams(expectedPath, outputStream); - } - } + [TestClass] + public class RotationTests : TestBase + { + [TestMethod] + [DataRow(null, DisplayName = "Default (no rotation)")] + [DataRow(PdfRotation.Rotate0, DisplayName = "No rotation")] + [DataRow(PdfRotation.Rotate90, DisplayName = "Rotated 90 degrees clockwise")] + [DataRow(PdfRotation.Rotate180, DisplayName = "Rotated 180 degrees")] + [DataRow(PdfRotation.Rotate270, DisplayName = "Rotated 90 degrees counter-clockwise")] + public void SaveWebpPageNumber(PdfRotation? rotation) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "Rotation", $"hundesteuer-anmeldung_{Enum.GetName(typeof(PdfRotation), rotation ?? PdfRotation.Rotate0)}.webp"); + + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); + using var outputStream = CreateOutputStream(expectedPath); + + if (rotation == null) + SaveWebp(outputStream, inputStream, options: new(Dpi: 40)); + else + SaveWebp(outputStream, inputStream, options: new(Dpi: 40, Rotation: rotation.Value)); + + CompareStreams(expectedPath, outputStream); + } + + [TestMethod] + [DataRow(null, DisplayName = "Default (no rotation)")] + [DataRow(PdfRotation.Rotate0, DisplayName = "No rotation")] + [DataRow(PdfRotation.Rotate90, DisplayName = "Rotated 90 degrees clockwise")] + [DataRow(PdfRotation.Rotate180, DisplayName = "Rotated 180 degrees")] + [DataRow(PdfRotation.Rotate270, DisplayName = "Rotated 90 degrees counter-clockwise")] + public void SavePngPageNumber(PdfRotation? rotation) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "Rotation", $"hundesteuer-anmeldung_{Enum.GetName(typeof(PdfRotation), rotation ?? PdfRotation.Rotate0)}.png"); + + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); + using var outputStream = CreateOutputStream(expectedPath); + + if (rotation == null) + SavePng(outputStream, inputStream, options: new(Dpi: 40)); + else + SavePng(outputStream, inputStream, options: new(Dpi: 40, Rotation: rotation.Value)); + + CompareStreams(expectedPath, outputStream); + } + + [TestMethod] + [DataRow(null, DisplayName = "Default (no rotation)")] + [DataRow(PdfRotation.Rotate0, DisplayName = "No rotation")] + [DataRow(PdfRotation.Rotate90, DisplayName = "Rotated 90 degrees clockwise")] + [DataRow(PdfRotation.Rotate180, DisplayName = "Rotated 180 degrees")] + [DataRow(PdfRotation.Rotate270, DisplayName = "Rotated 90 degrees counter-clockwise")] + public void SaveJpegPageNumber(PdfRotation? rotation) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "Rotation", $"hundesteuer-anmeldung_{Enum.GetName(typeof(PdfRotation), rotation ?? PdfRotation.Rotate0)}.jpg"); + + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); + using var outputStream = CreateOutputStream(expectedPath); + + if (rotation == null) + SaveJpeg(outputStream, inputStream, options: new(Dpi: 40)); + else + SaveJpeg(outputStream, inputStream, options: new(Dpi: 40, Rotation: rotation.Value)); + + CompareStreams(expectedPath, outputStream); + } + + [TestMethod] + [DataRow(null, null, null, false)] + [DataRow(PdfRotation.Rotate0, null, null, false)] + [DataRow(PdfRotation.Rotate90, null, null, false)] + [DataRow(PdfRotation.Rotate180, null, null, false)] + [DataRow(PdfRotation.Rotate270, null, null, false)] + [DataRow(null, null, null, true)] + [DataRow(PdfRotation.Rotate0, null, null, true)] + [DataRow(PdfRotation.Rotate90, null, null, true)] + [DataRow(PdfRotation.Rotate180, null, null, true)] + [DataRow(PdfRotation.Rotate270, null, null, true)] + [DataRow(null, 200, null, false)] + [DataRow(PdfRotation.Rotate0, 200, null, false)] + [DataRow(PdfRotation.Rotate90, 200, null, false)] + [DataRow(PdfRotation.Rotate180, 200, null, false)] + [DataRow(PdfRotation.Rotate270, 200, null, false)] + [DataRow(null, 200, null, true)] + [DataRow(PdfRotation.Rotate0, 200, null, true)] + [DataRow(PdfRotation.Rotate90, 200, null, true)] + [DataRow(PdfRotation.Rotate180, 200, null, true)] + [DataRow(PdfRotation.Rotate270, 200, null, true)] + [DataRow(null, null, 200, false)] + [DataRow(PdfRotation.Rotate0, null, 200, false)] + [DataRow(PdfRotation.Rotate90, null, 200, false)] + [DataRow(PdfRotation.Rotate180, null, 200, false)] + [DataRow(PdfRotation.Rotate270, 200, null, false)] + [DataRow(null, null, 200, true)] + [DataRow(PdfRotation.Rotate0, null, 200, true)] + [DataRow(PdfRotation.Rotate90, null, 200, true)] + [DataRow(PdfRotation.Rotate180, null, 200, true)] + [DataRow(PdfRotation.Rotate270, null, 200, true)] + [DataRow(null, 200, 200, false)] + [DataRow(PdfRotation.Rotate0, 200, 200, false)] + [DataRow(PdfRotation.Rotate90, 200, 200, false)] + [DataRow(PdfRotation.Rotate180, 200, 200, false)] + [DataRow(PdfRotation.Rotate270, 200, 200, false)] + [DataRow(null, 200, 200, true)] + [DataRow(PdfRotation.Rotate0, 200, 200, true)] + [DataRow(PdfRotation.Rotate90, 200, 200, true)] + [DataRow(PdfRotation.Rotate180, 200, 200, true)] + [DataRow(PdfRotation.Rotate270, 200, 200, true)] + public void WithWidthHeightAspect(PdfRotation? rotation, int? width, int? height, bool withAspectRatio) + { + var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), "Rotation", $"hundesteuer-anmeldung_{Enum.GetName(typeof(PdfRotation), rotation ?? PdfRotation.Rotate0)}_{width?.ToString() ?? "null"}x{height?.ToString() ?? "null"}_{withAspectRatio}.png"); + + using var inputStream = GetInputStream(Path.Combine("..", "Assets", "hundesteuer-anmeldung.pdf")); + using var outputStream = CreateOutputStream(expectedPath); + + if (rotation == null) + SavePng(outputStream, inputStream, options: new(Dpi: 40, Width: width, Height: height, WithAspectRatio: withAspectRatio)); + else + SavePng(outputStream, inputStream, options: new(Dpi: 40, Width: width, Height: height, WithAspectRatio: withAspectRatio, Rotation: rotation.Value)); + + CompareStreams(expectedPath, outputStream); + } + } } \ No newline at end of file diff --git a/src/Tests/TestBase.cs b/src/Tests/TestBase.cs index 645f888d..54e5e1cd 100644 --- a/src/Tests/TestBase.cs +++ b/src/Tests/TestBase.cs @@ -3,21 +3,21 @@ namespace PDFtoImage.Tests { - public abstract class TestBase - { - public TestContext? TestContext { get; set; } + public abstract class TestBase + { + public TestContext? TestContext { get; set; } - public static bool SaveOutputInGeneratedFolder { get; private set; } + public static bool SaveOutputInGeneratedFolder { get; private set; } - [TestInitialize] - public void Initialize() - { + [TestInitialize] + public void Initialize() + { #if NET6_0_OR_GREATER if (!OperatingSystem.IsWindows() && !OperatingSystem.IsLinux() && !OperatingSystem.IsMacOS()) Assert.Inconclusive("This test must run on Windows, Linux or macOS."); #endif - SaveOutputInGeneratedFolder = bool.Parse(TestContext?.Properties["SaveOutputInGeneratedFolder"]?.ToString() ?? false.ToString()); - } - } + SaveOutputInGeneratedFolder = bool.Parse(TestContext?.Properties["SaveOutputInGeneratedFolder"]?.ToString() ?? false.ToString()); + } + } } \ No newline at end of file diff --git a/src/WebConverter/Models/DummyFile.cs b/src/WebConverter/Models/DummyFile.cs index 3daf0944..5ab976fe 100644 --- a/src/WebConverter/Models/DummyFile.cs +++ b/src/WebConverter/Models/DummyFile.cs @@ -5,8 +5,8 @@ namespace PDFtoImage.WebConverter.Models { - public record DummyFile(string Name, DateTimeOffset LastModified, long Size, string ContentType) : IBrowserFile - { - public Stream OpenReadStream(long maxAllowedSize = 512000, CancellationToken cancellationToken = default) => throw new NotImplementedException(); - } + public record DummyFile(string Name, DateTimeOffset LastModified, long Size, string ContentType) : IBrowserFile + { + public Stream OpenReadStream(long maxAllowedSize = 512000, CancellationToken cancellationToken = default) => throw new NotImplementedException(); + } } diff --git a/src/WebConverter/Models/FileStringyfied.cs b/src/WebConverter/Models/FileStringyfied.cs index c8b0d255..776fd04d 100644 --- a/src/WebConverter/Models/FileStringyfied.cs +++ b/src/WebConverter/Models/FileStringyfied.cs @@ -3,29 +3,29 @@ namespace PDFtoImage.WebConverter.Models { - public partial record FileStringyfied( - [property: JsonPropertyName("name")] - [property: JsonRequired] - string Name, + public partial record FileStringyfied( + [property: JsonPropertyName("name")] + [property: JsonRequired] + string Name, - [property: JsonPropertyName("lastModified")] - [property: JsonRequired] - [property: JsonConverter(typeof(UnixDateTimeConverter))] - DateTimeOffset LastModified, + [property: JsonPropertyName("lastModified")] + [property: JsonRequired] + [property: JsonConverter(typeof(UnixDateTimeConverter))] + DateTimeOffset LastModified, - [property: JsonPropertyName("size")] - [property: JsonRequired] - int Size, + [property: JsonPropertyName("size")] + [property: JsonRequired] + int Size, - [property: JsonPropertyName("type")] - [property: JsonRequired] - string Type, + [property: JsonPropertyName("type")] + [property: JsonRequired] + string Type, - [property: JsonPropertyName("data")] - [property: JsonRequired] - string Data - ) - { - public string GetData() => Data[(Data.IndexOf("base64,") + "base64,".Length)..]; - }; + [property: JsonPropertyName("data")] + [property: JsonRequired] + string Data + ) + { + public string GetData() => Data[(Data.IndexOf("base64,") + "base64,".Length)..]; + }; } \ No newline at end of file diff --git a/src/WebConverter/Models/FilesStringyfied.cs b/src/WebConverter/Models/FilesStringyfied.cs index 1e21bb2a..a4211cb1 100644 --- a/src/WebConverter/Models/FilesStringyfied.cs +++ b/src/WebConverter/Models/FilesStringyfied.cs @@ -2,17 +2,17 @@ namespace PDFtoImage.WebConverter.Models { - public record FilesStringyfied( - [property: JsonPropertyName("title")] - string? Title, + public record FilesStringyfied( + [property: JsonPropertyName("title")] + string? Title, - [property: JsonPropertyName("text")] - string? Text, + [property: JsonPropertyName("text")] + string? Text, - [property: JsonPropertyName("url")] - string? Url, + [property: JsonPropertyName("url")] + string? Url, - [property: JsonPropertyName("files")] - FileStringyfied[]? Files - ); + [property: JsonPropertyName("files")] + FileStringyfied[]? Files + ); } \ No newline at end of file diff --git a/src/WebConverter/Models/UnixDateTimeConverter.cs b/src/WebConverter/Models/UnixDateTimeConverter.cs index 54dbb040..89685846 100644 --- a/src/WebConverter/Models/UnixDateTimeConverter.cs +++ b/src/WebConverter/Models/UnixDateTimeConverter.cs @@ -4,16 +4,16 @@ namespace PDFtoImage.WebConverter.Models { - public class UnixDateTimeConverter : JsonConverter - { - public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - return DateTimeOffset.FromUnixTimeMilliseconds(reader.GetInt64()); - } + public class UnixDateTimeConverter : JsonConverter + { + public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + return DateTimeOffset.FromUnixTimeMilliseconds(reader.GetInt64()); + } - public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options) - { - writer.WriteNumberValue(value.ToUnixTimeMilliseconds()); - } - } + public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options) + { + writer.WriteNumberValue(value.ToUnixTimeMilliseconds()); + } + } } \ No newline at end of file