rspec/rules/S2701/csharp/how-nunit.adoc
2024-02-28 16:24:40 +01:00

33 lines
954 B
Plaintext

== How to fix it in NUnit
=== Code examples
==== Noncompliant code example
[source,csharp,diff-id=2,diff-type=noncompliant]
----
bool someResult;
Assert.AreEqual(false, someResult); // Noncompliant: use Assert.False
Assert.AreEqual(true, someResult); // Noncompliant: use Assert.True
Assert.AreNotEqual(false, someResult); // Noncompliant: use Assert.True
Assert.AreNotEqual(true, someResult); // Noncompliant: use Assert.False
Assert.False(true, "Should not reach this line!"); // Noncompliant: use Assert.Fail
Assert.True(false, "Should not reach this line!"); // Noncompliant: use Assert.Fail
Assert.False(false); // Noncompliant: remove it
----
==== Compliant solution
[source,csharp,diff-id=2,diff-type=compliant]
----
bool someResult;
Assert.False(someResult);
Assert.True(someResult);
Assert.True(someResult);
Assert.False(someResult);
Assert.Fail("Should not reach this line!");
Assert.Fail("Should not reach this line!");
// Removed
----