public void When_two_objects_have_the_same_properties_but_a_different_value_it_should_throw() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var subject = new { Age = 36, }; var expectation = new { Age = 37, }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => subject.ShouldHave().AllProperties().EqualTo(expectation, "because {0} are the same", "they"); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldThrow<AssertFailedException>().WithMessage( "Expected property Age to be 37 because they are the same, but found 36", ComparisonMode.StartWith); }
public void When_two_objects_have_the_same_property_values_it_should_succeed() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var subject = new { Age = 36, Birthdate = new DateTime(1973, 9, 20), Name = "Dennis" }; var other = new { Age = 36, Birthdate = new DateTime(1973, 9, 20), Name = "Dennis" }; //----------------------------------------------------------------------------------------------------------- // Act / Assert //----------------------------------------------------------------------------------------------------------- subject.ShouldHave().AllProperties().EqualTo(other); }
When_specific_properties_of_a_subject_are_compared_with_another_object_it_should_ignore_the_other_properties () { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var subject = new { Age = 36, Birthdate = new DateTime(1973, 9, 20), Name = "John" }; var customer = new { Age = 36, Birthdate = new DateTime(1973, 9, 20), Name = "Dennis" }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => subject.ShouldHave().Properties(d => d.Age, d => d.Birthdate).EqualTo(customer); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldNotThrow(); }
public void When_equally_named_properties_are_type_incompatiblle_it_should_throw() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var subject = new { Type = "A", }; var other = new { Type = 36, }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => subject.ShouldHave().AllProperties().EqualTo(other); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act .ShouldThrow<AssertFailedException>() .WithMessage("Expected property Type to be*Int32*, but found*String*", ComparisonMode.Wildcard); }
public void When_subjects_properties_are_compared_to_null_object_it_should_throw() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var subject = new { }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => subject.ShouldHave().AllProperties().EqualTo(null); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldThrow<AssertFailedException>().WithMessage( "Expected subject to be <null>, but found { }", ComparisonMode.StartWith); }
public void When_subject_has_a_property_not_available_in_expected_object_it_should_throw() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var subject = new { City = "Rijswijk" }; var other = new { }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => subject.ShouldHave().AllProperties().EqualTo(other); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldThrow<AssertFailedException>().WithMessage( "Subject has property City that the other object does not have", ComparisonMode.StartWith); }
public void When_two_collection_properties_dont_match_it_should_throw_and_specify_the_difference() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var subject = new { Values = new[] { 1, 2, 3 } }; var other = new { Values = new[] { 1, 4, 3 } }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => subject.ShouldHave().AllProperties().EqualTo(other); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldThrow<AssertFailedException>().WithMessage( "*property*{1, 2, 3} to be equivalent to {1, 4, 3}*", ComparisonMode.Wildcard); }
public void When_subject_has_a_valid_property_that_is_compared_with_a_null_property_it_should_throw() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var subject = new { Name = "Dennis" }; var other = new { Name = (string) null }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => subject.ShouldHave().AllProperties().EqualTo(other); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldThrow<AssertFailedException>().WithMessage( "Expected property Name to be <null>, but found \"Dennis\"", ComparisonMode.StartWith); }
public void When_two_string_properties_do_not_match_it_should_throw_and_state_the_difference() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var subject = new { Name = "Dennes" }; var other = new { Name = "Dennis" }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => subject.ShouldHave().Properties(d => d.Name).EqualTo(other); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldThrow<AssertFailedException>().WithMessage( "Expected property Name to be \"Dennis\", but \"Dennes\" differs near \"es\" (index 4)", ComparisonMode.StartWith); }
public void When_two_objects_have_the_same_properties_with_convertable_values_it_should_succeed() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var subject = new { Age = "37", Birthdate = "1973-09-20", }; var other = new { Age = 37, Birthdate = new DateTime(1973, 9, 20) }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => subject.ShouldHave().AllProperties().EqualTo(other); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldNotThrow(); }
public void When_two_different_enumerables_contain_the_same_structural_equal_objects_it_should_succeed() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- Customer[] subject = new[] { new Customer { Name = "John", Age = 27, Id = 1 }, new Customer { Name = "Jane", Age = 24, Id = 2 } }; IEnumerable<Customer> expectation = new Collection<Customer> { new Customer { Name = "John", Age = 27, Id = 1 }, new Customer { Name = "Jane", Age = 24, Id = 2 } }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action action = () => subject.ShouldHave().AllProperties().IncludingNestedObjects().EqualTo(expectation); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- action.ShouldNotThrow(); }
public void When_a_complex_object_graph_with_collections_matches_expectations_it_should_not_throw() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var subject = new { Bytes = new byte[] { 1, 2, 3, 4 }, Object = new { A = 1, B = 2 } }; var expected = new { Bytes = new byte[] { 1, 2, 3, 4 }, Object = new { A = 1, B = 2 } }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => subject.ShouldHave().AllProperties().IncludingNestedObjects().EqualTo(expected); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldNotThrow(); }
public void When_a_collection_contains_less_items_than_expected_it_should_throw() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var expected = new { Customers = new[] { new Customer { Age = 38, Birthdate = 20.September(1973), Name = "John" }, new Customer { Age = 38, Birthdate = 20.September(1973), Name = "Jane" } } }; var subject = new { Customers = new[] { new CustomerDto { Age = 24, Birthdate = 21.September(1973), Name = "John" }, } }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => subject.ShouldHave().AllProperties().IncludingNestedObjects().EqualTo(expected); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldThrow<AssertFailedException>() .WithMessage("*property Customers to be a collection with 2 item(s), but found 1*", ComparisonMode.Wildcard); }
public void When_a_collection_property_was_expected_but_the_property_is_not_a_collection_it_should_throw() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var subject = new { Customers = "Jane, John" }; var expected = new { Customers = new[] { new Customer { Age = 38, Birthdate = 20.September(1973), Name = "John" }, } }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => subject.ShouldHave().AllProperties().IncludingNestedObjects().EqualTo(expected); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldThrow<AssertFailedException>() .WithMessage("*property Customers to be*Customer[]*, but*System.String*", ComparisonMode.Wildcard); }
public void When_a_collection_property_contains_objects_with_mismatching_properties_it_should_throw() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var expected = new { Customers = new[] { new Customer { Age = 38, Birthdate = 20.September(1973), Name = "John" }, } }; var subject = new { Customers = new[] { new CustomerDto { Age = 38, Birthdate = 20.September(1973), Name = "Jane" }, } }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => subject.ShouldHave().AllProperties().IncludingNestedObjects().EqualTo(expected); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldThrow<AssertFailedException>() .WithMessage("*Customers[0].Name*John*Jane*", ComparisonMode.Wildcard); }
public void When_comparing_anonymous_objects_by_their_shared_properties_and_all_match_it_should_not_throw() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var subject = new { Age = 36, }; var other = new { Age = 37, }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => subject.ShouldHave().SharedProperties().EqualTo(other); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldThrow<AssertFailedException>(); }
public void When_not_all_the_properties_of_the_nested_object_exist_on_the_expected_object_it_should_throw() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var subject = new { Level = new { Text = "Level1", OtherProperty = "OtherProperty" } }; var expected = new { Level = new { Text = "Level1" } }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => subject.ShouldHave().AllProperties().IncludingNestedObjects().EqualTo(expected); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act .ShouldThrow<AssertFailedException>() .WithMessage("Subject has property Level.OtherProperty that the other object does not have", ComparisonMode.StartWith); }
public void When_two_properties_are_of_derived_types_but_are_equal_it_should_succeed() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var subject = new { Type = new CustomerType("123") }; var other = new { Type = new DerivedCustomerType("123") }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => subject.ShouldHave().AllProperties().EqualTo(other); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldNotThrow(); }
public void When_all_the_shared_properties_of_the_nested_objects_are_equal_it_should_succeed() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var subject = new { Level = new { Text = "Level1", Property = "Property" } }; var expected = new { Level = new { Text = "Level1", OtherProperty = "OtherProperty" } }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => subject.ShouldHave().SharedProperties().IncludingNestedObjects().EqualTo(expected); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldNotThrow(); }
public void When_a_collection_property_contains_objects_with_matching_properties_it_should_not_throw() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var expected = new { Customers = new[] { new Customer { Age = 38, Birthdate = 20.September(1973), Name = "John" }, new Customer { Age = 32, Birthdate = 31.July(1978), Name = "Jane" } } }; var subject = new { Customers = new[] { new CustomerDto { Age = 38, Birthdate = 20.September(1973), Name = "John" }, new CustomerDto { Age = 32, Birthdate = 31.July(1978), Name = "Jane" } } }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => subject.ShouldHave().AllProperties().IncludingNestedObjects().EqualTo(expected); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldNotThrow(); }