@@ -65,13 +65,14 @@ public static IEnumerable<dynamic> CreateDynamicSet(this Table table, bool doTyp
6565 /// </summary>
6666 /// <param name="table">the table to compare the instance against</param>
6767 /// <param name="instance">the instance to compare the table against</param>
68- public static void CompareToDynamicInstance ( this Table table , dynamic instance )
68+ /// <param name="doTypeConversion">should types be converted according to conventions described in https://github.com/marcusoftnet/SpecFlow.Assist.Dynamic/wiki/Conversion-conventions#property-type-conversions</param>
69+ public static void CompareToDynamicInstance ( this Table table , dynamic instance , bool doTypeConversion = true )
6970 {
7071 IList < string > propDiffs = GetPropertyDifferences ( table , instance ) ;
7172 if ( propDiffs . Any ( ) )
7273 throw new DynamicInstanceComparisonException ( propDiffs ) ;
7374
74- AssertValuesOfRowDifference ( table . Rows [ 0 ] , instance ) ;
75+ AssertValuesOfRowDifference ( table . Rows [ 0 ] , instance , doTypeConversion ) ;
7576 }
7677
7778 /// <summary>
@@ -80,7 +81,8 @@ public static void CompareToDynamicInstance(this Table table, dynamic instance)
8081 /// </summary>
8182 /// <param name="table">the table to compare the set against</param>
8283 /// <param name="set">the set to compare the table against</param>
83- public static void CompareToDynamicSet ( this Table table , IList < dynamic > set )
84+ /// <param name="doTypeConversion">should types be converted according to conventions described in https://github.com/marcusoftnet/SpecFlow.Assist.Dynamic/wiki/Conversion-conventions#property-type-conversions</param>
85+ public static void CompareToDynamicSet ( this Table table , IList < dynamic > set , bool doTypeConversion = true )
8486 {
8587 AssertEqualNumberOfRows ( table , set ) ;
8688
@@ -92,15 +94,15 @@ public static void CompareToDynamicSet(this Table table, IList<dynamic> set)
9294
9395 // Now we know that the table and the list has the same number of rows and properties
9496
95- var valueDifference = GetSetValueDifferences ( table , set ) ;
97+ var valueDifference = GetSetValueDifferences ( table , set , doTypeConversion ) ;
9698
9799 if ( valueDifference . Any ( ) )
98100 {
99101 throw new DynamicSetComparisonException ( ERRORMESS_PROPERTY_DIFF_SET , valueDifference ) ;
100102 }
101103 }
102104
103- private static List < string > GetSetValueDifferences ( Table table , IList < object > set )
105+ private static List < string > GetSetValueDifferences ( Table table , IList < object > set , bool doTypeConversion = true )
104106 {
105107 var memberNames = Impromptu . GetMemberNames ( set [ 0 ] ) ;
106108 var valueDifference = new List < string > ( ) ;
@@ -110,7 +112,7 @@ private static List<string> GetSetValueDifferences(Table table, IList<object> se
110112 foreach ( var memberName in memberNames )
111113 {
112114 var currentHeader = string . Empty ;
113- var rowValue = GetRowValue ( i , table , memberName , out currentHeader ) ;
115+ var rowValue = GetRowValue ( i , table , memberName , out currentHeader , doTypeConversion ) ;
114116 var instanceValue = Impromptu . InvokeGet ( set [ i ] , memberName ) ;
115117
116118 if ( ! instanceValue . Equals ( rowValue ) )
@@ -129,7 +131,7 @@ private static List<string> GetSetValueDifferences(Table table, IList<object> se
129131 return valueDifference ;
130132 }
131133
132- private static object GetRowValue ( int rowIndex , Table table , string memberName , out string currentHeader )
134+ private static object GetRowValue ( int rowIndex , Table table , string memberName , out string currentHeader , bool doTypeConversion = true )
133135 {
134136 object rowValue = null ;
135137 currentHeader = string . Empty ;
@@ -138,21 +140,21 @@ private static object GetRowValue(int rowIndex, Table table, string memberName,
138140 if ( CreatePropertyName ( header ) == memberName )
139141 {
140142 currentHeader = header ;
141- rowValue = CreateTypedValue ( table . Rows [ rowIndex ] [ header ] ) ;
143+ rowValue = CreateTypedValue ( table . Rows [ rowIndex ] [ header ] , doTypeConversion ) ;
142144 break ;
143145 }
144146 }
145147 return rowValue ;
146148 }
147149
148- private static void AssertValuesOfRowDifference ( TableRow tableRow , dynamic instance )
150+ private static void AssertValuesOfRowDifference ( TableRow tableRow , dynamic instance , bool doTypeConversion = true )
149151 {
150- IList < string > valueDiffs = ValidateValuesOfRow ( tableRow , instance ) ;
152+ IList < string > valueDiffs = ValidateValuesOfRow ( tableRow , instance , doTypeConversion ) ;
151153 if ( valueDiffs . Any ( ) )
152154 throw new DynamicInstanceComparisonException ( valueDiffs ) ;
153155 }
154156
155- private static IList < string > GetPropertyDifferences ( Table table , dynamic instance )
157+ private static IList < string > GetPropertyDifferences ( Table table , dynamic instance , bool doTypeConversion = true )
156158 {
157159 var tableHeadersAsPropertyNames = table . Header . Select ( CreatePropertyName ) ;
158160 IEnumerable < string > instanceMembers = Impromptu . GetMemberNames ( instance ) ;
@@ -169,15 +171,15 @@ private static void AssertEqualNumberOfRows(Table table, IList<object> set)
169171 }
170172 }
171173
172- private static IList < string > ValidateValuesOfRow ( TableRow tableRow , dynamic instance )
174+ private static IList < string > ValidateValuesOfRow ( TableRow tableRow , dynamic instance , bool doTypeConversion = true )
173175 {
174176 var valueDiffs = new List < string > ( ) ;
175177
176178 foreach ( var header in tableRow . Keys )
177179 {
178180 var propertyName = CreatePropertyName ( header ) ;
179181 var valueFromInstance = Impromptu . InvokeGet ( instance , propertyName ) ;
180- var valueFromTable = CreateTypedValue ( tableRow [ header ] ) ;
182+ var valueFromTable = CreateTypedValue ( tableRow [ header ] , doTypeConversion ) ;
181183
182184 if ( ! valueFromInstance . Equals ( valueFromTable ) )
183185 {
0 commit comments