Esempio n. 1
0
        public void Nested_properties_can_be_mapped_using_a_nested_type_and_property_names()
        {
            // Arrange
            var subject = new ParentOfSubjectWithProperty1(new[] { new SubjectWithProperty1 {
                                                                       Property1 = "Hello"
                                                                   } });

            var expectation = new ParentOfExpectationWithProperty2(new[]
            {
                new ExpectationWithProperty2 {
                    Property2 = "Hello"
                }
            });

            // Act / Assert
            subject.Should()
            .BeEquivalentTo(expectation, opt => opt
                            .WithMapping <ExpectationWithProperty2, SubjectWithProperty1>("Property2", "Property1"));
        }
Esempio n. 2
0
        public void Nested_properties_can_be_mapped_using_a_nested_expression()
        {
            // Arrange
            var subject = new ParentOfSubjectWithProperty1(new[] { new SubjectWithProperty1 {
                                                                       Property1 = "Hello"
                                                                   } });

            var expectation = new ParentOfExpectationWithProperty2(new[]
            {
                new ExpectationWithProperty2 {
                    Property2 = "Hello"
                }
            });

            // Act / Assert
            subject.Should()
            .BeEquivalentTo(expectation, opt => opt
                            .WithMapping <ParentOfSubjectWithProperty1>(
                                e => e.Parent[0].Property2,
                                s => s.Parent[0].Property1));
        }
Esempio n. 3
0
        public void The_member_name_on_a_nested_type_mapping_must_be_a_valid_member()
        {
            // Arrange
            var subject = new ParentOfSubjectWithProperty1(new[] { new SubjectWithProperty1 {
                                                                       Property1 = "Hello"
                                                                   } });

            var expectation = new ParentOfExpectationWithProperty2(new[]
            {
                new ExpectationWithProperty2 {
                    Property2 = "Hello"
                }
            });

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

            // Assert
            act.Should()
            .Throw <ArgumentException>()
            .WithMessage("*does not have member NonExistingProperty*");
        }
Esempio n. 4
0
        public void Nested_types_and_dotted_subject_member_paths_cannot_be_combined()
        {
            // Arrange
            var subject = new ParentOfSubjectWithProperty1(new[] { new SubjectWithProperty1 {
                                                                       Property1 = "Hello"
                                                                   } });

            var expectation = new ParentOfExpectationWithProperty2(new[]
            {
                new ExpectationWithProperty2 {
                    Property2 = "Hello"
                }
            });

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

            // Assert
            act.Should()
            .Throw <ArgumentException>()
            .WithMessage("*cannot be a nested path*");
        }