Skip to content

Extend NullableBooleanAssertions by NotBe() #1864

@mu88

Description

@mu88

Description

The NullableBooleanAssertions do not support NotBe() at the moment.

Complete minimal example reproducing the issue

// Arrange
bool? input = true;

// Act
bool? result = false;

// Assert
result.Should().NotBe(input);

Expected behavior:

No compiler error

Actual behavior:

Compiler error Argument type 'System.Nullable<bool>' is not assignable to parameter type 'bool':
image

Versions

  • Which version of Fluent Assertions are you using? → 6.5.1
  • Which .NET runtime and version are you targeting? E.g. .NET framework 4.6.1 or .NET Core 2.1. → net6.0

Additional Information

I'm happy to provide a PR if you consider this feature useful. As far as I see, it should only be something like this in NullableBooleanAssertions:

public AndConstraint<TAssertions> NotBe(bool? expected, string because = "", params object[] becauseArgs)
{
    Execute.Assertion
        .ForCondition(Subject != expected)
        .BecauseOf(because, becauseArgs)
        .FailWith("Expected {context:nullable boolean} not to be {0}{reason}, but found {1}.", expected, Subject);

    return new AndConstraint<TAssertions>((TAssertions)this);
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions