diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3c26d81d9..b07697f4f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,7 +11,7 @@ List of new features.
- Two new overloads to the `RenderFragment()` and `ChildContent()` component parameter factory methods have been added that takes a `RenderFragment` as input. By [@egil](https://github.com/egil) in [#203](https://github.com/egil/bUnit/pull/203).
- Added a `ComponentParameterCollection` type. The `ComponentParameterCollection` is a collection of component parameters, that knows how to turn those components parameters into a `RenderFragment`, which will render a component and pass any parameters inside the collection to that component. That logic was spread out over multiple places in bUnit, and is now owned by the `ComponentParameterCollection` type. By [@egil](https://github.com/egil) in [#203](https://github.com/egil/bUnit/pull/203).
-- Added additional placeholder services for `NavigationManager`, `HttpClient`, and `IStringLocalizer`, to make it easier for users to figure out why a test is failing due to missing service registration before rendering a component. By [@joro550](https://github.com/joro550) in [#203](https://github.com/egil/bUnit/pull/223).
+- Added additional placeholder services for `NavigationManager`, `HttpClient`, and `IStringLocalizer`, to make it easier for users to figure out why a test is failing due to missing service registration before rendering a component. By [@joro550](https://github.com/joro550) in [#223](https://github.com/egil/bUnit/pull/223).
### Changed
List of changes in existing functionality.
@@ -34,7 +34,8 @@ List of changes in existing functionality.
);
```
By [@egil](https://github.com/egil) in [#203](https://github.com/egil/bUnit/pull/203).
-- All test doubles are now in the same namespace, `Bunit.TestDoubles`. So all import statements for `Bunit.TestDoubles.JSInterop` and `Bunit.TestDoubles.Authorization` must be changed to `Bunit.TestDoubles`. By [@egil](https://github.com/egil) in [#203](https://github.com/egil/bUnit/pull/223).
+- All test doubles are now in the same namespace, `Bunit.TestDoubles`. So all import statements for `Bunit.TestDoubles.JSInterop` and `Bunit.TestDoubles.Authorization` must be changed to `Bunit.TestDoubles`. By [@egil](https://github.com/egil) in [#223](https://github.com/egil/bUnit/pull/223).
+- Marked MarkupMatches methods as assertion methods to stop SonarSource analyzers complaining about missing assertions in tests. By [@egil](https://github.com/egil) in [#229](https://github.com/egil/bUnit/pull/229).
### Deprecated
List of soon-to-be removed features.
diff --git a/src/bunit.core/Asserting/AssertionMethodAttribute.cs b/src/bunit.core/Asserting/AssertionMethodAttribute.cs
new file mode 100644
index 000000000..cd89e2328
--- /dev/null
+++ b/src/bunit.core/Asserting/AssertionMethodAttribute.cs
@@ -0,0 +1,12 @@
+using System;
+
+namespace Bunit.Asserting
+{
+ ///
+ /// Add this attribute to assertion methods to indicate to
+ /// 3rd party analyzers that the method is an assertion method.
+ /// See more here: https://rules.sonarsource.com/csharp/RSPEC-2699
+ ///
+ [AttributeUsage(AttributeTargets.Method)]
+ public sealed class AssertionMethodAttribute : Attribute { }
+}
diff --git a/src/bunit.web/Asserting/MarkupMatchesAssertExtensions.cs b/src/bunit.web/Asserting/MarkupMatchesAssertExtensions.cs
index 466dd1c9d..37ef2cb86 100644
--- a/src/bunit.web/Asserting/MarkupMatchesAssertExtensions.cs
+++ b/src/bunit.web/Asserting/MarkupMatchesAssertExtensions.cs
@@ -1,5 +1,6 @@
using System;
using AngleSharp.Dom;
+using Bunit.Asserting;
using Bunit.Diffing;
using Bunit.Rendering;
using Microsoft.Extensions.DependencyInjection;
@@ -19,6 +20,7 @@ public static class MarkupMatchesAssertExtensions
/// The markup fragment to verify.
/// The expected markup fragment.
/// A custom user message to display in case the verification fails.
+ [AssertionMethod]
public static void MarkupMatches(this string actual, string expected, string? userMessage = null)
{
using var parser = new BunitHtmlParser();
@@ -35,6 +37,7 @@ public static void MarkupMatches(this string actual, string expected, string? us
/// The markup fragment to verify.
/// The expected .
/// A custom user message to display in case the verification fails.
+ [AssertionMethod]
public static void MarkupMatches(this string actual, IRenderedFragment expected, string? userMessage = null)
{
if (expected is null)
@@ -52,6 +55,7 @@ public static void MarkupMatches(this string actual, IRenderedFragment expected,
/// The markup fragment to verify.
/// The expected .
/// A custom user message to display in case the verification fails.
+ [AssertionMethod]
public static void MarkupMatches(this string actual, INodeList expected, string? userMessage = null)
{
if (expected is null)
@@ -69,6 +73,7 @@ public static void MarkupMatches(this string actual, INodeList expected, string?
/// The markup fragment to verify.
/// The expected .
/// A custom user message to display in case the verification fails.
+ [AssertionMethod]
public static void MarkupMatches(this string actual, INode expected, string? userMessage = null)
{
if (expected is null)
@@ -86,6 +91,7 @@ public static void MarkupMatches(this string actual, INode expected, string? use
/// The rendered fragment to verify.
/// The expected markup.
/// A custom user message to display in case the verification fails.
+ [AssertionMethod]
public static void MarkupMatches(this IRenderedFragment actual, string expected, string? userMessage = null)
{
if (actual is null)
@@ -105,6 +111,7 @@ public static void MarkupMatches(this IRenderedFragment actual, string expected,
/// The rendered fragment to verify.
/// The expected rendered fragment.
/// A custom user message to display in case the verification fails.
+ [AssertionMethod]
public static void MarkupMatches(this IRenderedFragment actual, IRenderedFragment expected, string? userMessage = null)
{
if (actual is null)
@@ -124,6 +131,7 @@ public static void MarkupMatches(this IRenderedFragment actual, IRenderedFragmen
/// The list of nodes to verify.
/// The expected rendered fragment.
/// A custom user message to display in case the verification fails.
+ [AssertionMethod]
public static void MarkupMatches(this INodeList actual, IRenderedFragment expected, string? userMessage = null)
{
if (actual is null)
@@ -143,6 +151,7 @@ public static void MarkupMatches(this INodeList actual, IRenderedFragment expect
/// The node to verify.
/// The expected rendered fragment.
/// A custom user message to display in case the verification fails.
+ [AssertionMethod]
public static void MarkupMatches(this INode actual, IRenderedFragment expected, string? userMessage = null)
{
if (actual is null)
@@ -162,6 +171,7 @@ public static void MarkupMatches(this INode actual, IRenderedFragment expected,
/// The node to verify.
/// The expected markup.
/// A custom user message to display in case the verification fails.
+ [AssertionMethod]
public static void MarkupMatches(this INode actual, string expected, string? userMessage = null)
{
if (actual is null)
@@ -180,6 +190,7 @@ public static void MarkupMatches(this INode actual, string expected, string? use
/// The list of nodes to verify.
/// The expected markup.
/// A custom user message to display in case the verification fails.
+ [AssertionMethod]
public static void MarkupMatches(this INodeList actual, string expected, string? userMessage = null)
{
if (actual is null)
@@ -198,6 +209,7 @@ public static void MarkupMatches(this INodeList actual, string expected, string?
/// The list of nodes to verify.
/// The expected list of nodes.
/// A custom user message to display in case the verification fails.
+ [AssertionMethod]
public static void MarkupMatches(this INodeList actual, INodeList expected, string? userMessage = null)
{
var diffs = actual.CompareTo(expected);
@@ -215,6 +227,7 @@ public static void MarkupMatches(this INodeList actual, INodeList expected, stri
/// The list of nodes to verify.
/// The expected node.
/// A custom user message to display in case the verification fails.
+ [AssertionMethod]
public static void MarkupMatches(this INodeList actual, INode expected, string? userMessage = null)
{
var diffs = actual.CompareTo(expected);
@@ -232,6 +245,7 @@ public static void MarkupMatches(this INodeList actual, INode expected, string?
/// The node to verify.
/// The expected list of nodes.
/// A custom user message to display in case the verification fails.
+ [AssertionMethod]
public static void MarkupMatches(this INode actual, INodeList expected, string? userMessage = null)
{
var diffs = actual.CompareTo(expected);