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

Enum comparison does not work as expected #1403

Closed
BenGeba opened this issue Oct 5, 2020 · 1 comment · Fixed by #1479
Closed

Enum comparison does not work as expected #1403

BenGeba opened this issue Oct 5, 2020 · 1 comment · Fixed by #1479

Comments

@BenGeba
Copy link

BenGeba commented Oct 5, 2020

Description

According to the documentation, with the standard method Should().Be(), the Enum comparison should work the same as the .NET Implementation Enum.Equals() method.

However, with the following code this does not work for me.

public enum MyEnumResult
{
    Successfully,
    Failed
}

public enum MySecondEnumResult
{
    Successfully,
    AnotherValue,
    Failed
}

[Test]
public void MyTest()
{
    MyEnumResult result = _sut.Get(_id);

    //This works as expected
    result.Should().Be(MyEnumResult.Successfully);
    //This works also, but should not
    result.Should().Be(MySecondEnumResult.Successfully);
}

Although the two enums are not of the same type, the test does not fail. Apparently only the underlying value is tested, but not the type.

Versions

  • Fluent Assertions version is 5.10.3
  • .NET framework 4.7.2
@jnyrup
Copy link
Member

jnyrup commented Oct 5, 2020

Thanks for highlighting this inconsistency of Be for enums.
If you use HaveFlag instead, this should work as expected.

In the upcoming v6 this should be more visible due to #1375.
We also have discussions about reworking this further, see #1204.
Another case of inconsistency is #1208

@jnyrup jnyrup linked a pull request Feb 6, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants