Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Mikkel Nylander Bundgaard <[email protected]>
  • Loading branch information
manfred-brands and mikkelbu authored Feb 3, 2025
1 parent ab66d67 commit dee9068
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions documentation/NUnit4002.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,41 @@ Replace 'EqualTo' with a keyword in the corresponding specific constraint.

## Motivation

ADD MOTIVATION HERE
Sometimes constraints can be written more concisely using the inbuilt constraints provided by NUnit -
e.g. `Is.True` instead of `Is.EqualTo(true)`.

Also, from NUnit version 4.3.0 where new overloads of `Is.EqualTo` were introduced, it is sometimes
not possible to uniquely determine `default` when provided as the expected value - e.g. in
`Is.EqualTo(default)`. Again, in such cases, it is better to use the inbuilt constraint provided by NUnit.

Some examples of constraints that can be be simplified by using a more specific constraint can be seen below.

```csharp
[Test]
public void Test()
{
Assert.That(actualFalse, Is.EqualTo(false));
Assert.That(actualTrue, Is.EqualTo(true));
Assert.That(actualObject, Is.EqualTo(null));
Assert.That(actualObject, Is.EqualTo(default));
Assert.That(actualInt, Is.EqualTo(default));
}

## How to fix violations

ADD HOW TO FIX VIOLATIONS HERE
The analyzer comes with a code fix that will replace the constraint `Is.EqualTo(x)` with
the matching `Is.X` constraint (for some `x`). So the code block above will be changed into

```csharp
[Test]
public void Test()
{
Assert.That(actualFalse, Is.False);
Assert.That(actualTrue, Is.True);
Assert.That(actualObject, Is.Null);
Assert.That(actualObject, Is.Null);
Assert.That(actualInt, Is.Default);
}

<!-- start generated config severity -->
## Configure severity
Expand Down

0 comments on commit dee9068

Please sign in to comment.