I'd like to assert that my dto (which is flat object with few properties) is equivalent to my entity (which is complex object with nested properties).
public class Dto
{
public string A {get;set;}
public string B {get;set;}
}
public class Entity
{
public string A {get;set;}
public NestedObject C {get;set;}
public string D {get;set;}
public class NestedObject
{
public string B {get;set;}
}
}
Dto | Entity |
---|---|
A | A |
B | C.B |
- | D |
If I try to do this:
dto.Should().BeEquivalentTo(entity)
it will throw an exception that Dto doesn't have "D" property. I don't want it to throw this exception.
entity.Should().BeEquivalentTo(dto)
this will not check nested objects and fail.
dto.Should().BeEquivalentTo(entity, x => x.ExcludeMissingProperties())
this will not throw an exception if dto have some property (for example, property "E") that does not map to an entity (entity does not have property "E"). I want it to throw an exception in that case.
How can I accomplish this? Thanks.