Skip to content
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

Extend NullableBooleanAssertions by NotBe() #1864

Closed
mu88 opened this issue Mar 24, 2022 · 1 comment · Fixed by #1865
Closed

Extend NullableBooleanAssertions by NotBe() #1864

mu88 opened this issue Mar 24, 2022 · 1 comment · Fixed by #1865

Comments

@mu88
Copy link
Contributor

mu88 commented Mar 24, 2022

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);
}
@dennisdoomen
Copy link
Member

Sure. Go ahead.

mu88 added a commit to swisspost/fluentassertions that referenced this issue Mar 24, 2022
mu88 added a commit to swisspost/fluentassertions that referenced this issue Mar 28, 2022
@jnyrup jnyrup changed the title Extend NullableBooleanAssertions by NotBe() Extend NullableBooleanAssertions by NotBe() Apr 16, 2022
@jnyrup jnyrup linked a pull request Apr 16, 2022 that will close this issue
5 tasks
@jnyrup jnyrup closed this as completed Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants