The latest changes to NUnit's properties comparer allows comparing the common properties of different types.
[Test]
public void AssertThatDifferentTypesCanBeCompared()
{
var instanceC = new ClassWithSomeToleranceAwareMembers(1, 1.1, "1.1", null);
var instanceS = new StructWithSomeToleranceAwareMembers(1, 1.1, "1.1", SomeEnum.Two);
Assert.That(instanceS, Is.EqualTo(instanceC).UsingPropertiesComparer(
c => c.CompareOnlyCommonProperties()));
}
UsingPropertiesComparer also supports type mapping:
Assert.That(usPerson, Is.EqualTo(person).UsingPropertiesComparer(
c => c.Map<USPerson>(x => x.Address, y => y.USAddress)
.Map<Address, USAddress>(x => x.AreaCode, y => y.ZipCode)
.Map<Address>(x => x.Country, "U.S.A.")));
The latest changes to NUnit's properties comparer allows comparing the common properties of different types.
UsingPropertiesCompareralso supports type mapping: