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)); }
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*"); }
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*"); }