Skip to content

feat: add nunit null asserts migration docs #333

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

Merged
merged 1 commit into from
May 13, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions docs/NunitAnalyzer.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This is a generated file, please edit src\FluentAssertions.Analyzers.FluentAsser

- [BooleanAssertIsTrue](#scenario-booleanassertistrue) - `flag.Should().BeTrue();`
- [BooleanAssertIsFalse](#scenario-booleanassertisfalse) - `flag.Should().BeFalse();`
- [AssertNull](#scenario-assertnull) - `obj.Should().BeNull();`
- [AssertNotNull](#scenario-assertnotnull) - `obj.Should().NotBeNull();`


## Scenarios
Expand Down Expand Up @@ -72,4 +74,66 @@ Assert.IsFalse(flag); /* fail message: Expected: False
flag.Should().BeFalse(); /* fail message: Expected flag to be false, but found True. */
```

### scenario: AssertNull

```cs
// arrange
object obj = null;

// old assertion:
Assert.IsNull(obj);
Assert.Null(obj);

// new assertion:
obj.Should().BeNull();
```

#### Failure messages

```cs
object obj = "foo";

// old assertion:
Assert.Null(obj); /* fail message: Expected: null
But was: "foo"
*/
Assert.IsNull(obj); /* fail message: Expected: null
But was: "foo"
*/

// new assertion:
obj.Should().BeNull(); /* fail message: Expected obj to be <null>, but found "foo". */
```

### scenario: AssertNotNull

```cs
// arrange
object obj = "foo";

// old assertion:
Assert.IsNotNull(obj);
Assert.NotNull(obj);

// new assertion:
obj.Should().NotBeNull();
```

#### Failure messages

```cs
object obj = null;

// old assertion:
Assert.NotNull(obj); /* fail message: Expected: not null
But was: null
*/
Assert.IsNotNull(obj); /* fail message: Expected: not null
But was: null
*/

// new assertion:
obj.Should().NotBeNull(); /* fail message: Expected obj not to be <null>. */
```


Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,92 @@ public void BooleanAssertIsFalse_Failure_NewAssertion()
// new assertion:
flag.Should().BeFalse();
}

[TestMethod]
public void AssertNull()
{
// arrange
object obj = null;

// old assertion:
Assert.IsNull(obj);
Assert.Null(obj);

// new assertion:
obj.Should().BeNull();
}

[TestMethod, ExpectedTestFrameworkException]
public void AssertNull_Failure_OldAssertion_0()
{
// arrange
object obj = "foo";

// old assertion:
Assert.Null(obj);
}

[TestMethod, ExpectedTestFrameworkException]
public void AssertNull_Failure_OldAssertion_1()
{
// arrange
object obj = "foo";

// old assertion:
Assert.IsNull(obj);
}

[TestMethod, ExpectedTestFrameworkException]
public void AssertNull_Failure_NewAssertion()
{
// arrange
object obj = "foo";

// new assertion:
obj.Should().BeNull();
}

[TestMethod]
public void AssertNotNull()
{
// arrange
object obj = "foo";

// old assertion:
Assert.IsNotNull(obj);
Assert.NotNull(obj);

// new assertion:
obj.Should().NotBeNull();
}

[TestMethod, ExpectedTestFrameworkException]
public void AssertNotNull_Failure_OldAssertion_0()
{
// arrange
object obj = null;

// old assertion:
Assert.NotNull(obj);
}

[TestMethod, ExpectedTestFrameworkException]
public void AssertNotNull_Failure_OldAssertion_1()
{
// arrange
object obj = null;

// old assertion:
Assert.IsNotNull(obj);
}

[TestMethod, ExpectedTestFrameworkException]
public void AssertNotNull_Failure_NewAssertion()
{
// arrange
object obj = null;

// new assertion:
obj.Should().NotBeNull();
}
}
Loading