'Using ShouldBeEquivalentTo and handling different names

I want to make a mapper test that maps a database model to a dto

In the database model there is

class Order
{
    long Id
}

But on the Dto the same field is named

class OrderDto
{
    long OrderId
}

Using ShouldBeEquivalentTo how do I tell FluentAssertions that these fields are the same, but the name is different?



Solution 1:[1]

Its not exactly what you are asking for, but you can override the assertion comparison completely in fluent assertions for a given property with Using When. Its a little clunky and long winded syntax though if you need to do a lot of them. Probably the closest thing I can think of in there.

Solution 2:[2]

This should finally be possible in 6.5 release: ?

orderDto.Should().BeEquivalentTo(order, options => options
    .WithMapping<OrderDto>(e => e.Id, s => s.OrderId));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gmn
Solution 2 Victor Fialkin