1+ using System . Globalization ;
12using System . Net ;
23using System . Reflection ;
34using System . Text . Json . Serialization ;
@@ -60,7 +61,9 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
6061 } ) ;
6162
6263 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 } ')";
6467
6568 // Act
6669 ( HttpResponseMessage httpResponse , Document responseDocument ) = await _testContext . ExecuteGetAsync < Document > ( route ) ;
@@ -88,7 +91,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
8891 await dbContext . SaveChangesAsync ( ) ;
8992 } ) ;
9093
91- string route = $ "/filterableResources?filter=equals(someDecimal,'{ resource . SomeDecimal } ')";
94+ string route = $ "/filterableResources?filter=equals(someDecimal,'{ resource . SomeDecimal . ToString ( CultureInfo . InvariantCulture ) } ')";
9295
9396 // Act
9497 ( HttpResponseMessage httpResponse , Document responseDocument ) = await _testContext . ExecuteGetAsync < Document > ( route ) ;
@@ -232,7 +235,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
232235 await dbContext . SaveChangesAsync ( ) ;
233236 } ) ;
234237
235- string route = $ "/filterableResources?filter=equals(someTimeSpan,'{ resource . SomeTimeSpan } ')";
238+ string route = $ "/filterableResources?filter=equals(someTimeSpan,'{ resource . SomeTimeSpan : c } ')";
236239
237240 // Act
238241 ( HttpResponseMessage httpResponse , Document responseDocument ) = await _testContext . ExecuteGetAsync < Document > ( route ) ;
@@ -244,6 +247,62 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
244247 responseDocument . Data . ManyValue [ 0 ] . Attributes . ShouldContainKey ( "someTimeSpan" ) . With ( value => value . Should ( ) . Be ( resource . SomeTimeSpan ) ) ;
245248 }
246249
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+
247306 [ Fact ]
248307 public async Task Cannot_filter_equality_on_incompatible_value ( )
249308 {
@@ -288,6 +347,8 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
288347 [ InlineData ( nameof ( FilterableResource . SomeNullableDateTime ) ) ]
289348 [ InlineData ( nameof ( FilterableResource . SomeNullableDateTimeOffset ) ) ]
290349 [ InlineData ( nameof ( FilterableResource . SomeNullableTimeSpan ) ) ]
350+ [ InlineData ( nameof ( FilterableResource . SomeNullableDateOnly ) ) ]
351+ [ InlineData ( nameof ( FilterableResource . SomeNullableTimeOnly ) ) ]
291352 [ InlineData ( nameof ( FilterableResource . SomeNullableEnum ) ) ]
292353 public async Task Can_filter_is_null_on_type ( string propertyName )
293354 {
@@ -308,6 +369,8 @@ public async Task Can_filter_is_null_on_type(string propertyName)
308369 SomeNullableDateTime = 1 . January ( 2001 ) . AsUtc ( ) ,
309370 SomeNullableDateTimeOffset = 1 . January ( 2001 ) . AsUtc ( ) ,
310371 SomeNullableTimeSpan = TimeSpan . FromHours ( 1 ) ,
372+ SomeNullableDateOnly = DateOnly . FromDateTime ( 1 . January ( 2001 ) ) ,
373+ SomeNullableTimeOnly = new TimeOnly ( 1 , 0 ) ,
311374 SomeNullableEnum = DayOfWeek . Friday
312375 } ;
313376
@@ -342,6 +405,8 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
342405 [ InlineData ( nameof ( FilterableResource . SomeNullableDateTime ) ) ]
343406 [ InlineData ( nameof ( FilterableResource . SomeNullableDateTimeOffset ) ) ]
344407 [ InlineData ( nameof ( FilterableResource . SomeNullableTimeSpan ) ) ]
408+ [ InlineData ( nameof ( FilterableResource . SomeNullableDateOnly ) ) ]
409+ [ InlineData ( nameof ( FilterableResource . SomeNullableTimeOnly ) ) ]
345410 [ InlineData ( nameof ( FilterableResource . SomeNullableEnum ) ) ]
346411 public async Task Can_filter_is_not_null_on_type ( string propertyName )
347412 {
@@ -358,6 +423,8 @@ public async Task Can_filter_is_not_null_on_type(string propertyName)
358423 SomeNullableDateTime = 1 . January ( 2001 ) . AsUtc ( ) ,
359424 SomeNullableDateTimeOffset = 1 . January ( 2001 ) . AsUtc ( ) ,
360425 SomeNullableTimeSpan = TimeSpan . FromHours ( 1 ) ,
426+ SomeNullableDateOnly = DateOnly . FromDateTime ( 1 . January ( 2001 ) ) ,
427+ SomeNullableTimeOnly = new TimeOnly ( 1 , 0 ) ,
361428 SomeNullableEnum = DayOfWeek . Friday
362429 } ;
363430
0 commit comments