Skip to content

Asserting ushort, short, and byte shows a conversion in failure message #2729

@siewers

Description

@siewers

Description

When asserting on properties of type ushort, short, and byte, the failure message is slightly more difficult to read than with other unsigned number types.

Reproduction Steps

record Foo(string Text, ushort Number); // `Number` can be ushort, short, or byte
// Arrange
var foo = new Foo("bar", 42);

// Assert
foo.Should().Match<Foo>(x => x.Number < 32 && x.Number > 45);

Expected behavior

The failure message should read:

Expected object to match (x.Number < 32) AndAlso (x.Number > 45), but found Foo
{
    Number = 42us,
    Text = "bar"
}.

Actual behavior

The actual failure message reads:

Expected object to match (Convert(x.Number, Int32) < 32) AndAlso (Convert(x.Number, Int32) > 45), but found Foo
{
    Number = 42us,
    Text = "bar"
}.

Regression?

No response

Known Workarounds

No response

Configuration

FluentAssertions 6.12.0
.NET 8.0

Other information

Other number types besides ushort, short, and byte displays a more readable failure message.

Are you willing to help with a pull-request?

No

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