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