@@ -27,9 +27,25 @@ public class QueryTests
2727 private class MyClass
2828 {
2929 public int ID { get ; set ; }
30+
3031 public string Name { get ; set ; }
32+
3133 [ Column ( "RealColumnName" ) ]
3234 public string PropWithAttribute { get ; set ; }
35+
36+ public FoodEnum PlainFood { get ; set ; }
37+
38+ [ FoodEnumConverter ]
39+ public FoodEnum ConvertedFood { get ; set ; }
40+ }
41+
42+ public enum FoodEnum { Apple , Banana , Carrot } ;
43+
44+ private class FoodEnumConverter : ValueConverterAttribute
45+ {
46+ public override object ConvertFromDb ( object value ) => throw new NotImplementedException ( ) ;
47+
48+ public override object ConvertToDb ( object value ) => value . ToString ( ) ;
3349 }
3450
3551 private Mock < IDatabase > _mockDb ;
@@ -66,5 +82,19 @@ public void Query_Should_Use_Column_Attribute(string value)
6682 _mockDb . Object . Query < MyClass > ( c => c . PropWithAttribute == value ) ;
6783 _lastSql . Should ( ) . BeEquivalentTo ( new Sql ( "WHERE <RealColumnName> = @0" , value ) ) ;
6884 }
85+
86+ [ Theory , AutoData ]
87+ public void Query_Should_Use_Value_Converter ( FoodEnum food )
88+ {
89+ _mockDb . Object . Query < MyClass > ( c => c . ConvertedFood == food ) ;
90+ _lastSql . Should ( ) . BeEquivalentTo ( new Sql ( "WHERE <ConvertedFood> = @0" , food . ToString ( ) ) ) ;
91+ }
92+
93+ [ Theory , AutoData ]
94+ public void Query_Should_Use_Plain_Value_With_No_Value_Converter ( FoodEnum food )
95+ {
96+ _mockDb . Object . Query < MyClass > ( c => c . PlainFood == food ) ;
97+ _lastSql . Should ( ) . BeEquivalentTo ( new Sql ( "WHERE <PlainFood> = @0" , ( int ) food ) ) ;
98+ }
6999 }
70100}
0 commit comments