Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save scichelli/1065926 to your computer and use it in GitHub Desktop.
Save scichelli/1065926 to your computer and use it in GitHub Desktop.
First two fail (as expected), but with an unexpected error message, e.g., "For Customer, expected <>f__AnonymousType3`1[System.String]:[{ Name = Expected Name }] but found ExpectedObjectsAssertions.Customer."
[TestFixture]
public class When_testing_equivalence_or_matching_for_partially_supplied_properties
{
private const string ExpectedName = "Expected Name";
private Customer _actual;
private ExpectedObject _expected;
[Test]
public void Should_flag_extra_properties_on_actual_object_as_unequal()
{
_actual = new Customer {Name = ExpectedName, PhoneNumber = "1234567890"};
_expected = new {Name = ExpectedName}.ToExpectedObject();
_expected.ShouldEqual(_actual);
}
[Test]
public void Should_flag_uninitialized_properties_on_actual_object_as_unequal()
{
_actual = new Customer {Name = ExpectedName};
_expected = new {Name = ExpectedName, PhoneNumber = "1234567890"}.ToExpectedObject();
_expected.ShouldEqual(_actual);
}
[Test]
public void Should_flag_uninitialized_properties_on_actual_object_as_not_matching()
{
_actual = new Customer {Name = ExpectedName};
_expected = new {Name = ExpectedName, PhoneNumber = "1234567890"}.ToExpectedObject();
_expected.ShouldMatch(_actual); //fails as expected
}
[Test]
public void Should_ignore_extra_properties_on_actual_object_when_matching()
{
_actual = new Customer {Name = ExpectedName, PhoneNumber = "1234567890"};
_expected = new {Name = ExpectedName}.ToExpectedObject();
_expected.ShouldMatch(_actual); //passes as expected
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment