1
+ using System . Text . Json ;
2
+ using System . Text . Json . Serialization . Metadata ;
1
3
using FluentAssertions ;
4
+ using ksqlDb . RestApi . Client . FluentAPI . Builders ;
5
+ using ksqlDB . RestApi . Client . KSql . RestApi ;
2
6
using ksqlDB . RestApi . Client . KSql . RestApi . Exceptions ;
3
7
using ksqlDB . RestApi . Client . KSql . RestApi . Parameters ;
4
8
using ksqlDb . RestApi . Client . Tests . Fakes . Logging ;
@@ -34,7 +38,7 @@ public async Task Run_LogInformation()
34
38
var queryParameters = new QueryStreamParameters ( ) ;
35
39
36
40
//Act
37
- var tweets = await ClassUnderTest . Run < Tweet > ( queryParameters ) . ToListAsync ( ) ;
41
+ await ClassUnderTest . Run < Tweet > ( queryParameters ) . ToListAsync ( ) ;
38
42
39
43
//Assert
40
44
LoggerMock . VerifyLog ( LogLevel . Information , Times . Once ) ;
@@ -177,12 +181,11 @@ public async Task LogError()
177
181
try
178
182
{
179
183
//Act
180
- var tweets = await ClassUnderTest . Run < Tweet > ( queryParameters ) . ToListAsync ( ) ;
181
-
182
- //Assert
184
+ await ClassUnderTest . Run < Tweet > ( queryParameters ) . ToListAsync ( ) ;
183
185
}
184
186
catch ( Exception )
185
187
{
188
+ //Assert
186
189
LoggerMock . VerifyLog ( LogLevel . Error , Times . Once ) ;
187
190
}
188
191
}
@@ -196,7 +199,7 @@ public async Task Run_Disposed_NothingWasReceived()
196
199
197
200
//Act
198
201
IAsyncEnumerable < Tweet > tweets = ClassUnderTest . Run < Tweet > ( queryParameters , cts . Token ) ;
199
- cts . Cancel ( ) ;
202
+ await cts . CancelAsync ( ) ;
200
203
201
204
//Assert
202
205
var receivedTweets = new List < Tweet > ( ) ;
@@ -237,4 +240,64 @@ public async Task Run_DonNotDisposeHttpClient()
237
240
//Assert
238
241
ClassUnderTest . LastUsedHttpClient . IsDisposed . Should ( ) . BeTrue ( ) ;
239
242
}
243
+
244
+ private class DomainObject
245
+ {
246
+ public int Id { get ; set ; }
247
+ }
248
+
249
+ #region JsonPropertyNameModifier
250
+
251
+ [ Test ]
252
+ public void JsonPropertyNameModifier ( )
253
+ {
254
+ //Arrange
255
+ var modelBuilder = new ModelBuilder ( ) ;
256
+ var jsonTypeInfo = new DefaultJsonTypeInfoResolver ( ) . GetTypeInfo ( typeof ( DomainObject ) , new JsonSerializerOptions ( ) ) ;
257
+
258
+ //Act
259
+ KSqlDbProvider . JsonPropertyNameModifier ( jsonTypeInfo , modelBuilder ) ;
260
+
261
+ //Assert
262
+ jsonTypeInfo . Properties [ 0 ] . Name . Should ( ) . Be ( nameof ( DomainObject . Id ) ) ;
263
+ }
264
+
265
+ [ Test ]
266
+ public void JsonPropertyNameModifier_ModelBuilder_HasColumnNameOverride ( )
267
+ {
268
+ //Arrange
269
+ var idColumnName = "id" ;
270
+ var modelBuilder = new ModelBuilder ( ) ;
271
+ modelBuilder . Entity < DomainObject > ( )
272
+ . Property ( c => c . Id )
273
+ . HasColumnName ( idColumnName ) ;
274
+
275
+ var jsonTypeInfo = new DefaultJsonTypeInfoResolver ( ) . GetTypeInfo ( typeof ( DomainObject ) , new JsonSerializerOptions ( ) ) ;
276
+
277
+ //Act
278
+ KSqlDbProvider . JsonPropertyNameModifier ( jsonTypeInfo , modelBuilder ) ;
279
+
280
+ //Assert
281
+ jsonTypeInfo . Properties [ 0 ] . Name . Should ( ) . Be ( idColumnName ) ;
282
+ }
283
+
284
+ [ Test ]
285
+ public void JsonPropertyNameModifier_ModelBuilder_WithoutHasColumnNameOverride ( )
286
+ {
287
+ //Arrange
288
+ var modelBuilder = new ModelBuilder ( ) ;
289
+ modelBuilder . Entity < DomainObject > ( )
290
+ . Property ( c => c . Id )
291
+ . WithHeaders ( ) ;
292
+
293
+ var jsonTypeInfo = new DefaultJsonTypeInfoResolver ( ) . GetTypeInfo ( typeof ( DomainObject ) , new JsonSerializerOptions ( ) ) ;
294
+
295
+ //Act
296
+ KSqlDbProvider . JsonPropertyNameModifier ( jsonTypeInfo , modelBuilder ) ;
297
+
298
+ //Assert
299
+ jsonTypeInfo . Properties [ 0 ] . Name . Should ( ) . Be ( nameof ( DomainObject . Id ) ) ;
300
+ }
301
+
302
+ #endregion
240
303
}
0 commit comments