Quantcast
Channel: Fluent Assertions
Viewing all articles
Browse latest Browse all 1402

New Post: Mappings in object graph comparisons

$
0
0

Hi leoghann,

Thanks for taking the time to properly formulate your question. What you might want to do is use theUsing-When methods of the options object. The EquivalencySpecs you'll find some examples like these:

            Action act = () => subject.ShouldBeEquivalentTo(expectation, options => options
                .Using<DateTime>(ctx => ctx.Subject.Should().BeCloseTo(ctx.Expectation, 1000))
                .When(info => info.PropertyPath.EndsWith("Date")));

 or

            Action act = () => subject.ShouldBeEquivalentTo(expectation, options => 
                options
                .Using<DateTime>(ctx => ctx.Subject.Should().BeCloseTo(ctx.Expectation, 1000))
                .WhenTypeIs<DateTime>());


If you really want to make it fluent, I would rewrite your example as

orderDto.ShouldBeEquivalentTo(order,
    opt => opt
        .Where(dto => dto.Product.ManufacturerName).ShouldMapTo(o => o.Product.Manufacturer.Name)
        .Where(dto => dto.Customer.Name).ShouldHaveValue(o => o.Customer.FirstName + " " + o.Customer.LastName));
Hope that helps,

Dennis

Viewing all articles
Browse latest Browse all 1402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>