I have a couple of object graph comparison cases that I'm struggling to set up with the Fluent Assertions library. Both involve some level of advanced mapping from an object (and Entity Framework entity in this case) to its corresponding DTO.
Case 1: Using the documentation's example of Order and OrderDto, let's say that Product as an associated Manufacturer with a Name property (o.Product.Manufacturer.Name). The ProductDto, though, just has a ManufacturerName property on it instead of
an associated ManufacturerDto (i.e. dto.Product.ManufacturerName = o.Product.Manufacturer.Name).
Case 2: Assume that CustomerDto has a name property on it. The underlying Customer object, though, is split into a FirstName and LastName that are combined when creating the DTO (i.e. dto.Customer.Name = o.Customer.FirstName + " " + o.Customer.LastName).
It looks like these cases can be handled by creating appropriate IMatchingRule and IAssertionRule classes and plugging them in with the Using() method. Is there some more (for lack of a better word) "fluent" way to do this? Something
like:
orderDto.ShouldBeEquivalentTo(order,
opt => opt
.MappingProperty(dto => dto.Product.ManufacturerName).ToProperty(o => o.Product.Manufacturer.Name)
.MappingProperty(dto => dto.Customer.Name).ToValue(o => o.Customer.FirstName + " "+ o.Customer.LastName));
Or maybe:
orderDto.ShouldBeEquivalentTo(order,
opt => opt
.WhereProperty(dto => dto.Product.ManufacturerName, (val, o) => val.Should().Be(o.Product.Manufacturer.Name))
.WhereProperty(dto => dto.Customer.Name, (val, o) => val.Should().Be(o => o.Customer.FirstName + " "+ o.Customer.LastName)));
I may have just missed something obvious, so I figured I would ask before I start writing extensions or forking and hacking.
Many thanks for the library. I wish I had discovered it a year ago.