diff --git a/readme.md b/readme.md
index 5965b19..c10eea1 100644
--- a/readme.md
+++ b/readme.md
@@ -48,7 +48,7 @@ The following will use ImageHash to compare the images instead of the default Di
```cs
[Test]
public Task CompareImage() =>
- VerifyFile("sample.jpg");
+ VerifyFile("sample1.jpg");
```
snippet source | anchor
diff --git a/src/Directory.Build.props b/src/Directory.Build.props
index 77a5f5c..0bd62d2 100644
--- a/src/Directory.Build.props
+++ b/src/Directory.Build.props
@@ -2,7 +2,7 @@
CS1591;CS0649;NU1608;NU1109
- 3.0.2
+ 3.0.3
1.0.0
preview
enable
@@ -13,4 +13,4 @@
true
true
-
\ No newline at end of file
+
diff --git a/src/Tests.CustomThreshold/ModuleInitializer.cs b/src/Tests.CustomThreshold/ModuleInitializer.cs
new file mode 100644
index 0000000..c2c8e3c
--- /dev/null
+++ b/src/Tests.CustomThreshold/ModuleInitializer.cs
@@ -0,0 +1,9 @@
+static class ModuleInitializer
+{
+ [ModuleInitializer]
+ public static void Init()
+ {
+ VerifyImageSharpCompare.RegisterComparers(threshold: 10);
+ VerifierSettings.InitializePlugins();
+ }
+}
diff --git a/src/Tests/sample.jpg b/src/Tests.CustomThreshold/Tests.CompareImageWithCustomThreshold.verified.jpg
similarity index 100%
rename from src/Tests/sample.jpg
rename to src/Tests.CustomThreshold/Tests.CompareImageWithCustomThreshold.verified.jpg
diff --git a/src/Tests.CustomThreshold/Tests.CustomThreshold.csproj b/src/Tests.CustomThreshold/Tests.CustomThreshold.csproj
new file mode 100644
index 0000000..3c50bd2
--- /dev/null
+++ b/src/Tests.CustomThreshold/Tests.CustomThreshold.csproj
@@ -0,0 +1,17 @@
+
+
+
+ net8.0
+
+
+
+
+
+
+
+
+
+ PreserveNewest
+
+
+
diff --git a/src/Tests.CustomThreshold/Tests.FailingCompare.verified.txt b/src/Tests.CustomThreshold/Tests.FailingCompare.verified.txt
new file mode 100644
index 0000000..2b80aa4
--- /dev/null
+++ b/src/Tests.CustomThreshold/Tests.FailingCompare.verified.txt
@@ -0,0 +1,23 @@
+{
+ Type: VerifyException,
+ Message:
+Directory: {ProjectDirectory}
+NotEqual:
+ - Received: Tests.FailingCompareInner.received.jpg
+ Verified: Tests.FailingCompareInner.verified.jpg
+
+FileContent:
+
+NotEqual:
+
+Received: Tests.FailingCompareInner.received.jpg
+Verified: Tests.FailingCompareInner.verified.jpg
+Compare Result:
+similarity(159345906) > threshold(10).
+If this difference is acceptable, use:
+
+ * Globally: VerifyImageSharpCompare.RegisterComparers(159345906);
+ * For one test: Verifier.VerifyFile("file.jpg").UseImageHash(159345906);
+
+
+}
\ No newline at end of file
diff --git a/src/Tests.CustomThreshold/Tests.FailingCompareInner.verified.jpg b/src/Tests.CustomThreshold/Tests.FailingCompareInner.verified.jpg
new file mode 100644
index 0000000..dfbb05b
Binary files /dev/null and b/src/Tests.CustomThreshold/Tests.FailingCompareInner.verified.jpg differ
diff --git a/src/Tests.CustomThreshold/Tests.Working.verified.jpg b/src/Tests.CustomThreshold/Tests.Working.verified.jpg
new file mode 100644
index 0000000..dfbb05b
Binary files /dev/null and b/src/Tests.CustomThreshold/Tests.Working.verified.jpg differ
diff --git a/src/Tests.CustomThreshold/Tests.cs b/src/Tests.CustomThreshold/Tests.cs
new file mode 100644
index 0000000..8623351
--- /dev/null
+++ b/src/Tests.CustomThreshold/Tests.cs
@@ -0,0 +1,18 @@
+[TestFixture]
+public class Tests
+{
+ [Test]
+ public Task Working() =>
+ VerifyFile("sample1.jpg");
+
+ [Test]
+ public Task FailingCompare() =>
+ ThrowsTask(async () =>
+ {
+ await VerifyFile("sample2.jpg")
+ .DisableDiff()
+ .UseMethodName("FailingCompareInner");
+ })
+ .IgnoreStackTrace()
+ .ScrubLinesContaining("clipboard", "DiffEngineTray");
+}
diff --git a/src/Tests.CustomThreshold/sample1.jpg b/src/Tests.CustomThreshold/sample1.jpg
new file mode 100644
index 0000000..dfbb05b
Binary files /dev/null and b/src/Tests.CustomThreshold/sample1.jpg differ
diff --git a/src/Tests.CustomThreshold/sample2.jpg b/src/Tests.CustomThreshold/sample2.jpg
new file mode 100644
index 0000000..df77612
Binary files /dev/null and b/src/Tests.CustomThreshold/sample2.jpg differ
diff --git a/src/Tests/Samples.cs b/src/Tests/Samples.cs
index 91fd595..7710209 100644
--- a/src/Tests/Samples.cs
+++ b/src/Tests/Samples.cs
@@ -5,7 +5,7 @@ public class Samples
[Test]
public Task CompareImage() =>
- VerifyFile("sample.jpg");
+ VerifyFile("sample1.jpg");
#endregion
-}
\ No newline at end of file
+}
diff --git a/src/Tests/Tests.FailingCompare.verified.txt b/src/Tests/Tests.FailingCompare.verified.txt
index 88bdb31..54d0431 100644
--- a/src/Tests/Tests.FailingCompare.verified.txt
+++ b/src/Tests/Tests.FailingCompare.verified.txt
@@ -13,7 +13,11 @@ NotEqual:
Received: Tests.FailingCompareInner.received.jpg
Verified: Tests.FailingCompareInner.verified.jpg
Compare Result:
-Size of images differ.
+similarity(159345906) > threshold(85).
+If this difference is acceptable, use:
+
+ * Globally: VerifyImageSharpCompare.RegisterComparers(159345906);
+ * For one test: Verifier.VerifyFile("file.jpg").UseImageHash(159345906);
}
\ No newline at end of file
diff --git a/src/Tests/Tests.FailingCompareInner.verified.jpg b/src/Tests/Tests.FailingCompareInner.verified.jpg
index e8c0584..dfbb05b 100644
Binary files a/src/Tests/Tests.FailingCompareInner.verified.jpg and b/src/Tests/Tests.FailingCompareInner.verified.jpg differ
diff --git a/src/Tests/Tests.Working.verified.jpg b/src/Tests/Tests.Working.verified.jpg
new file mode 100644
index 0000000..dfbb05b
Binary files /dev/null and b/src/Tests/Tests.Working.verified.jpg differ
diff --git a/src/Tests/Tests.cs b/src/Tests/Tests.cs
index a8749d0..a5eb336 100644
--- a/src/Tests/Tests.cs
+++ b/src/Tests/Tests.cs
@@ -1,15 +1,19 @@
[TestFixture]
public class Tests
{
+ [Test]
+ public Task Working() =>
+ VerifyFile("sample1.jpg");
+
[Test]
public Task FailingCompare() =>
ThrowsTask(async () =>
{
- await VerifyFile("sample.jpg")
+ await VerifyFile("sample2.jpg")
.DisableDiff()
.UseMethodName("FailingCompareInner")
.UseImageHash(85);
})
.IgnoreStackTrace()
.ScrubLinesContaining("clipboard", "DiffEngineTray");
-}
\ No newline at end of file
+}
diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj
index e36a1b4..b63e708 100644
--- a/src/Tests/Tests.csproj
+++ b/src/Tests/Tests.csproj
@@ -1,7 +1,7 @@
- net8.0
+ net10.0
@@ -12,7 +12,7 @@
-
+
PreserveNewest
diff --git a/src/Tests/sample1.jpg b/src/Tests/sample1.jpg
new file mode 100644
index 0000000..dfbb05b
Binary files /dev/null and b/src/Tests/sample1.jpg differ
diff --git a/src/Tests/sample2.jpg b/src/Tests/sample2.jpg
new file mode 100644
index 0000000..df77612
Binary files /dev/null and b/src/Tests/sample2.jpg differ
diff --git a/src/Verify.ImageSharp.Compare.slnx b/src/Verify.ImageSharp.Compare.slnx
index 48d2e31..f5c1050 100644
--- a/src/Verify.ImageSharp.Compare.slnx
+++ b/src/Verify.ImageSharp.Compare.slnx
@@ -13,6 +13,7 @@
+
\ No newline at end of file
diff --git a/src/Verify.ImageSharp.Compare/VerifyImageSharpCompare.cs b/src/Verify.ImageSharp.Compare/VerifyImageSharpCompare.cs
index de4b1de..2870333 100644
--- a/src/Verify.ImageSharp.Compare/VerifyImageSharpCompare.cs
+++ b/src/Verify.ImageSharp.Compare/VerifyImageSharpCompare.cs
@@ -2,6 +2,8 @@
public static class VerifyImageSharpCompare
{
+ static HashSet registeredComparers = [];
+
public static bool Initialized { get; private set; }
///
@@ -23,6 +25,7 @@ public static void Initialize()
public static void RegisterComparers(int threshold = 5)
{
InnerVerifier.ThrowIfVerifyHasBeenRun();
+
RegisterComparer(threshold, "png");
RegisterComparer(threshold, "bmp");
RegisterComparer(threshold, "jpg");
@@ -36,10 +39,17 @@ public static SettingsTask UseImageHash(this SettingsTask settings, int threshol
settings.UseStreamComparer(
(received, verified, _) => Compare(threshold, received, verified));
- public static void RegisterComparer(int threshold, string extension) =>
+ public static void RegisterComparer(int threshold, string extension)
+ {
+ if (!registeredComparers.Add(extension))
+ {
+ return;
+ }
+
VerifierSettings.RegisterStreamComparer(
extension,
(received, verified, _) => Compare(threshold, received, verified));
+ }
static Task Compare(int threshold, Stream received, Stream verified)
{
@@ -72,4 +82,4 @@ static Task Compare(int threshold, Stream received, Stream verifi
* For one test: Verifier.VerifyFile("file.jpg").UseImageHash({absoluteError});
"""));
}
-}
\ No newline at end of file
+}