コード例 #1
0
        public void ByFields_CreatesComparerBasedOnAllPropertiesEquality()
        {
            var comparer =
                EqualityComparer.ByFields <DummyByMembersEqualityComparable>();

            comparer.Should()
            .HandleBasicEqualitiesAndInequalites()
            .And.ValidateEqualityOf(
                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[] { false, false }),
                "properties should be ignored")
            .And.InvalidateEqualityOf(
                new DummyByMembersEqualityComparable(
                    5, new[] { 'a', 'b' }, new DateTime(2018, 07, 30), new[] { true, true }),
                new DummyByMembersEqualityComparable(
                    5, new[] { 'c', 'd' }, new DateTime(2018, 07, 30), new[] { true, true }),
                "objects with different fields shouldn't equals");
        }
コード例 #2
0
        public void ByFields_WithSelector_CreatesComparerBasedOnSelectedFieldsEquality()
        {
            var comparer =
                EqualityComparer.ByFields <DummyByMembersEqualityComparable>(
                    fields => fields.Where(field => field.Name.EndsWith("A")));

            comparer.Should()
            .HandleBasicEqualitiesAndInequalites()
            .And.ValidateEqualityOf(
                new DummyByMembersEqualityComparable(
                    5, new[] { 'a', 'b' }, new DateTime(2018, 07, 30), new[] { true, true }),
                new DummyByMembersEqualityComparable(
                    5, new[] { 'c', 'd' }, new DateTime(2018, 06, 24), new[] { false, false }),
                "unselected fields and every property should be ignored")
            .And.InvalidateEqualityOf(
                new DummyByMembersEqualityComparable(
                    5, new[] { 'a', 'b' }, new DateTime(2018, 07, 30), new[] { true, true }),
                new DummyByMembersEqualityComparable(
                    3, new[] { 'a', 'b' }, new DateTime(2018, 06, 24), new[] { true, true }),
                "objects with different selected fields shouldn't equals");
        }