BeEquivalentTo shows enums as decimal in error message
See original GitHub issueDescription
BeEquivalentTo shows enums as decimal in error message
public enum Color
{
Red,Blue
}
Expected member Color to be 1M, but found 0M.
Complete minimal example reproducing the issue
public enum Color
{
Red,Blue
}
public class Car
{
public Color Color { get; set; }
}
[Fact]
public void Test()
{
var car = new Car
{
Color = Color.Red
};
car.Should().BeEquivalentTo(new Car() { Color = Color.Blue });
}
Expected behavior:
Message: Expected member Color to be Blue, but found Red.
Actual behavior:
Message: Expected member Color to be 1M, but found 0M.
Versions
- FluentAssertions 5.4.1
- .NET Core 2.0
Additional Information
Running in Xunit, when relevant.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
FluentAssertions Should().BeEquivalentTo() fails with Lists ...
c# - FluentAssertions Should(). BeEquivalentTo() fails with Lists containing run-time specified types deriving from identical interface - Stack ...
Read more >Upgrading to version 6.0 - Fluent Assertions
BeEquivalentTo (expectation, opt => opt.ComparingEnumsByValue());. If your assertions rely on the formatting of enums in failure messages, you'll notice that ...
Read more >How to declare enums with float value.
Hi, I'm trying to make and enum that contains informations about the rarity of a item and i'm using enums, but if make...
Read more >Types — Solidity 0.8.20 documentation
Types . Solidity is a statically typed language, which means that the type of each variable (state and local) needs to be...
Read more >Message (Java(TM) EE 7 Specification APIs)
The Message interface is the root interface of all JMS messages. ... An exact numeric literal is a numeric value without a decimal...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for bringing this up.
The default behavior for comparing
enum
s inBeEquivalentTo
is to compare them by value. That is, two (different) enums are considered equivalent if and only if their underlying values are equal.If you want to compare the enums by name instead, you can use
which changes the failure message to
Getting back to your issue, I think the failure message can be improved for both
ComparingEnumsByName
andComparingEnumsByValue
.Some ideas for the failure message:
Expected member Color to be Color.Blue, but found Color.Red.
Expected member Color to be Blue (1), but found Red (0).
Expected member Color to be Color.Blue (1), but found Color.Red (0).
Including more details is useful if one e.g. compares
Color.Red = 0
withAnotherColor.Red = 1
by value. Only displayingMessage: Expected member Color to be Blue, but found Red.
would be confusing.The relevant class is
EnumEqualityStep
.Agree, thanks @krajek!