From 364b5461a5385cca3122afed09585d68d5ef998b Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Mon, 27 Mar 2023 15:45:20 +0200 Subject: [PATCH] Refactor checks. --- .../MagickImageCollectionTests/TheComplexMethod.cs | 4 +--- .../MagickImageTests/TheToBase64Method.cs | 4 ++-- .../MagickImageTests/TheToByteArrayMethod.cs | 6 +++--- tests/Magick.NET.Tests/TestHelpers/TestRuntime.cs | 13 +++++++++++++ 4 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 tests/Magick.NET.Tests/TestHelpers/TestRuntime.cs diff --git a/tests/Magick.NET.Tests/MagickImageCollectionTests/TheComplexMethod.cs b/tests/Magick.NET.Tests/MagickImageCollectionTests/TheComplexMethod.cs index bf51325a60..5358e8b012 100644 --- a/tests/Magick.NET.Tests/MagickImageCollectionTests/TheComplexMethod.cs +++ b/tests/Magick.NET.Tests/MagickImageCollectionTests/TheComplexMethod.cs @@ -32,10 +32,8 @@ public void ShouldThrowExceptionWhenSettingsIsNull() [Fact] public void ShouldApplyTheOperatorToTheImages() { - if (Runtime.IsLinux && Runtime.IsArm64) - { + if (TestRuntime.HasFlakyLinuxArm64Result) return; - } using (var images = new MagickImageCollection()) { diff --git a/tests/Magick.NET.Tests/MagickImageTests/TheToBase64Method.cs b/tests/Magick.NET.Tests/MagickImageTests/TheToBase64Method.cs index da58bb7c22..25ab160e3c 100644 --- a/tests/Magick.NET.Tests/MagickImageTests/TheToBase64Method.cs +++ b/tests/Magick.NET.Tests/MagickImageTests/TheToBase64Method.cs @@ -34,14 +34,14 @@ public void ShouldReturnBase64EncodedStringUsingTheSpecifiedFormat() { var base64 = image.ToBase64(MagickFormat.Jpeg); Assert.NotNull(base64); - if (Runtime.IsLinux && Runtime.IsArm64) + if (TestRuntime.HasFlakyLinuxArm64Result) Assert.InRange(base64.Length, 1140, 1144); else Assert.Equal(1140, base64.Length); var bytes = Convert.FromBase64String(base64); Assert.NotNull(bytes); - if (Runtime.IsLinux && Runtime.IsArm64) + if (TestRuntime.HasFlakyLinuxArm64Result) Assert.InRange(bytes.Length, 853, 858); else Assert.Equal(853, bytes.Length); diff --git a/tests/Magick.NET.Tests/MagickImageTests/TheToByteArrayMethod.cs b/tests/Magick.NET.Tests/MagickImageTests/TheToByteArrayMethod.cs index 7de5097a3e..0836c4b4c1 100644 --- a/tests/Magick.NET.Tests/MagickImageTests/TheToByteArrayMethod.cs +++ b/tests/Magick.NET.Tests/MagickImageTests/TheToByteArrayMethod.cs @@ -32,7 +32,7 @@ public void ShouldReturnImageWithTheSameFormat() var data = image.ToByteArray(); Assert.NotNull(data); - if (Runtime.IsLinux && Runtime.IsArm64) + if (TestRuntime.HasFlakyLinuxArm64Result) Assert.InRange(data.Length, 18830, 18831); else Assert.Equal(18830, data.Length); @@ -56,7 +56,7 @@ public void ShouldUseTheFormatOfTheDefines() var data = image.ToByteArray(defines); Assert.NotNull(data); - if (Runtime.IsLinux && Runtime.IsArm64) + if (TestRuntime.HasFlakyLinuxArm64Result) Assert.InRange(data.Length, 853, 858); else Assert.Equal(853, data.Length); @@ -75,7 +75,7 @@ public void ShouldUseTheSpecifiedFormat() var data = image.ToByteArray(MagickFormat.Jpeg); Assert.NotNull(data); - if (Runtime.IsLinux && Runtime.IsArm64) + if (TestRuntime.HasFlakyLinuxArm64Result) Assert.InRange(data.Length, 60301, 60304); else Assert.Equal(60304, data.Length); diff --git a/tests/Magick.NET.Tests/TestHelpers/TestRuntime.cs b/tests/Magick.NET.Tests/TestHelpers/TestRuntime.cs new file mode 100644 index 0000000000..e8ea34e723 --- /dev/null +++ b/tests/Magick.NET.Tests/TestHelpers/TestRuntime.cs @@ -0,0 +1,13 @@ +// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET. +// Licensed under the Apache License, Version 2.0. + +using ImageMagick; + +namespace Magick.NET.Tests +{ + internal static class TestRuntime + { + public static bool HasFlakyLinuxArm64Result + => Runtime.IsLinux && Runtime.IsArm64; + } +}