public void ByProperties_CreatesComparerBasedOnAllPropertiesEquality() { var comparer = EqualityComparer.ByProperties <DummyByMembersEqualityComparable>(); comparer.Should() .HandleBasicEqualitiesAndInequalites() .And.ValidateEqualityOf( new DummyByMembersEqualityComparable( 5, new[] { 'a', 'b' }, new DateTime(2018, 07, 30), new[] { true, true }), new DummyByMembersEqualityComparable( 3, new[] { 'c', 'd' }, new DateTime(2018, 07, 30), new[] { true, true }), "fields should be ignored") .And.InvalidateEqualityOf( new DummyByMembersEqualityComparable( 5, new[] { 'a', 'b' }, new DateTime(2018, 07, 30), new[] { true, true }), new DummyByMembersEqualityComparable( 5, new[] { 'a', 'b' }, new DateTime(2018, 06, 24), new[] { true, true }), "objects with different properties shouldn't equals"); }
public void ByProperties_WithSelector_CreatesComparerBasedOnSelectedPropertiesEquality() { var comparer = EqualityComparer.ByProperties <DummyByMembersEqualityComparable>( properties => properties.Where(property => property.Name.EndsWith("A"))); comparer.Should() .HandleBasicEqualitiesAndInequalites() .And.ValidateEqualityOf( new DummyByMembersEqualityComparable( 5, new[] { 'a', 'b' }, new DateTime(2018, 07, 30), new[] { true, true }), new DummyByMembersEqualityComparable( 3, new[] { 'c', 'd' }, new DateTime(2018, 07, 30), new[] { false, false }), "unselected properties and every field should be ignored") .And.InvalidateEqualityOf( new DummyByMembersEqualityComparable( 5, new[] { 'a', 'b' }, new DateTime(2018, 07, 30), new[] { true, true }), new DummyByMembersEqualityComparable( 5, new[] { 'a', 'b' }, new DateTime(2018, 06, 24), new[] { true, true }), "objects with different selected properties shouldn't equals"); }