public void Replaced_member_does_not_break_comparison()
        {
            var one = new AbstractMembers {
                NotSealedProperty = _fixture.Create <BaseNestedObject>()
            };

            _comparer.Equals(one, one.DeepClone()).Should().BeTrue();

            for (var i = 0; i < 100; i++)
            {
                one.NotSealedProperty = _fixture.Create <AnotherNestedObject>();
                var other = new AbstractMembers {
                    NotSealedProperty = _fixture.Create <AnotherNestedObject>()
                };

                var expectedHashX  = one.GetHashCode();
                var expectedHashY  = other.GetHashCode();
                var expectedEquals = one.Equals(other);

                var hashX  = _comparer.GetHashCode(one);
                var hashY  = _comparer.GetHashCode(other);
                var equals = _comparer.Equals(one, other);

                using (new AssertionScope()) {
                    equals.Should().Be(expectedEquals);
                    hashX.Should().Be(expectedHashX);
                    hashY.Should().Be(expectedHashY);
                }
            }
        }
Example #2
0
        public void Generate_comparer_for_not_sealed_member_in_parallel_still_works()
        {
            Helper.Parallel(() => {
                var one = new AbstractMembers {
                    NotSealedProperty = _fixture.Create <AnotherNestedObject>()
                };
                var other = new AbstractMembers {
                    NotSealedProperty = _fixture.Create <AnotherNestedObject>()
                };

                var expectedHashX  = one.GetHashCode();
                var expectedHashY  = other.GetHashCode();
                var expectedEquals = one.Equals(other);

                var comparer = CreateComparer();
                Helper.Parallel(() => {
                    var hashX  = comparer.GetHashCode(one);
                    var hashY  = comparer.GetHashCode(other);
                    var equals = comparer.Equals(one, other);

                    using (new AssertionScope()) {
                        equals.Should().Be(expectedEquals);
                        hashX.Should().Be(expectedHashX);
                        hashY.Should().Be(expectedHashY);
                    }
                });
            });
        }
        public void When_right_member_is_null_comparison_produces_positive_value()
        {
            var one = new AbstractMembers {
                NotSealedProperty = _fixture.Create <BaseNestedObject>()
            };
            var another = new AbstractMembers();

            _comparer.Compare(one, another).Should().BePositive();
        }
        public void When_left_member_is_null_comparison_produces_false()
        {
            var one   = new AbstractMembers();
            var other = new AbstractMembers {
                NotSealedProperty = _fixture.Create <BaseNestedObject>()
            };

            _comparer.Equals(one, other).Should().BeFalse();
        }
        public void Attempt_to_compare_inherited_types_throws_argument_exception()
        {
            var sealedNestedObject  = _fixture.Create <BaseNestedObject>();
            var anotherNestedObject = _fixture.Create <AnotherNestedObject>();

            var one = new AbstractMembers {
                NotSealedProperty = sealedNestedObject
            };

            var another = new AbstractMembers {
                NotSealedProperty = anotherNestedObject
            };

            Assert.Throws <ArgumentException>(() => _comparer.Compare(one, another));
        }
        public void Different_Inherited_types_are_not_equal()
        {
            var sealedNestedObject  = _fixture.Create <BaseNestedObject>();
            var anotherNestedObject = _fixture.Create <AnotherNestedObject>();

            var one = new AbstractMembers {
                NotSealedProperty = sealedNestedObject
            };

            var another = new AbstractMembers {
                NotSealedProperty = anotherNestedObject
            };

            _comparer.Equals(one, another).Should().BeFalse();
        }
        public void Attempt_to_compare_different_sibling_types_throws_argument_exception()
        {
            var sealedNestedObject = _fixture
                                     .Build <SealedNestedObject>()
                                     .Without(x => x.DeepNestedField)
                                     .Without(x => x.DeepNestedProperty)
                                     .Create();

            var anotherNestedObject = _fixture.Create <AnotherNestedObject>();

            var one = new AbstractMembers {
                InterfaceField = sealedNestedObject
            };

            var another = new AbstractMembers {
                InterfaceField = anotherNestedObject
            };

            Assert.Throws <ArgumentException>(() => _comparer.Compare(one, another));
        }
        public void Different_sibling_types_are_not_equals()
        {
            var sealedNestedObject = _fixture
                                     .Build <SealedNestedObject>()
                                     .Without(x => x.DeepNestedField)
                                     .Without(x => x.DeepNestedProperty)
                                     .Create();

            var anotherNestedObject = _fixture.Create <AnotherNestedObject>();

            var one = new AbstractMembers {
                InterfaceField = sealedNestedObject
            };

            var another = new AbstractMembers {
                InterfaceField = anotherNestedObject
            };

            _comparer.Equals(one, another).Should().BeFalse();
        }
        public void Replaced_member_does_not_break_comparison()
        {
            var one = new AbstractMembers {
                NotSealedProperty = _fixture.Create <BaseNestedObject>()
            };

            _comparer.Compare(one, one.DeepClone()).Should().Be(0);

            for (var i = 0; i < 100; i++)
            {
                one.NotSealedProperty = _fixture.Create <AnotherNestedObject>();
                var other = new AbstractMembers {
                    NotSealedProperty = _fixture.Create <AnotherNestedObject>()
                };

                var expected = AbstractMembers.Comparer.Compare(one, other).Normalize();
                var actual   = _comparer.Compare(one, other).Normalize();

                actual.Should().Be(expected);
            }
        }
Example #10
0
        public void Generate_comparer_for_not_sealed_member_in_parallel_still_works()
        {
            var one = new AbstractMembers {
                NotSealedProperty = _fixture.Create <AnotherNestedObject>()
            };

            Helper.Parallel(() => {
                var comparer = CreateComparer();

                var other = new AbstractMembers {
                    NotSealedProperty = _fixture.Create <AnotherNestedObject>()
                };

                var expected = AbstractMembers.Comparer.Compare(one, other).Normalize();

                Helper.Parallel(() => {
                    var actual = comparer.Compare(one, other).Normalize();
                    actual.Should().Be(expected);
                });
            });
        }