Skip to content

After update to v5, Equals() does not work as expected when using FluentAssersions' .BeEquevalentTo() #1193

Closed
@dmytro-gokun

Description

@dmytro-gokun

After updating to v5 when using FluentAssertions's .BeEquiavalentTo() on classes having UnitNet's types as members, we get false negatives, like:

Expected property actual.Mileage to be 0 m, but found 0 km

This worked properly in v4.

As far as I can understand, the reason for this is that .BeEquiavalentTo() uses .Equals() method which is implemented as:

        public bool Equals(Length other)
        {
            return new { Value, Unit }.Equals(new { other.Value, other.Unit });
        }

IMO, this is incorrect behavior. 0 km == 0m, 1km == 1000 m etc. Is not that a valid assumption when writing unit tests?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions