@@ -11,49 +11,186 @@ namespace Snowflake.Client.Tests.UnitTests
11
11
public class SnowflakeDataMapperTests
12
12
{
13
13
[ Test ]
14
- public void SnowflakeDataMapper_MapTo_CustomClass ( )
14
+ public void ResponseWithValues_MapTo_CustomClass ( )
15
15
{
16
16
var responseSample = GetFakeResponse ( ) ;
17
+ var firstObjectRowset = new List < List < string > > ( ) { responseSample . RowSet [ 0 ] } ;
18
+ var mappedObjects = SnowflakeDataMapper . MapTo < CustomClass > ( responseSample . RowType , firstObjectRowset ) ;
19
+ var mappedObject = mappedObjects . FirstOrDefault ( ) ;
17
20
18
- var mappedObjects = SnowflakeDataMapper . MapTo < CustomClass > ( responseSample . RowType , responseSample . RowSet ) ;
19
- var firstObject = mappedObjects . FirstOrDefault ( ) ;
20
-
21
- Assert . IsNotNull ( firstObject ) ;
22
- Assert . AreEqual ( "Sometext" , firstObject . StringProperty ) ;
23
- Assert . AreEqual ( true , firstObject . BoolProperty ) ;
24
- Assert . AreEqual ( 7 , firstObject . IntProperty ) ;
25
- Assert . AreEqual ( 27.6F , firstObject . FloatProperty ) ;
26
- Assert . AreEqual ( 19.239834M , firstObject . DecimalProperty ) ;
27
- Assert . AreEqual ( Guid . Parse ( "e7412bbf-88ee-4149-b341-101e0f72ec7c" ) , firstObject . GuidProperty ) ;
28
- Assert . AreEqual ( new byte [ ] { 0 , 128 , 255 } , firstObject . ByteArrayProperty ) ;
21
+ Assert . IsNotNull ( mappedObject ) ;
22
+ Assert . AreEqual ( "Sometext" , mappedObject . StringProperty ) ;
23
+ Assert . AreEqual ( true , mappedObject . BoolProperty ) ;
24
+ Assert . AreEqual ( 7 , mappedObject . IntProperty ) ;
25
+ Assert . AreEqual ( 27.6F , mappedObject . FloatProperty ) ;
26
+ Assert . AreEqual ( 19.239834M , mappedObject . DecimalProperty ) ;
27
+ Assert . AreEqual ( Guid . Parse ( "e7412bbf-88ee-4149-b341-101e0f72ec7c" ) , mappedObject . GuidProperty ) ;
28
+ Assert . AreEqual ( new byte [ ] { 0 , 128 , 255 } , mappedObject . ByteArrayProperty ) ;
29
29
30
30
var dateTime = DateTime . ParseExact ( "2020-09-13 12:26:40.0000000" , "yyyy-MM-dd HH:mm:ss.fffffff" , CultureInfo . InvariantCulture ) ;
31
- Assert . AreEqual ( dateTime , firstObject . DateTimeProperty ) ;
31
+ Assert . AreEqual ( dateTime , mappedObject . DateTimeProperty ) ;
32
32
33
33
var dateTimeOffset = DateTimeOffset . ParseExact ( "2020-09-13 12:26:40.0000000" , "yyyy-MM-dd HH:mm:ss.fffffff" , CultureInfo . InvariantCulture , DateTimeStyles . AssumeUniversal ) ;
34
- Assert . AreEqual ( dateTimeOffset , firstObject . DateTimeOffsetProperty ) ;
34
+ Assert . AreEqual ( dateTimeOffset , mappedObject . DateTimeOffsetProperty ) ;
35
35
}
36
36
37
37
[ Test ]
38
- public void SnowflakeDataMapper_MapTo_CustomClassWithNullableProps ( )
38
+ public void ResponseWithValues_MapTo_CustomClassWithNullableProps ( )
39
39
{
40
40
var responseSample = GetFakeResponse ( ) ;
41
+ var firstObjectRowset = new List < List < string > > ( ) { responseSample . RowSet [ 0 ] } ;
42
+ var mappedObjects = SnowflakeDataMapper . MapTo < CustomClassNullables > ( responseSample . RowType , firstObjectRowset ) ;
43
+ var mappedObject = mappedObjects . FirstOrDefault ( ) ;
41
44
42
- var mappedObjects = SnowflakeDataMapper . MapTo < CustomClassNullables > ( responseSample . RowType , responseSample . RowSet ) ;
43
- var firstObject = mappedObjects . FirstOrDefault ( ) ;
44
-
45
- Assert . IsNotNull ( firstObject ) ;
46
- Assert . AreEqual ( true , firstObject . BoolProperty ) ;
47
- Assert . AreEqual ( 7 , firstObject . IntProperty ) ;
48
- Assert . AreEqual ( 27.6F , firstObject . FloatProperty ) ;
49
- Assert . AreEqual ( 19.239834M , firstObject . DecimalProperty ) ;
50
- Assert . AreEqual ( Guid . Parse ( "e7412bbf-88ee-4149-b341-101e0f72ec7c" ) , firstObject . GuidProperty ) ;
45
+ Assert . IsNotNull ( mappedObject ) ;
46
+ Assert . AreEqual ( true , mappedObject . BoolProperty ) ;
47
+ Assert . AreEqual ( 7 , mappedObject . IntProperty ) ;
48
+ Assert . AreEqual ( 27.6F , mappedObject . FloatProperty ) ;
49
+ Assert . AreEqual ( 19.239834M , mappedObject . DecimalProperty ) ;
50
+ Assert . AreEqual ( Guid . Parse ( "e7412bbf-88ee-4149-b341-101e0f72ec7c" ) , mappedObject . GuidProperty ) ;
51
51
52
52
var dateTime = DateTime . ParseExact ( "2020-09-13 12:26:40.0000000" , "yyyy-MM-dd HH:mm:ss.fffffff" , CultureInfo . InvariantCulture ) ;
53
- Assert . AreEqual ( dateTime , firstObject . DateTimeProperty ) ;
53
+ Assert . AreEqual ( dateTime , mappedObject . DateTimeProperty ) ;
54
54
55
55
var dateTimeOffset = DateTimeOffset . ParseExact ( "2020-09-13 12:26:40.0000000" , "yyyy-MM-dd HH:mm:ss.fffffff" , CultureInfo . InvariantCulture , DateTimeStyles . AssumeUniversal ) ;
56
- Assert . AreEqual ( dateTimeOffset , firstObject . DateTimeOffsetProperty ) ;
56
+ Assert . AreEqual ( dateTimeOffset , mappedObject . DateTimeOffsetProperty ) ;
57
+ }
58
+
59
+ [ Test ]
60
+ public void ResponseWithStringNull_MapTo_CustomClassWithNullables ( )
61
+ {
62
+ var responseSample = GetFakeResponse ( ) ;
63
+
64
+ var firstObjectRowset = new List < List < string > > ( ) { responseSample . RowSet [ 1 ] } ;
65
+ var mappedObjects = SnowflakeDataMapper . MapTo < CustomClassNullables > ( responseSample . RowType , firstObjectRowset ) ;
66
+ var mappedObject = mappedObjects . FirstOrDefault ( ) ;
67
+
68
+ Assert . IsNotNull ( mappedObject ) ;
69
+ Assert . AreEqual ( null , mappedObject . StringProperty ) ;
70
+ Assert . AreEqual ( null , mappedObject . BoolProperty ) ;
71
+ Assert . AreEqual ( null , mappedObject . IntProperty ) ;
72
+ Assert . AreEqual ( null , mappedObject . FloatProperty ) ;
73
+ Assert . AreEqual ( null , mappedObject . DecimalProperty ) ;
74
+ Assert . AreEqual ( null , mappedObject . GuidProperty ) ;
75
+ Assert . AreEqual ( null , mappedObject . DateTimeProperty ) ;
76
+ Assert . AreEqual ( null , mappedObject . DateTimeOffsetProperty ) ;
77
+ Assert . AreEqual ( null , mappedObject . ByteArrayProperty ) ;
78
+ }
79
+
80
+ [ Test ]
81
+ public void ResponseWithNull_MapTo_CustomClassWithNullables ( )
82
+ {
83
+ var responseSample = GetFakeResponse ( ) ;
84
+
85
+ var firstObjectRowset = new List < List < string > > ( ) { responseSample . RowSet [ 2 ] } ;
86
+ var mappedObjects = SnowflakeDataMapper . MapTo < CustomClassNullables > ( responseSample . RowType , firstObjectRowset ) ;
87
+ var mappedObject = mappedObjects . FirstOrDefault ( ) ;
88
+
89
+ Assert . IsNotNull ( mappedObject ) ;
90
+ Assert . AreEqual ( null , mappedObject . StringProperty ) ;
91
+ Assert . AreEqual ( null , mappedObject . BoolProperty ) ;
92
+ Assert . AreEqual ( null , mappedObject . IntProperty ) ;
93
+ Assert . AreEqual ( null , mappedObject . FloatProperty ) ;
94
+ Assert . AreEqual ( null , mappedObject . DecimalProperty ) ;
95
+ Assert . AreEqual ( null , mappedObject . GuidProperty ) ;
96
+ Assert . AreEqual ( null , mappedObject . DateTimeProperty ) ;
97
+ Assert . AreEqual ( null , mappedObject . DateTimeOffsetProperty ) ;
98
+ Assert . AreEqual ( null , mappedObject . ByteArrayProperty ) ;
99
+ }
100
+
101
+ [ Test ]
102
+ public void ResponseWithValues_MapTo_SingleValue ( )
103
+ {
104
+ var responseSample = GetFakeResponse ( ) ;
105
+ var rowSet = responseSample . RowSet [ 0 ] ;
106
+ var rowType = responseSample . RowType ;
107
+
108
+ var stringValue = SnowflakeDataMapper . MapTo < string > ( rowType [ 0 ] , rowSet [ 0 ] ) ;
109
+ Assert . AreEqual ( "Sometext" , stringValue ) ;
110
+
111
+ var boolValue = SnowflakeDataMapper . MapTo < bool > ( rowType [ 1 ] , rowSet [ 1 ] ) ;
112
+ Assert . AreEqual ( true , boolValue ) ;
113
+
114
+ var intValue = SnowflakeDataMapper . MapTo < int > ( rowType [ 2 ] , rowSet [ 2 ] ) ;
115
+ Assert . AreEqual ( 7 , intValue ) ;
116
+
117
+ var floatValue = SnowflakeDataMapper . MapTo < float > ( rowType [ 3 ] , rowSet [ 3 ] ) ;
118
+ Assert . AreEqual ( 27.6F , floatValue ) ;
119
+
120
+ var decimalValue = SnowflakeDataMapper . MapTo < decimal > ( rowType [ 4 ] , rowSet [ 4 ] ) ;
121
+ Assert . AreEqual ( 19.239834M , decimalValue ) ;
122
+
123
+ var dateTimeExpected = DateTime . ParseExact ( "2020-09-13 12:26:40.0000000" , "yyyy-MM-dd HH:mm:ss.fffffff" , CultureInfo . InvariantCulture ) ;
124
+ var dateTimeValue = SnowflakeDataMapper . MapTo < DateTime > ( rowType [ 5 ] , rowSet [ 5 ] ) ;
125
+ Assert . AreEqual ( dateTimeExpected , dateTimeValue ) ;
126
+
127
+ var dateTimeOffsetExpected = DateTimeOffset . ParseExact ( "2020-09-13 12:26:40.0000000" , "yyyy-MM-dd HH:mm:ss.fffffff" , CultureInfo . InvariantCulture , DateTimeStyles . AssumeUniversal ) ;
128
+ var dateTimeOffsetValue = SnowflakeDataMapper . MapTo < DateTimeOffset > ( rowType [ 6 ] , rowSet [ 6 ] ) ;
129
+ Assert . AreEqual ( dateTimeOffsetExpected , dateTimeOffsetValue ) ;
130
+
131
+ var guidValue = SnowflakeDataMapper . MapTo < Guid > ( rowType [ 7 ] , rowSet [ 7 ] ) ;
132
+ Assert . AreEqual ( Guid . Parse ( "e7412bbf-88ee-4149-b341-101e0f72ec7c" ) , guidValue ) ;
133
+
134
+ var bytesValues = SnowflakeDataMapper . MapTo < byte [ ] > ( rowType [ 8 ] , rowSet [ 8 ] ) ;
135
+ Assert . AreEqual ( new byte [ ] { 0 , 128 , 255 } , bytesValues ) ;
136
+ }
137
+
138
+ [ Test ]
139
+ public void ResponseWithStringNull_MapTo_SingleValueNullable ( )
140
+ {
141
+ var responseSample = GetFakeResponse ( ) ;
142
+ var rowSet = responseSample . RowSet [ 1 ] ;
143
+ var rowType = responseSample . RowType ;
144
+
145
+ var boolValue = SnowflakeDataMapper . MapTo < bool ? > ( rowType [ 1 ] , rowSet [ 1 ] ) ;
146
+ Assert . AreEqual ( null , boolValue ) ;
147
+
148
+ var intValue = SnowflakeDataMapper . MapTo < int ? > ( rowType [ 2 ] , rowSet [ 2 ] ) ;
149
+ Assert . AreEqual ( null , intValue ) ;
150
+
151
+ var floatValue = SnowflakeDataMapper . MapTo < float ? > ( rowType [ 3 ] , rowSet [ 3 ] ) ;
152
+ Assert . AreEqual ( null , floatValue ) ;
153
+
154
+ var decimalValue = SnowflakeDataMapper . MapTo < decimal ? > ( rowType [ 4 ] , rowSet [ 4 ] ) ;
155
+ Assert . AreEqual ( null , decimalValue ) ;
156
+
157
+ var dateTimeValue = SnowflakeDataMapper . MapTo < DateTime ? > ( rowType [ 5 ] , rowSet [ 5 ] ) ;
158
+ Assert . AreEqual ( null , dateTimeValue ) ;
159
+
160
+ var dateTimeOffsetValue = SnowflakeDataMapper . MapTo < DateTimeOffset ? > ( rowType [ 6 ] , rowSet [ 6 ] ) ;
161
+ Assert . AreEqual ( null , dateTimeOffsetValue ) ;
162
+
163
+ var guidValue = SnowflakeDataMapper . MapTo < Guid ? > ( rowType [ 7 ] , rowSet [ 7 ] ) ;
164
+ Assert . AreEqual ( null , guidValue ) ;
165
+ }
166
+
167
+ [ Test ]
168
+ public void ResponseWithNull_MapTo_SingleValueNullable ( )
169
+ {
170
+ var responseSample = GetFakeResponse ( ) ;
171
+ var rowSet = responseSample . RowSet [ 2 ] ;
172
+ var rowType = responseSample . RowType ;
173
+
174
+ var boolValue = SnowflakeDataMapper . MapTo < bool ? > ( rowType [ 1 ] , rowSet [ 1 ] ) ;
175
+ Assert . AreEqual ( null , boolValue ) ;
176
+
177
+ var intValue = SnowflakeDataMapper . MapTo < int ? > ( rowType [ 2 ] , rowSet [ 2 ] ) ;
178
+ Assert . AreEqual ( null , intValue ) ;
179
+
180
+ var floatValue = SnowflakeDataMapper . MapTo < float ? > ( rowType [ 3 ] , rowSet [ 3 ] ) ;
181
+ Assert . AreEqual ( null , floatValue ) ;
182
+
183
+ var decimalValue = SnowflakeDataMapper . MapTo < decimal ? > ( rowType [ 4 ] , rowSet [ 4 ] ) ;
184
+ Assert . AreEqual ( null , decimalValue ) ;
185
+
186
+ var dateTimeValue = SnowflakeDataMapper . MapTo < DateTime ? > ( rowType [ 5 ] , rowSet [ 5 ] ) ;
187
+ Assert . AreEqual ( null , dateTimeValue ) ;
188
+
189
+ var dateTimeOffsetValue = SnowflakeDataMapper . MapTo < DateTimeOffset ? > ( rowType [ 6 ] , rowSet [ 6 ] ) ;
190
+ Assert . AreEqual ( null , dateTimeOffsetValue ) ;
191
+
192
+ var guidValue = SnowflakeDataMapper . MapTo < Guid ? > ( rowType [ 7 ] , rowSet [ 7 ] ) ;
193
+ Assert . AreEqual ( null , guidValue ) ;
57
194
}
58
195
59
196
private QueryExecResponseData GetFakeResponse ( )
@@ -70,7 +207,8 @@ private QueryExecResponseData GetFakeResponse()
70
207
response . RowType . Add ( new ColumnDescription ( ) { Name = "GuidProperty" , Type = "text" } ) ;
71
208
response . RowType . Add ( new ColumnDescription ( ) { Name = "ByteArrayProperty" , Type = "binary" } ) ;
72
209
73
- response . RowSet . Add ( new List < string > ( ) {
210
+ response . RowSet . Add ( new List < string > ( )
211
+ {
74
212
"Sometext" ,
75
213
"true" ,
76
214
"7" ,
@@ -82,6 +220,33 @@ private QueryExecResponseData GetFakeResponse()
82
220
"0080ff"
83
221
} ) ;
84
222
223
+ response . RowSet . Add ( new List < string > ( )
224
+ {
225
+ "null" ,
226
+ "null" ,
227
+ "null" ,
228
+ "null" ,
229
+ "null" ,
230
+ "null" ,
231
+ "null" ,
232
+ "null" ,
233
+ "null"
234
+ } ) ;
235
+
236
+
237
+ response . RowSet . Add ( new List < string > ( )
238
+ {
239
+ null ,
240
+ null ,
241
+ null ,
242
+ null ,
243
+ null ,
244
+ null ,
245
+ null ,
246
+ null ,
247
+ null
248
+ } ) ;
249
+
85
250
return response ;
86
251
}
87
252
@@ -108,6 +273,8 @@ private class CustomClass
108
273
109
274
private class CustomClassNullables
110
275
{
276
+ public string StringProperty { get ; set ; }
277
+
111
278
public bool ? BoolProperty { get ; set ; }
112
279
113
280
public int ? IntProperty { get ; set ; }
@@ -121,6 +288,8 @@ private class CustomClassNullables
121
288
public DateTimeOffset ? DateTimeOffsetProperty { get ; set ; }
122
289
123
290
public Guid ? GuidProperty { get ; set ; }
291
+
292
+ public byte [ ] ByteArrayProperty { get ; set ; }
124
293
}
125
294
}
126
- }
295
+ }
0 commit comments