Skip to content

Failure Output

Derek Greer edited this page Sep 4, 2017 · 2 revisions

When comparing objects which differ in value, ExpectedObjects will throw an exception displaying a list of issues.

The following example attempts to perform a comparison where several properties of an object are not equivalent to the expected values:

using ExpectedObjects;
using Xunit;

namespace ExpectedObjectExamples.Specs
{
    public class CustomerSpecs
    {
        [Fact]
        public void ComparingEqualCustomers_ShouldBeEqual()
        {
            // establish context
            var expectedCustomer = new Customer
            {
                FirstName = "Silence",
                LastName = "Dogood",
                Address = new Address
                {
                    AddressLineOne = "The New-England Courant",
                    AddressLineTwo = "3 Queen Street",
                    City = "Boston",
                    State = "MA",
                    PostalCode = "02114"
                }
            }.ToExpectedObject();

            var actualCustomer = new Customer
            {
                FirstName = "John",
                LastName = "Doe",
                Address = new Address
                {
                    AddressLineOne = "The New-England Courant",
                    AddressLineTwo = string.Empty,
                    City = "Boston",
                    State = string.Empty,
                    PostalCode = "02114"
                }
            };


            // observation
            expectedCustomer.ShouldEqual(actualCustomer);
        }
    }
}

In this case, ExpectedObjects will throw an exception containing a description for each of the issues found:

Message: The expected object did not match the actual object.

The following issues were found:

1) Customer.FirstName:

  Expected:
    "Silence"
    
  Actual:
    "John"
    


2) Customer.LastName:

  Expected:
    "Dogood"
    
  Actual:
    "Doe"
    


3) Customer.Address.AddressLineTwo:

  Expected:
    "3 Queen Street"
    
  Actual:
    String.Empty
    


4) Customer.Address.State:

  Expected:
    "MA"
    
  Actual:
    String.Empty

Clone this wiki locally