From b0b5935eaa17019f24baab3c91511c71d837a829 Mon Sep 17 00:00:00 2001 From: Gut Daniel AVENIQ Date: Thu, 16 Feb 2023 08:57:36 +0100 Subject: [PATCH] feat: add assert attributes to assert methods --- src/Snapshooter.Json/JsonAssert.cs | 3 ++- src/Snapshooter.Json/Snapshot.cs | 6 +++++- src/Snapshooter.MSTest/Snapshot.cs | 10 ++++++++++ src/Snapshooter.MSTest/SnapshotExtension.cs | 5 +++++ src/Snapshooter.NUnit/Snapshot.cs | 12 +++++++++++- src/Snapshooter.NUnit/SnapshotExtension.cs | 5 +++++ src/Snapshooter.Xunit/Snapshot.cs | 12 +++++++++++- src/Snapshooter.Xunit/SnapshotExtension.cs | 5 +++++ src/Snapshooter/AssertionMethodAttribute.cs | 8 ++++++++ 9 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 src/Snapshooter/AssertionMethodAttribute.cs diff --git a/src/Snapshooter.Json/JsonAssert.cs b/src/Snapshooter.Json/JsonAssert.cs index 98e7132..d5db495 100644 --- a/src/Snapshooter.Json/JsonAssert.cs +++ b/src/Snapshooter.Json/JsonAssert.cs @@ -1,4 +1,4 @@ -using System; +using System; using Snapshooter.Core; using Snapshooter.Exceptions; @@ -15,6 +15,7 @@ public class JsonAssert : IAssert /// /// The expected snapshot. /// The actual snapshot. + [AssertionMethod] public virtual void Assert(string expectedSnapshot, string actualSnapshot) { int snapshotCompare = string.Compare( diff --git a/src/Snapshooter.Json/Snapshot.cs b/src/Snapshooter.Json/Snapshot.cs index 42f1eb1..de5f82f 100644 --- a/src/Snapshooter.Json/Snapshot.cs +++ b/src/Snapshooter.Json/Snapshot.cs @@ -1,4 +1,4 @@ -using System; +using System; using Snapshooter.Core; using Snapshooter.Core.Serialization; @@ -26,6 +26,7 @@ public static class Snapshot /// /// Additional compare actions, which can be applied during the comparison /// + [AssertionMethod] public static void Match(T currentResult, string snapshotName, Func matchOptions = null) @@ -56,6 +57,7 @@ public static void Match(T currentResult, /// /// Additional compare actions, which can be applied during the comparison /// + [AssertionMethod] public static void Match(T currentResult, string snapshotName, SnapshotNameExtension snapshotNameExtension, @@ -77,6 +79,7 @@ public static void Match(T currentResult, /// /// Additional compare actions, which can be applied during the comparison /// + [AssertionMethod] public static void Match(object currentResult, string snapshotName, Func matchOptions = null) @@ -108,6 +111,7 @@ public static void Match(object currentResult, /// /// Additional compare actions, which can be applied during the comparison /// + [AssertionMethod] public static void Match(object currentResult, string snapshotName, SnapshotNameExtension snapshotNameExtension, diff --git a/src/Snapshooter.MSTest/Snapshot.cs b/src/Snapshooter.MSTest/Snapshot.cs index 22d793e..8bd6208 100644 --- a/src/Snapshooter.MSTest/Snapshot.cs +++ b/src/Snapshooter.MSTest/Snapshot.cs @@ -27,6 +27,7 @@ public static class Snapshot /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void Match( T currentResult, Func matchOptions = null) @@ -54,6 +55,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void Match( T currentResult, SnapshotNameExtension snapshotNameExtension, @@ -77,6 +79,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void Match( T currentResult, string snapshotName, @@ -109,6 +112,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void Match( T currentResult, string snapshotName, @@ -130,6 +134,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison. /// + [AssertionMethod] public static void Match( T currentResult, SnapshotFullName snapshotFullName, @@ -148,6 +153,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void Match( object currentResult, Func matchOptions = null) @@ -181,6 +187,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void Match( object currentResult, SnapshotNameExtension snapshotNameExtension, @@ -203,6 +210,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void Match( object currentResult, string snapshotName, @@ -234,6 +242,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison. /// + [AssertionMethod] public static void Match( object currentResult, string snapshotName, @@ -255,6 +264,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison. /// + [AssertionMethod] public static void Match( object currentResult, SnapshotFullName snapshotFullName, diff --git a/src/Snapshooter.MSTest/SnapshotExtension.cs b/src/Snapshooter.MSTest/SnapshotExtension.cs index 6336d0b..393c7d8 100644 --- a/src/Snapshooter.MSTest/SnapshotExtension.cs +++ b/src/Snapshooter.MSTest/SnapshotExtension.cs @@ -14,6 +14,7 @@ public static class SnapshotExtension /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void MatchSnapshot( this object currentResult, Func matchOptions = null) @@ -41,6 +42,7 @@ public static void MatchSnapshot( /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void MatchSnapshot( this object currentResult, SnapshotNameExtension snapshotNameExtension, @@ -64,6 +66,7 @@ public static void MatchSnapshot( /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void MatchSnapshot( this object currentResult, string snapshotName, @@ -96,6 +99,7 @@ public static void MatchSnapshot( /// /// Additional compare actions, which can be applied during the snapshot comparison. /// + [AssertionMethod] public static void MatchSnapshot( this object currentResult, string snapshotName, @@ -119,6 +123,7 @@ public static void MatchSnapshot( /// /// Additional compare actions, which can be applied during the snapshot comparison. /// + [AssertionMethod] public static void MatchSnapshot( this object currentResult, SnapshotFullName snapshotFullName, diff --git a/src/Snapshooter.NUnit/Snapshot.cs b/src/Snapshooter.NUnit/Snapshot.cs index bd38485..e33f55d 100644 --- a/src/Snapshooter.NUnit/Snapshot.cs +++ b/src/Snapshooter.NUnit/Snapshot.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading; using Snapshooter.Core; using Snapshooter.Core.Serialization; @@ -28,6 +28,7 @@ public static class Snapshot /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void Match( T currentResult, Func matchOptions = null) @@ -55,6 +56,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void Match( T currentResult, SnapshotNameExtension snapshotNameExtension, @@ -78,6 +80,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void Match( T currentResult, string snapshotName, @@ -110,6 +113,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void Match( T currentResult, string snapshotName, @@ -131,6 +135,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison. /// + [AssertionMethod] public static void Match( T currentResult, SnapshotFullName snapshotFullName, @@ -149,6 +154,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void Match( object currentResult, Func matchOptions = null) @@ -175,6 +181,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void Match( object currentResult, SnapshotNameExtension snapshotNameExtension, @@ -197,6 +204,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void Match( object currentResult, string snapshotName, @@ -228,6 +236,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison. /// + [AssertionMethod] public static void Match( object currentResult, string snapshotName, @@ -249,6 +258,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison. /// + [AssertionMethod] public static void Match( object currentResult, SnapshotFullName snapshotFullName, diff --git a/src/Snapshooter.NUnit/SnapshotExtension.cs b/src/Snapshooter.NUnit/SnapshotExtension.cs index b57d5f8..02261f4 100644 --- a/src/Snapshooter.NUnit/SnapshotExtension.cs +++ b/src/Snapshooter.NUnit/SnapshotExtension.cs @@ -14,6 +14,7 @@ public static class SnapshotExtension /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void MatchSnapshot( this object currentResult, Func matchOptions = null) @@ -41,6 +42,7 @@ public static void MatchSnapshot( /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void MatchSnapshot( this object currentResult, SnapshotNameExtension snapshotNameExtension, @@ -64,6 +66,7 @@ public static void MatchSnapshot( /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void MatchSnapshot( this object currentResult, string snapshotName, @@ -96,6 +99,7 @@ public static void MatchSnapshot( /// /// Additional compare actions, which can be applied during the snapshot comparison. /// + [AssertionMethod] public static void MatchSnapshot( this object currentResult, string snapshotName, @@ -119,6 +123,7 @@ public static void MatchSnapshot( /// /// Additional compare actions, which can be applied during the snapshot comparison. /// + [AssertionMethod] public static void MatchSnapshot( this object currentResult, SnapshotFullName snapshotFullName, diff --git a/src/Snapshooter.Xunit/Snapshot.cs b/src/Snapshooter.Xunit/Snapshot.cs index 2d62eb1..52fe1b9 100644 --- a/src/Snapshooter.Xunit/Snapshot.cs +++ b/src/Snapshooter.Xunit/Snapshot.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading; using Snapshooter.Core; using Snapshooter.Core.Serialization; @@ -28,6 +28,7 @@ public static class Snapshot /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void Match( T currentResult, Func matchOptions = null) @@ -55,6 +56,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void Match( T currentResult, SnapshotNameExtension snapshotNameExtension, @@ -78,6 +80,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void Match( T currentResult, string snapshotName, @@ -110,6 +113,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void Match( T currentResult, string snapshotName, @@ -131,6 +135,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison. /// + [AssertionMethod] public static void Match( T currentResult, SnapshotFullName snapshotFullName, @@ -149,6 +154,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void Match( object currentResult, Func matchOptions = null) @@ -182,6 +188,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void Match( object currentResult, SnapshotNameExtension snapshotNameExtension, @@ -204,6 +211,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void Match( object currentResult, string snapshotName, @@ -235,6 +243,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison. /// + [AssertionMethod] public static void Match( object currentResult, string snapshotName, @@ -256,6 +265,7 @@ public static void Match( /// /// Additional compare actions, which can be applied during the snapshot comparison. /// + [AssertionMethod] public static void Match( object currentResult, SnapshotFullName snapshotFullName, diff --git a/src/Snapshooter.Xunit/SnapshotExtension.cs b/src/Snapshooter.Xunit/SnapshotExtension.cs index afdff1c..dfad32b 100644 --- a/src/Snapshooter.Xunit/SnapshotExtension.cs +++ b/src/Snapshooter.Xunit/SnapshotExtension.cs @@ -14,6 +14,7 @@ public static class SnapshotExtension /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void MatchSnapshot( this object currentResult, Func matchOptions = null) @@ -41,6 +42,7 @@ public static void MatchSnapshot( /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void MatchSnapshot( this object currentResult, SnapshotNameExtension snapshotNameExtension, @@ -64,6 +66,7 @@ public static void MatchSnapshot( /// /// Additional compare actions, which can be applied during the snapshot comparison /// + [AssertionMethod] public static void MatchSnapshot( this object currentResult, string snapshotName, @@ -96,6 +99,7 @@ public static void MatchSnapshot( /// /// Additional compare actions, which can be applied during the snapshot comparison. /// + [AssertionMethod] public static void MatchSnapshot( this object currentResult, string snapshotName, @@ -119,6 +123,7 @@ public static void MatchSnapshot( /// /// Additional compare actions, which can be applied during the snapshot comparison. /// + [AssertionMethod] public static void MatchSnapshot( this object currentResult, SnapshotFullName snapshotFullName, diff --git a/src/Snapshooter/AssertionMethodAttribute.cs b/src/Snapshooter/AssertionMethodAttribute.cs new file mode 100644 index 0000000..ce603a1 --- /dev/null +++ b/src/Snapshooter/AssertionMethodAttribute.cs @@ -0,0 +1,8 @@ +using System; + +namespace Snapshooter +{ + // Attribute to flag assert methods + // https://rules.sonarsource.com/csharp/RSPEC-2699 + public class AssertionMethodAttribute : Attribute { } +}