Skip to content

No FAA0001 when ?. is followed by Should().BeApproximately #405

Description

@JeppeSN

Suppose for the sake of this bug report that we have the following type:

public interface IExample {
    double Amount { get; }
}

Then if we write the following incorrect test:

public void TestMethod() {
    IExample? actual = null;

    actual?.Amount.Should().BeApproximately(3.14, 0.01);   // no FAA0001 here?!
}

then we get no message from FluentAssertions.Analyzers about the wrong code.

For other assertions, this works fine. For example:

    actual?.Amount.Should().BeGreaterThan(3.1);  // good, we get 'FAA0001: Use .Should() instead of ?.Should()'

or:

    actual?.Amount.Should().BePositive();  // good, we get 'FAA0001: Use .Should() instead of ?.Should()'

or:

    actual?.Amount.Should().BeInRange(3.1, 3.2);  // good, we get 'FAA0001: Use .Should() instead of ?.Should()'

We need the FAA0001 with .BeApproximately(3.14, 0.01) as well. Without it, the author may think his tests proves actual is an instance where Amount equals 3.14 within a tolerance of 0.01 when in fact actual is a null reference (and no Amount exists).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions