From 38e8a9ac332d889cc69906ed857cdb66728cedfc Mon Sep 17 00:00:00 2001 From: Marcus Hammarberg Date: Mon, 1 Oct 2018 18:51:18 +0200 Subject: [PATCH] Extended with type information in set comparision exception --- .gitignore | 3 +- .../DynamicTableHelpers.cs | 43 +++++++++++-------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index acfb1a2..ad3994c 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ binaries TestResults *_mm_cache.bin *.nupkg -packages \ No newline at end of file +packages +.idea/* \ No newline at end of file diff --git a/SpecFlow.Assist.Dynamic/DynamicTableHelpers.cs b/SpecFlow.Assist.Dynamic/DynamicTableHelpers.cs index ea1504a..2ffca45 100644 --- a/SpecFlow.Assist.Dynamic/DynamicTableHelpers.cs +++ b/SpecFlow.Assist.Dynamic/DynamicTableHelpers.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text.RegularExpressions; using ImpromptuInterface; +using ImpromptuInterface.InvokeExt; namespace TechTalk.SpecFlow.Assist { @@ -14,13 +15,13 @@ public static class DynamicTableHelpers private const string ERRORMESS_NOT_ON_TABLE = "The '{0}' value not present in the table, but on the instance"; private const string ERRORMESS_NOT_ON_INSTANCE = "The '{0}' value not present on the instance, but in the table"; private const string ERRORMESS_VALUE_DIFFERS = - "The '{0}' value differs from table and instance.\n\tInstance:\t'{1}'.\n\tTable:\t\t'{2}'"; + "The '{0}' value differs from table and instance.\n\tInstance:\t'{1}'(type: {2}).\n\tTable:\t\t'{3}'(type: {4})"; private const string ERRORMESS_NUMBER_OF_ROWS_DIFFERS = "Number of rows for table ({0} rows) and set ({1} rows) differs"; private const string ERRORMESS_SET_VALUES_DIFFERS = - "A difference was found on row '{0}' for column '{1}' (property '{2}').\n\tInstance:\t'{3}'.\n\tTable:\t\t'{4}'"; + "A difference was found on row '{0}' for column '{1}' (property '{2}').\n\tInstance:\t'{3}'(type: {4}).\n\tTable:\t\t'{5}'(type: {6})"; /// /// Create a dynamic object from the headers and values of the @@ -109,21 +110,25 @@ private static List GetSetValueDifferences(Table table, IList se { foreach (var memberName in memberNames) { - var currentHeader = string.Empty; - var rowValue = GetRowValue(i, table, memberName, out currentHeader, doTypeConversion); - var instanceValue = Impromptu.InvokeGet(set[i], memberName); - - if (!instanceValue.Equals(rowValue)) - { - var difference = string.Format(ERRORMESS_SET_VALUES_DIFFERS, - i + 1, - currentHeader, - memberName, - instanceValue, - rowValue); - - valueDifference.Add(difference); - } + var currentHeader = string.Empty; + var rowValue = GetRowValue(i, table, memberName, out currentHeader, doTypeConversion); + var rowType = rowValue.GetType().Name; + var instanceValue = Impromptu.InvokeGet(set[i], memberName); + var instanceType = instanceValue.GetType().Name; + + if (!instanceValue.Equals(rowValue)) + { + var difference = string.Format(ERRORMESS_SET_VALUES_DIFFERS, + i + 1, + currentHeader, + memberName, + instanceValue, + instanceType, + rowValue, + rowType); + + valueDifference.Add(difference); + } } } return valueDifference; @@ -177,11 +182,13 @@ private static IList ValidateValuesOfRow(TableRow tableRow, dynamic inst { var propertyName = CreatePropertyName(header); var valueFromInstance = Impromptu.InvokeGet(instance, propertyName); + var typeFromInstance = valueFromInstance.GetType().Name; var valueFromTable = CreateTypedValue(tableRow[header], doTypeConversion); + var typeFromTable = valueFromTable.GetType().Name; if (!valueFromInstance.Equals(valueFromTable)) { - var mess = string.Format(ERRORMESS_VALUE_DIFFERS, propertyName, valueFromInstance, valueFromTable); + var mess = string.Format(ERRORMESS_VALUE_DIFFERS, propertyName, valueFromInstance, typeFromInstance, valueFromTable, typeFromTable); valueDiffs.Add(mess); } }