Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify rule S2970: Improve description of supported test library functions #1518

Merged
merged 4 commits into from Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions rules/S2970/csharp/rule.adoc
@@ -1,19 +1,35 @@
include::../description.adoc[]
It is very easy to write incomplete assertions when using some test frameworks. This rule enforces complete assertions in the following cases:

* Fluent Assertions: https://fluentassertions.com/introduction[`Should()`] is not followed by an assertion invocation.
* NFluent: https://www.n-fluent.net[`Check.That()`] is not followed by an assertion invocation.
* NSubstitute: https://nsubstitute.github.io/help/received-calls[`Received()`] is not followed by an invocation.

In such cases, what is intended to be a test doesn't actually verify anything.

== Noncompliant Code Example

[source,csharp]
----
string actual = "Hello World!";
actual.Should(); // Noncompliant
// Fluent Assertions
actual.Should(); // Noncompliant
// NFluent
Check.That(actual); // Noncompliant
// NSubstitute
command.Received(); // Noncompliant
----

== Compliant Solution

[source,csharp]
----
string actual = "Hello World!";
// Fluent Assertions
actual.Should().Contain("Hello");
// NFluent
Check.That(actual).Contains("Hello");
// NSubstitute
command.Received().Execute();
----

ifdef::env-github,rspecator-view[]
Expand Down
1 change: 0 additions & 1 deletion rules/S2970/description.adoc

This file was deleted.