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 InstanceComparisonTestObject();

            var exception = GetExceptionThrownByThisComparison(table, test);

            exception.Message.AgnosticLineBreak().Should().Be(@"The following fields did not match:
IDoNotExist: Property does not exist".AgnosticLineBreak());
        }
        public void Ignores_casing_when_matching_property_name()
        {
            var table = new Table("Field", "Value");

            table.AddRow("STRINGproperty", "Howard Roark");

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

            var comparisonResult = ExceptionWasThrownByThisComparison(table, test);

            comparisonResult.ExceptionWasThrown.Should().BeFalse(comparisonResult.ExceptionMessage);
        }
        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 InstanceComparisonTestObject {
                StringProperty = "Howard Roark"
            };

            ComparisonTestResult comparisonResult = ExceptionWasThrownByThisComparison(table, test);

            comparisonResult.ExceptionWasThrown.Should().BeFalse(comparisonResult.ExceptionMessage);
        }
        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 InstanceComparisonTestObject {
                StringProperty = "Peter Keating"
            };

            ComparisonTestResult comparisonResult = ExceptionWasThrownByThisComparison(table, test);

            comparisonResult.ExceptionWasThrown.Should().BeTrue();
        }
        public void Should_not_throw_an_exception_when_actual_value_is_null_and_expected_is_empty()
        {
            var table = new Table("Field", "Value");

            table.AddRow("NullableIntProperty", "");

            var test = new InstanceComparisonTestObject
            {
                NullableIntProperty = null,
            };

            ComparisonTestResult comparisonResult = ExceptionWasThrownByThisComparison(table, test);

            comparisonResult.ExceptionWasThrown.Should().BeFalse(comparisonResult.ExceptionMessage);
        }
        public void Should_not_throw_an_exception_when_the_date_time_value_is_midnight_and_the_table_does_not_include_a_time()
        {
            var table = new Table("Field", "Value");

            table.AddRow("DateTimeProperty", "12/25/2010");

            var test = new InstanceComparisonTestObject
            {
                DateTimeProperty = new DateTime(2010, 12, 25, 0, 0, 0)
            };

            ComparisonTestResult comparisonResult = ExceptionWasThrownByThisComparison(table, test);

            comparisonResult.ExceptionWasThrown.Should().BeFalse(comparisonResult.ExceptionMessage);
        }
        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 InstanceComparisonTestObject {
                StringProperty = "Peter Keating"
            };

            var exception = GetExceptionThrownByThisComparison(table, test);

            exception.Message.AgnosticLineBreak().Should().Be(
                @"The following fields did not match:
StringProperty: Expected <Howard Roark>, Actual <Peter Keating>".AgnosticLineBreak());
        }
        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 InstanceComparisonTestObject
            {
                StringProperty = "Howard Roark",
                IntProperty    = 10
            };

            ComparisonTestResult comparisonResult = ExceptionWasThrownByThisComparison(table, test);

            comparisonResult.ExceptionWasThrown.Should().BeTrue();
        }
Пример #9
0
        public void returns_true_if_instance_matches_horizontal_table()
        {
            var table = new Table("IntProperty", "BoolProperty", "StringProperty", "DateTimeProperty");

            table.AddRow("1", "true", "Test", "4/30/2016");

            var test = new InstanceComparisonTestObject()
            {
                IntProperty      = 1,
                BoolProperty     = true,
                StringProperty   = "Test",
                DateTimeProperty = new DateTime(2016, 4, 30)
            };

            var result = GetResultFromThisComparison(table, test);

            result.Should().Be(true);
        }
        public void Can_compare_a_horizontal_table()
        {
            var table = new Table("StringProperty", "IntProperty", "DecimalProperty", "FloatProperty");

            table.AddRow("Test", "42", "23.01", "11.56");

            var test = new InstanceComparisonTestObject
            {
                StringProperty  = "Test",
                IntProperty     = 42,
                DecimalProperty = 23.01M,
                FloatProperty   = 11.56F
            };

            var comparisonResult = ExceptionWasThrownByThisComparison(table, test);

            comparisonResult.ExceptionWasThrown.Should().BeFalse(comparisonResult.ExceptionMessage);
        }
Пример #11
0
        public void returns_false_if_instance_does_not_have_property()
        {
            var table = new Table("IntProperty", "BoolProperty", "StringProperty", "DateTimeProperty", "SomeMissingProperty");

            table.AddRow("1", "true", "Test", "4/30/2016", "MissingPropertyValue");

            var test = new InstanceComparisonTestObject
            {
                IntProperty      = 1,
                BoolProperty     = true,
                StringProperty   = "Test",
                DateTimeProperty = new DateTime(2016, 4, 30)
            };

            var result = GetResultFromThisComparison(table, test);

            result.Should().Be(false);
        }
        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 8:00:00 AM");

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

            ComparisonTestResult comparisonResult = ExceptionWasThrownByThisComparison(table, test);

            comparisonResult.ExceptionWasThrown.Should().BeFalse(comparisonResult.ExceptionMessage);
        }
        public void Exception_returns_an_exception_for_two_errors_when_there_are_two_differences()
        {
            var table = new Table("Field", "Value");

            table.AddRow("StringProperty", "Howard Roark");
            table.AddRow("IntProperty", "1");

            var test = new InstanceComparisonTestObject
            {
                StringProperty = "Peter Keating",
                IntProperty    = 2
            };

            var exception = GetExceptionThrownByThisComparison(table, test);

            exception.Message.AgnosticLineBreak().Should().Be(
                @"The following fields did not match:
StringProperty: Expected <Howard Roark>, Actual <Peter Keating>, Using 'TechTalk.SpecFlow.Assist.ValueComparers.DefaultValueComparer'
IntProperty: Expected <1>, Actual <2>, Using 'TechTalk.SpecFlow.Assist.ValueComparers.DefaultValueComparer'".AgnosticLineBreak());
        }
        public void Exception_returns_an_exception_for_two_errors_when_there_are_two_differences()
        {
            var table = new Table("Field", "Value");

            table.AddRow("StringProperty", "Howard Roark");
            table.AddRow("IntProperty", "1");

            var test = new InstanceComparisonTestObject
            {
                StringProperty = "Peter Keating",
                IntProperty    = 2
            };

            var exception = GetExceptionThrownByThisComparison(table, test);

            exception.Message.ShouldEqual(
                @"The following fields did not match:
StringProperty: Expected <Howard Roark>, Actual <Peter Keating>
IntProperty: Expected <1>, Actual <2>");
        }
        private static ComparisonTestResult ExceptionWasThrownByThisComparison(Table table, InstanceComparisonTestObject test)
        {
            var result = new ComparisonTestResult {
                ExceptionWasThrown = false
            };

            try
            {
                table.CompareToInstance(test);
            }
            catch (ComparisonException ex)
            {
                result.ExceptionWasThrown = true;
                result.ExceptionMessage   = ex.Message;
            }
            return(result);
        }
 private static ComparisonException GetExceptionThrownByThisComparison(Table table, InstanceComparisonTestObject test)
 {
     try
     {
         table.CompareToInstance(test);
     }
     catch (ComparisonException ex)
     {
         return(ex);
     }
     return(null);
 }
Пример #17
0
 private static bool GetResultFromThisComparison(Table table, InstanceComparisonTestObject test)
 {
     return(table.IsEquivalentToInstance(test));
 }