public void When_property_is_compared_but_a_nonproperty_is_specified_it_should_throw() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var dto = new CustomerDto(); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => dto.ShouldBeEquivalentTo(dto, options => options.Including(d => d.GetType())); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldThrow<ArgumentException>().WithMessage( "Cannot use <d.GetType()> when a property expression is expected."); }
public void When_subject_property_lambda_is_null_it_should_throw() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var dto = new CustomerDto(); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => dto.ShouldBeEquivalentTo(dto, options => options.Including(null)); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldThrow<NullReferenceException>().WithMessage( "Expected a property expression, but found <null>."); }
public void When_all_properties_but_one_match_and_that_is_expected_it_should_not_throw() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var dto = new CustomerDto { Age = 36, Birthdate = new DateTime(1973, 9, 20), Name = "John" }; var customer = new Customer { Age = 36, Birthdate = new DateTime(1973, 9, 20), Name = "Dennis" }; //----------------------------------------------------------------------------------------------------------- // Act / Assert //----------------------------------------------------------------------------------------------------------- dto.ShouldBeEquivalentTo(customer, options => options.Excluding(d => d.Name)); }
public void When_comparing_objects_by_their_shared_properties_and_all_match_it_should_not_throw() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var dto = new CustomerDto { Version = 2, Age = 36, Birthdate = new DateTime(1973, 9, 20), Name = "John" }; var customer = new Customer { Id = 1, Version = 2, Age = 36, Birthdate = new DateTime(1973, 9, 20), Name = "John" }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => dto.ShouldBeEquivalentTo(customer, options => options.ExcludingMissingProperties()); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldNotThrow(); }