Using ShouldBeEquivalentTo and handling different

2019-07-17 19:29发布

问题:

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?

回答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.