public void When_an_type_only_exposes_fields_but_fields_are_ignored_in_the_equivalence_comparision_it_should_fail() { // Arrange var object1 = new ClassWithOnlyAField { Value = 1 }; var object2 = new ClassWithOnlyAField { Value = 101 }; // Act Action act = () => object1.Should().BeEquivalentTo(object2, opts => opts.IncludingAllDeclaredProperties()); // Assert act.Should().Throw <InvalidOperationException>("the objects have no members to compare."); }
public void When_all_field_of_the_object_are_not_equal_equivalency_should_fail() { // Arrange var object1 = new ClassWithOnlyAField { Value = 1 }; var object2 = new ClassWithOnlyAField { Value = 101 }; // Act Action act = () => object1.Should().BeEquivalentTo(object2); // Assert act.Should().Throw <XunitException>(); }
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.*"); }
public void When_all_field_of_the_object_are_equal_equivalency_should_pass() { // Arrange var object1 = new ClassWithOnlyAField { Value = 1 }; var object2 = new ClassWithOnlyAField { Value = 1 }; // Act Action act = () => object1.Should().BeEquivalentTo(object2); // Assert act.Should().NotThrow(); }
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*"); }