public void Does_not_throw_exception_when_value_of_matching_string_property_matches()
        {
            var table = new Table("Field", "Value");
            table.AddRow("StringProperty", "Howard Roark");

            var test = new ComparisonTest {StringProperty = "Howard Roark"};

            var exceptionThrown = ExceptionWasThrownByThisComparison(table, test);

            exceptionThrown.ShouldBeFalse();
        }
        public void Exception_returns_an_exception_for_one_error_when_there_is_one_difference()
        {
            var table = new Table("Field", "Value");
            table.AddRow("StringProperty", "Howard Roark");

            var test = new ComparisonTest {StringProperty = "Peter Keating"};

            var exception = GetExceptionThrownByThisComparison(table, test);

            exception.Message.ShouldEqual(
                @"The following fields did not match:
            StringProperty: Expected <Howard Roark>, Actual <Peter Keating>");
        }
 private static bool ExceptionWasThrownByThisComparison(Table table, ComparisonTest test)
 {
     var exception = false;
     try
     {
         table.CompareToInstance(test);
     }
     catch (ComparisonException ex)
     {
         exception = true;
     }
     return exception;
 }
 private static ComparisonException GetExceptionThrownByThisComparison(Table table, ComparisonTest test)
 {
     try
     {
         table.CompareToInstance(test);
     }
     catch (ComparisonException ex)
     {
         return ex;
     }
     return null;
 }
        public void Throws_exception_when_value_of_matching_string_property_does_not_match()
        {
            var table = new Table("Field", "Value");
            table.AddRow("StringProperty", "Howard Roark");

            var test = new ComparisonTest {StringProperty = "Peter Keating"};

            var exceptionThrown = ExceptionWasThrownByThisComparison(table, test);

            exceptionThrown.ShouldBeTrue();
        }
        public void Throws_exception_when_first_row_matches_but_second_does_not()
        {
            var table = new Table("Field", "Value");
            table.AddRow("StringProperty", "Howard Roark");
            table.AddRow("IntProperty", "20");

            var test = new ComparisonTest
                           {
                               StringProperty = "Howard Roark",
                               IntProperty = 10
                           };

            var exceptionThrown = ExceptionWasThrownByThisComparison(table, test);

            exceptionThrown.ShouldBeTrue();
        }
        public void Should_not_throw_an_exception_when_the_ToString_values_of_each_match()
        {
            var table = new Table("Field", "Value");
            table.AddRow("StringProperty", "Howard Roark");
            table.AddRow("IntProperty", "10");
            table.AddRow("DateTimeProperty", "12/25/2010 12:00:00 AM");

            var test = new ComparisonTest
            {
                StringProperty = "Howard Roark",
                IntProperty = 10,
                DateTimeProperty = new DateTime(2010, 12, 25)
            };

            var exceptionThrown = ExceptionWasThrownByThisComparison(table, test);

            exceptionThrown.ShouldBeFalse();
        }
        public void Should_not_throw_an_exception_when_actual_value_is_null_and_expected_is_empty()
        {
            var table = new Table("Field", "Value");
            table.AddRow("NullableField", "");

            var test = new ComparisonTest
            {
                NullableField = null,
            };

            var exceptionThrown = ExceptionWasThrownByThisComparison(table, test);

            exceptionThrown.ShouldBeFalse();
        }
        public void Exception_returns_a_descriptive_error_when_property_in_table_does_not_exist()
        {
            var table = new Table("Field", "Value");
            table.AddRow("IDoNotExist", "Ok, mister");

            var test = new ComparisonTest();

            var exception = GetExceptionThrownByThisComparison(table, test);

            exception.Message.ShouldEqual(@"The following fields did not match:
            IDoNotExist: Property does not exist");
        }