Object graph comparison - Is there a way to ensure that all properties on a subject are populated? #2730
Unanswered
dynamictulip
asked this question in
Q&A
Replies: 1 comment 1 reply
-
|
Unfortunately no, although it shouldn't be too difficult to use a bit of Reflection to accomplish that. FWIW, I usually don't test the DTOs directly, but build HTTP API tests that send real (in-memory) HTTP requests and in which the assertion verifies the actual JSON that comes back. I see DTOs as implementation details. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a system to test which maps data from one type to another type, lets call them
OrderandOrderDtoIn my scenario,
Orderhas many more properties thanOrderDtoso I useorderDto.Should().BeEquivalentTo(order, options => options.ExcludingMissingMembers());to prevent an exception being thrown due to properties existing onOrderwhich do not exist onOrderDto.Some of the property names are slightly different between
OrderandOrderDtoso I useoptions.WithMapping<OrderDto>(e => e.Name, s => s.OrderName)for each property that varies.The problem is that I would like to ensure that every property that exists on
OrderDtohas been populated as it would be very easy to forget to add aWithMappingfor a particular property, especially as things change in the future.Is there a way to do this with object graph comparison like
options.IncludingMembers<OrderDto>()or even anorderDto.Should().NotHaveNullProperties()?Beta Was this translation helpful? Give feedback.
All reactions