-
-
Save undergroundmonorail/f93779d2e14c9839b7d2d8292694b5a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PropertyInfo[] allProps = typeof(Patient).GetProperties(); | |
foreach (var property in allProps) | |
{ | |
if (property.PropertyType == typeof(List<Address>)) | |
{ | |
// If the property is a list of addresses, use reflection on each address to compare all their properties | |
PropertyInfo[] addressProps = typeof(Address).GetProperties(); | |
var addressPairs = ((List<Address>)property.GetValue(deserialized)).Zip((List<Address>)property.GetValue(expectedResult)); | |
foreach ((Address deserializedAddress, Address expectedAddress) in addressPairs) | |
{ | |
foreach (var addressProperty in addressProps) | |
{ | |
Assert.AreEqual(addressProperty.GetValue(deserializedAddress), addressProperty.GetValue(expectedAddress), | |
$"Address Property {addressProperty.Name} did not match when deserialized"); | |
} | |
} | |
} | |
else if (property.PropertyType == typeof(List<Identifier>)) | |
{ | |
// If the property is a list of identifiers, use reflection on each identifier to compare all their properties | |
PropertyInfo[] identifierProps = typeof(Identifier).GetProperties(); | |
var identifierPairs = ((List<Identifier>)property.GetValue(deserialized)).Zip((List<Identifier>)property.GetValue(expectedResult)); | |
foreach ((Identifier deserializedIdentifier, Identifier expectedIdentifier) in identifierPairs) | |
{ | |
foreach (var identifierProperty in identifierProps) | |
{ | |
Assert.AreEqual(identifierProperty.GetValue(deserializedIdentifier), identifierProperty.GetValue(expectedIdentifier), | |
$"Address Property {identifierProperty.Name} did not match when deserialized"); | |
} | |
} | |
} | |
else | |
{ | |
// Otherwise compare each property directly | |
Assert.AreEqual(property.GetValue(deserialized), property.GetValue(expectedResult), $"Property {property.Name} did not match when deserialized"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment