1
+ using System . Globalization ;
1
2
using System . Net ;
2
3
using System . Reflection ;
3
4
using System . Text . Json . Serialization ;
@@ -60,7 +61,9 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
60
61
} ) ;
61
62
62
63
string attributeName = propertyName . Camelize ( ) ;
63
- string route = $ "/filterableResources?filter=equals({ attributeName } ,'{ propertyValue } ')";
64
+ string ? attributeValue = Convert . ToString ( propertyValue , CultureInfo . InvariantCulture ) ;
65
+
66
+ string route = $ "/filterableResources?filter=equals({ attributeName } ,'{ attributeValue } ')";
64
67
65
68
// Act
66
69
( HttpResponseMessage httpResponse , Document responseDocument ) = await _testContext . ExecuteGetAsync < Document > ( route ) ;
@@ -88,7 +91,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
88
91
await dbContext . SaveChangesAsync ( ) ;
89
92
} ) ;
90
93
91
- string route = $ "/filterableResources?filter=equals(someDecimal,'{ resource . SomeDecimal } ')";
94
+ string route = $ "/filterableResources?filter=equals(someDecimal,'{ resource . SomeDecimal . ToString ( CultureInfo . InvariantCulture ) } ')";
92
95
93
96
// Act
94
97
( HttpResponseMessage httpResponse , Document responseDocument ) = await _testContext . ExecuteGetAsync < Document > ( route ) ;
@@ -232,7 +235,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
232
235
await dbContext . SaveChangesAsync ( ) ;
233
236
} ) ;
234
237
235
- string route = $ "/filterableResources?filter=equals(someTimeSpan,'{ resource . SomeTimeSpan } ')";
238
+ string route = $ "/filterableResources?filter=equals(someTimeSpan,'{ resource . SomeTimeSpan : c } ')";
236
239
237
240
// Act
238
241
( HttpResponseMessage httpResponse , Document responseDocument ) = await _testContext . ExecuteGetAsync < Document > ( route ) ;
@@ -244,6 +247,62 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
244
247
responseDocument . Data . ManyValue [ 0 ] . Attributes . ShouldContainKey ( "someTimeSpan" ) . With ( value => value . Should ( ) . Be ( resource . SomeTimeSpan ) ) ;
245
248
}
246
249
250
+ [ Fact ]
251
+ public async Task Can_filter_equality_on_type_DateOnly ( )
252
+ {
253
+ // Arrange
254
+ var resource = new FilterableResource
255
+ {
256
+ SomeDateOnly = DateOnly . FromDateTime ( 27 . January ( 2003 ) )
257
+ } ;
258
+
259
+ await _testContext . RunOnDatabaseAsync ( async dbContext =>
260
+ {
261
+ await dbContext . ClearTableAsync < FilterableResource > ( ) ;
262
+ dbContext . FilterableResources . AddRange ( resource , new FilterableResource ( ) ) ;
263
+ await dbContext . SaveChangesAsync ( ) ;
264
+ } ) ;
265
+
266
+ string route = $ "/filterableResources?filter=equals(someDateOnly,'{ resource . SomeDateOnly : O} ')";
267
+
268
+ // Act
269
+ ( HttpResponseMessage httpResponse , Document responseDocument ) = await _testContext . ExecuteGetAsync < Document > ( route ) ;
270
+
271
+ // Assert
272
+ httpResponse . ShouldHaveStatusCode ( HttpStatusCode . OK ) ;
273
+
274
+ responseDocument . Data . ManyValue . ShouldHaveCount ( 1 ) ;
275
+ responseDocument . Data . ManyValue [ 0 ] . Attributes . ShouldContainKey ( "someDateOnly" ) . With ( value => value . Should ( ) . Be ( resource . SomeDateOnly ) ) ;
276
+ }
277
+
278
+ [ Fact ]
279
+ public async Task Can_filter_equality_on_type_TimeOnly ( )
280
+ {
281
+ // Arrange
282
+ var resource = new FilterableResource
283
+ {
284
+ SomeTimeOnly = new TimeOnly ( 23 , 59 , 59 , 999 )
285
+ } ;
286
+
287
+ await _testContext . RunOnDatabaseAsync ( async dbContext =>
288
+ {
289
+ await dbContext . ClearTableAsync < FilterableResource > ( ) ;
290
+ dbContext . FilterableResources . AddRange ( resource , new FilterableResource ( ) ) ;
291
+ await dbContext . SaveChangesAsync ( ) ;
292
+ } ) ;
293
+
294
+ string route = $ "/filterableResources?filter=equals(someTimeOnly,'{ resource . SomeTimeOnly : O} ')";
295
+
296
+ // Act
297
+ ( HttpResponseMessage httpResponse , Document responseDocument ) = await _testContext . ExecuteGetAsync < Document > ( route ) ;
298
+
299
+ // Assert
300
+ httpResponse . ShouldHaveStatusCode ( HttpStatusCode . OK ) ;
301
+
302
+ responseDocument . Data . ManyValue . ShouldHaveCount ( 1 ) ;
303
+ responseDocument . Data . ManyValue [ 0 ] . Attributes . ShouldContainKey ( "someTimeOnly" ) . With ( value => value . Should ( ) . Be ( resource . SomeTimeOnly ) ) ;
304
+ }
305
+
247
306
[ Fact ]
248
307
public async Task Cannot_filter_equality_on_incompatible_value ( )
249
308
{
@@ -288,6 +347,8 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
288
347
[ InlineData ( nameof ( FilterableResource . SomeNullableDateTime ) ) ]
289
348
[ InlineData ( nameof ( FilterableResource . SomeNullableDateTimeOffset ) ) ]
290
349
[ InlineData ( nameof ( FilterableResource . SomeNullableTimeSpan ) ) ]
350
+ [ InlineData ( nameof ( FilterableResource . SomeNullableDateOnly ) ) ]
351
+ [ InlineData ( nameof ( FilterableResource . SomeNullableTimeOnly ) ) ]
291
352
[ InlineData ( nameof ( FilterableResource . SomeNullableEnum ) ) ]
292
353
public async Task Can_filter_is_null_on_type ( string propertyName )
293
354
{
@@ -308,6 +369,8 @@ public async Task Can_filter_is_null_on_type(string propertyName)
308
369
SomeNullableDateTime = 1 . January ( 2001 ) . AsUtc ( ) ,
309
370
SomeNullableDateTimeOffset = 1 . January ( 2001 ) . AsUtc ( ) ,
310
371
SomeNullableTimeSpan = TimeSpan . FromHours ( 1 ) ,
372
+ SomeNullableDateOnly = DateOnly . FromDateTime ( 1 . January ( 2001 ) ) ,
373
+ SomeNullableTimeOnly = new TimeOnly ( 1 , 0 ) ,
311
374
SomeNullableEnum = DayOfWeek . Friday
312
375
} ;
313
376
@@ -342,6 +405,8 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
342
405
[ InlineData ( nameof ( FilterableResource . SomeNullableDateTime ) ) ]
343
406
[ InlineData ( nameof ( FilterableResource . SomeNullableDateTimeOffset ) ) ]
344
407
[ InlineData ( nameof ( FilterableResource . SomeNullableTimeSpan ) ) ]
408
+ [ InlineData ( nameof ( FilterableResource . SomeNullableDateOnly ) ) ]
409
+ [ InlineData ( nameof ( FilterableResource . SomeNullableTimeOnly ) ) ]
345
410
[ InlineData ( nameof ( FilterableResource . SomeNullableEnum ) ) ]
346
411
public async Task Can_filter_is_not_null_on_type ( string propertyName )
347
412
{
@@ -358,6 +423,8 @@ public async Task Can_filter_is_not_null_on_type(string propertyName)
358
423
SomeNullableDateTime = 1 . January ( 2001 ) . AsUtc ( ) ,
359
424
SomeNullableDateTimeOffset = 1 . January ( 2001 ) . AsUtc ( ) ,
360
425
SomeNullableTimeSpan = TimeSpan . FromHours ( 1 ) ,
426
+ SomeNullableDateOnly = DateOnly . FromDateTime ( 1 . January ( 2001 ) ) ,
427
+ SomeNullableTimeOnly = new TimeOnly ( 1 , 0 ) ,
361
428
SomeNullableEnum = DayOfWeek . Friday
362
429
} ;
363
430
0 commit comments