How to exclude members from BeEquivalentTo that are null
See original GitHub issueHi,
I have code like this:
var user = table.CreateInstance<User>();
userDTO.Should().BeEquivalentTo(user, options => options.ExcludingMissingMembers());
user:
example userDTO:
{ "email": "testuser01@kl;kl;.com", "password": "nn91PKBrv99yQc/uNqTM2", "id": 2, "name": "Ervin Howell", "username": "Antonette", "address": { "street": "Victor Plains", "suite": "Suite 879", "city": "Wisokyburgh", "zipcode": "90566-7771", "geo": { "lat": "-43.9509", "lng": "-34.4618" } }, "phone": "010-692-6593 x09125", "website": "anastasia.net", "company": { "name": "Deckow-Crist", "catchPhrase": "Proactive didactic contingency", "bs": "synergize scalable supply-chains" } },
I want assert only fields that are not null in user but get exception:
'Expected member Email to be <null>, but found "testuser01@dfhdfh.com". Expected member Password to be <null>, but found "O5jG6//tFKinn91PKBrv99yQc/uNqTM2". Expected member Company to be <null>, but found
Null values still are checked. How to not check null values?
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (8 by maintainers)
Top GitHub Comments
Here’s an example on how to recursively ignore members from the
expectation
, when their runtime value isnull
.To be honest, I think it’s a scary way to compare two types. Just imagine what happens if
Username
suddenly becomenull
. But if your intention is to compare only certain properties, you can pass in an anonymous type instead ofuser
that only defines the properties that you care about.