Skip to content

Enum comparison does not work as expected #1403

@BenGeba

Description

@BenGeba

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

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