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

33 lines
977 B
Plaintext

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