Exemple #1
0
        public void Subject_and_expectation_member_paths_must_have_the_same_parent()
        {
            var subject     = new SubjectWithProperty1();
            var expectation = new ExpectationWithProperty2();

            // Act
            Action act = () => subject.Should()
                         .BeEquivalentTo(expectation, opt => opt
                                         .WithMapping("Parent[].Property1", "OtherParent[].Property2"));

            // Assert
            act.Should()
            .Throw <ArgumentException>()
            .WithMessage("*parent*");
        }
Exemple #2
0
        public void Null_as_the_subject_member_path_is_not_allowed()
        {
            var subject     = new SubjectWithProperty1();
            var expectation = new ExpectationWithProperty2();

            // Act
            Action act = () => subject.Should()
                         .BeEquivalentTo(expectation, opt => opt
                                         .WithMapping("Parent[0].Property1", null));

            // Assert
            act.Should()
            .Throw <ArgumentException>()
            .WithMessage("*member path*");
        }
Exemple #3
0
        public void Properties_can_be_mapped_by_name()
        {
            // Arrange
            var subject = new SubjectWithProperty1 {
                Property1 = "Hello"
            };

            var expectation = new ExpectationWithProperty2 {
                Property2 = "Hello"
            };

            // Act / Assert
            subject.Should()
            .BeEquivalentTo(expectation, opt => opt
                            .WithMapping("Property2", "Property1"));
        }
Exemple #4
0
        public void A_null_subject_should_result_in_a_normal_assertion_failure()
        {
            // Arrange
            SubjectWithProperty1 subject = null;

            ExpectationWithProperty2 expectation = new() { Property2 = "Hello" };

            // Act
            Action act = () => subject.Should()
                         .BeEquivalentTo(expectation, opt => opt
                                         .WithMapping("Property2", "Property1"));

            // Assert
            act.Should()
            .Throw <XunitException>()
            .WithMessage("*Expected*ExpectationWithProperty2*found <null>*");
        }
Exemple #5
0
        public void Mapping_to_a_non_existing_subject_member_is_not_allowed()
        {
            // Arrange
            var subject = new SubjectWithProperty1 {
                Property1 = "Hello"
            };

            var expectation = new ExpectationWithProperty2 {
                Property2 = "Hello"
            };

            // Act
            Action act = () => subject.Should()
                         .BeEquivalentTo(expectation, opt => opt
                                         .WithMapping("Property2", "NonExistingProperty"));

            // Assert
            act.Should()
            .Throw <ArgumentException>()
            .WithMessage("*not have member NonExistingProperty*");
        }
Exemple #6
0
        public void A_failed_assertion_reports_the_subjects_mapped_property()
        {
            // Arrange
            var subject = new SubjectWithProperty1 {
                Property1 = "Hello"
            };

            var expectation = new ExpectationWithProperty2 {
                Property2 = "Hello2"
            };

            // Act
            Action act = () => subject.Should()
                         .BeEquivalentTo(expectation, opt => opt
                                         .WithMapping <SubjectWithProperty1>(e => e.Property2, e => e.Property1));

            // Assert
            act.Should()
            .Throw <XunitException>()
            .WithMessage("Expected property subject.Property1 to be*Hello*");
        }