@@ -5,7 +5,10 @@ namespace QueryKit.IntegrationTests.Tests;
55using FluentAssertions ;
66using Microsoft . EntityFrameworkCore ;
77using SharedTestingHelper . Fakes ;
8+ using SharedTestingHelper . Fakes . Author ;
9+ using SharedTestingHelper . Fakes . Recipes ;
810using WebApiTestProject . Entities ;
11+ using WebApiTestProject . Entities . Recipes ;
912using WebApiTestProject . Features ;
1013
1114public class DatabaseFilteringTests : TestBase
@@ -341,4 +344,65 @@ public async Task can_handle_case_sensitive_in_for_string()
341344 // Assert
342345 people . FirstOrDefault ( x => x . Id == fakePersonOne . Id ) . Should ( ) . BeNull ( ) ;
343346 }
347+
348+ [ Fact ]
349+ public async Task can_filter_on_child_entity ( )
350+ {
351+ // Arrange
352+ var testingServiceScope = new TestingServiceScope ( ) ;
353+ var fakeAuthorOne = new FakeAuthorBuilder ( ) . Build ( ) ;
354+ var fakeRecipeOne = new FakeRecipeBuilder ( ) . Build ( ) ;
355+ fakeRecipeOne . SetAuthor ( fakeAuthorOne ) ;
356+
357+ var fakeAuthorTwo = new FakeAuthorBuilder ( ) . Build ( ) ;
358+ var fakeRecipeTwo = new FakeRecipeBuilder ( ) . Build ( ) ;
359+ fakeRecipeTwo . SetAuthor ( fakeAuthorTwo ) ;
360+ await testingServiceScope . InsertAsync ( fakeRecipeOne , fakeRecipeTwo ) ;
361+
362+ var input = $ """ Author.Name == "{ fakeAuthorOne . Name } " """ ;
363+
364+ // Act
365+ var queryableRecipe = testingServiceScope . DbContext ( ) . Recipes
366+ . Include ( x => x . Author ) ;
367+ var appliedQueryable = queryableRecipe . ApplyQueryKitFilter ( input ) ;
368+ var people = await appliedQueryable . ToListAsync ( ) ;
369+
370+ // Assert
371+ people . Count . Should ( ) . Be ( 1 ) ;
372+ people . FirstOrDefault ( x => x . Id == fakeRecipeOne . Id ) . Should ( ) . NotBeNull ( ) ;
373+ people . FirstOrDefault ( x => x . Id == fakeRecipeTwo . Id ) . Should ( ) . BeNull ( ) ;
374+ }
375+
376+ [ Fact ]
377+ public async Task can_filter_on_child_entity_with_config ( )
378+ {
379+ // Arrange
380+ var testingServiceScope = new TestingServiceScope ( ) ;
381+ var fakeAuthorOne = new FakeAuthorBuilder ( ) . Build ( ) ;
382+ var fakeRecipeOne = new FakeRecipeBuilder ( ) . Build ( ) ;
383+ fakeRecipeOne . SetAuthor ( fakeAuthorOne ) ;
384+
385+ var fakeAuthorTwo = new FakeAuthorBuilder ( ) . Build ( ) ;
386+ var fakeRecipeTwo = new FakeRecipeBuilder ( ) . Build ( ) ;
387+ fakeRecipeTwo . SetAuthor ( fakeAuthorTwo ) ;
388+ await testingServiceScope . InsertAsync ( fakeRecipeOne , fakeRecipeTwo ) ;
389+
390+ var input = $ """ author == "{ fakeAuthorOne . Name } " """ ;
391+
392+ var config = new QueryKitConfiguration ( config =>
393+ {
394+ config . Property < Recipe > ( x => x . Author . Name ) . HasQueryName ( "author" ) ;
395+ } ) ;
396+
397+ // Act
398+ var queryableRecipe = testingServiceScope . DbContext ( ) . Recipes
399+ . Include ( x => x . Author ) ;
400+ var appliedQueryable = queryableRecipe . ApplyQueryKitFilter ( input , config ) ;
401+ var people = await appliedQueryable . ToListAsync ( ) ;
402+
403+ // Assert
404+ people . Count . Should ( ) . Be ( 1 ) ;
405+ people . FirstOrDefault ( x => x . Id == fakeRecipeOne . Id ) . Should ( ) . NotBeNull ( ) ;
406+ people . FirstOrDefault ( x => x . Id == fakeRecipeTwo . Id ) . Should ( ) . BeNull ( ) ;
407+ }
344408}
0 commit comments