Skip to content

NUnit2021 Should not raise for UsingPropertiesComparer #857

@manfred-brands

Description

@manfred-brands

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.")));

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions