We’re currently using Fluent Assertions to help make writing tests for our project a bit easier. This is a very handy library and certainly helps to make test conditions easier to specify and more readable.
One issue we did have though was how to exclude specific child properties from a list property that belonged to our object being tested.
Fluent Assertations has an Excluding method that can be used to ignore properties which works for nested objects but not if you’re trying to exclude a property from a list of objects.
orderDto.Should().BeEquivalentTo(order, options => options.Excluding(o => o.Customer.Name));
After a bit of searching it looks like they’ve recently added a For method which allows for navigation through lists of objects which solved our problem nicely.
orderDto.Should().BeEquivalentTo(order, options => options.For(o => o.Products) .For(o => o.Parts) .Exclude(o => o.Name));