示例#1
0
        When_an_type_only_exposes_properties_but_properties_are_ignored_in_the_equivalence_comparision_it_should_fail()
        {
            // Arrange
            var object1 = new ClassWithOnlyAProperty {
                Value = 1
            };
            var object2 = new ClassWithOnlyAProperty {
                Value = 101
            };

            // Act
            Action act = () => object1.Should().BeEquivalentTo(object2, opts => opts.ExcludingProperties());

            // Assert
            act.Should().Throw <InvalidOperationException>("the objects have no members to compare.");
        }
示例#2
0
        public void When_a_field_on_the_subject_matches_a_property_the_members_should_match_for_equivalence()
        {
            // Arrange
            var onlyAField = new ClassWithOnlyAField {
                Value = 1
            };
            var onlyAProperty = new ClassWithOnlyAProperty {
                Value = 101
            };

            // Act
            Action act = () => onlyAField.Should().BeEquivalentTo(onlyAProperty);

            // Assert
            act.Should().Throw <XunitException>().WithMessage("Expected property onlyAField.Value*to be 101, but found 1.*");
        }
示例#3
0
        public void When_multiple_equivalency_steps_are_added_they_should_be_executed_in_registration_order()
        {
            // Arrange
            var subject  = new ClassWithOnlyAProperty();
            var expected = new ClassWithOnlyAProperty();

            // Act
            Action act =
                () =>
                subject.Should().BeEquivalentTo(expected,
                                                opts =>
                                                opts.Using(new ThrowExceptionEquivalencyStep <NotSupportedException>())
                                                .Using(new ThrowExceptionEquivalencyStep <InvalidOperationException>()));

            // Assert
            act.Should().Throw <NotSupportedException>();
        }
示例#4
0
        public void When_an_equivalency_does_not_handle_the_comparison_later_equivalency_steps_should_still_be_ran()
        {
            // Arrange
            var subject  = new ClassWithOnlyAProperty();
            var expected = new ClassWithOnlyAProperty();

            // Act
            Action act =
                () =>
                subject.Should().BeEquivalentTo(expected,
                                                opts =>
                                                opts.Using(new NeverHandleEquivalencyStep())
                                                .Using(new ThrowExceptionEquivalencyStep <InvalidOperationException>()));

            // Assert
            act.Should().Throw <InvalidOperationException>();
        }
示例#5
0
        public void When_asserting_equivalence_including_only_properties_it_should_not_match_fields()
        {
            // Arrange
            var onlyAField = new ClassWithOnlyAField {
                Value = 1
            };
            var onlyAProperty = new ClassWithOnlyAProperty {
                Value = 101
            };

            // Act
            Action act = () => onlyAField.Should().BeEquivalentTo(onlyAProperty, opts => opts.IncludingAllDeclaredProperties());

            // Assert
            act.Should().Throw <XunitException>()
            .WithMessage("Expectation has property onlyAField.Value that the other object does not have*");
        }
示例#6
0
        public void When_multiple_assertion_rules_are_added_with_the_fluent_api_they_should_be_executed_from_right_to_left()
        {
            // Arrange
            var subject  = new ClassWithOnlyAProperty();
            var expected = new ClassWithOnlyAProperty();

            // Act
            Action act =
                () =>
                subject.Should().BeEquivalentTo(expected,
                                                opts =>
                                                opts.Using <object>(_ => throw new Exception())
                                                .When(_ => true)
                                                .Using <object>(_ => { })
                                                .When(_ => true));

            // Assert
            act.Should().NotThrow(
                "a different assertion rule should handle the comparison before the exception throwing assertion rule is hit");
        }