Skip to content

Commit 7e9ea21

Browse files
committed
refactor: more tests
1 parent 2f73d59 commit 7e9ea21

File tree

1 file changed

+57
-8
lines changed

1 file changed

+57
-8
lines changed

QueryKit.IntegrationTests/Tests/DatabaseFilteringTests.cs

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,12 +1286,12 @@ public async Task can_filter_with_child_props_for_complex_property()
12861286
var input = $"""CollectionEmail.Value == "{fakePersonOne.CollectionEmail.Value}" """;
12871287

12881288
// Act
1289-
var queryablePeople = testingServiceScope.DbContext().Recipes;
1289+
var queryableRecipes = testingServiceScope.DbContext().Recipes;
12901290
var config = new QueryKitConfiguration(config =>
12911291
{
12921292
config.Property<Recipe>(x => x.CollectionEmail.Value);
12931293
});
1294-
var appliedQueryable = queryablePeople.ApplyQueryKitFilter(input, config);
1294+
var appliedQueryable = queryableRecipes.ApplyQueryKitFilter(input, config);
12951295
var people = await appliedQueryable.ToListAsync();
12961296

12971297
// Assert
@@ -1315,12 +1315,12 @@ public async Task can_filter_with_child_props_for_aliased_complex_property()
13151315
var input = $"""email == "{fakePersonOne.CollectionEmail.Value}" """;
13161316

13171317
// Act
1318-
var queryablePeople = testingServiceScope.DbContext().Recipes;
1318+
var queryableRecipes = testingServiceScope.DbContext().Recipes;
13191319
var config = new QueryKitConfiguration(config =>
13201320
{
13211321
config.Property<Recipe>(x => x.CollectionEmail.Value).HasQueryName("email");
13221322
});
1323-
var appliedQueryable = queryablePeople.ApplyQueryKitFilter(input, config);
1323+
var appliedQueryable = queryableRecipes.ApplyQueryKitFilter(input, config);
13241324
var people = await appliedQueryable.ToListAsync();
13251325

13261326
// Assert
@@ -1344,12 +1344,12 @@ public async Task can_filter_with_child_props_for_null_aliased_complex_property(
13441344
var input = $"""email == null""";
13451345

13461346
// Act
1347-
var queryablePeople = testingServiceScope.DbContext().Recipes;
1347+
var queryableRecipes = testingServiceScope.DbContext().Recipes;
13481348
var config = new QueryKitConfiguration(config =>
13491349
{
13501350
config.Property<Recipe>(x => x.CollectionEmail.Value).HasQueryName("email");
13511351
});
1352-
var appliedQueryable = queryablePeople.ApplyQueryKitFilter(input, config);
1352+
var appliedQueryable = queryableRecipes.ApplyQueryKitFilter(input, config);
13531353
var people = await appliedQueryable.ToListAsync();
13541354

13551355
// Assert
@@ -1373,12 +1373,12 @@ public async Task can_filter_with_child_props_for_complex_property_with_alias()
13731373
var input = $"""email == "{fakePersonOne.CollectionEmail.Value}" """;
13741374

13751375
// Act
1376-
var queryablePeople = testingServiceScope.DbContext().Recipes;
1376+
var queryableRecipes = testingServiceScope.DbContext().Recipes;
13771377
var config = new QueryKitConfiguration(config =>
13781378
{
13791379
config.Property<Recipe>(x => x.CollectionEmail.Value).HasQueryName("email");
13801380
});
1381-
var appliedQueryable = queryablePeople.ApplyQueryKitFilter(input, config);
1381+
var appliedQueryable = queryableRecipes.ApplyQueryKitFilter(input, config);
13821382
var people = await appliedQueryable.ToListAsync();
13831383

13841384
// Assert
@@ -1485,4 +1485,53 @@ public async Task can_filter_by_in_enum_numbers()
14851485
people.Count.Should().Be(1);
14861486
people[0].Id.Should().Be(fakePersonOne.Id);
14871487
}
1488+
1489+
[Fact]
1490+
public async Task can_have_derived_prop_work_with_collection_filters()
1491+
{
1492+
// Arrange
1493+
var testingServiceScope = new TestingServiceScope();
1494+
var ingredient = new FakeIngredientBuilder().Build();
1495+
var recipe = new FakeRecipeBuilder().Build();
1496+
recipe.AddIngredient(ingredient);
1497+
await testingServiceScope.InsertAsync(recipe);
1498+
1499+
var input = $"""special_title_directions == "{recipe.Title + recipe.Directions}" && Ingredients.Name == "{ingredient.Name}" """;
1500+
var config = new QueryKitConfiguration(config =>
1501+
{
1502+
config.DerivedProperty<Recipe>(x => x.Title + x.Directions).HasQueryName("special_title_directions");
1503+
});
1504+
var queryableRecipes = testingServiceScope.DbContext().Recipes;
1505+
var appliedQueryable = queryableRecipes.ApplyQueryKitFilter(input, config);
1506+
var recipes = await appliedQueryable.ToListAsync();
1507+
1508+
// Assert
1509+
recipes.Count.Should().Be(1);
1510+
recipes[0].Id.Should().Be(recipe.Id);
1511+
}
1512+
1513+
1514+
[Fact]
1515+
public async Task can_have_custom_prop_work_with_collection_filters()
1516+
{
1517+
// Arrange
1518+
var testingServiceScope = new TestingServiceScope();
1519+
var ingredient = new FakeIngredientBuilder().Build();
1520+
var recipe = new FakeRecipeBuilder().Build();
1521+
recipe.AddIngredient(ingredient);
1522+
await testingServiceScope.InsertAsync(recipe);
1523+
1524+
var input = $"""special_title == "{recipe.Title}" && Ingredients.Name == "{ingredient.Name}" """;
1525+
var config = new QueryKitConfiguration(config =>
1526+
{
1527+
config.Property<Recipe>(x => x.Title).HasQueryName("special_title");
1528+
});
1529+
var queryableRecipes = testingServiceScope.DbContext().Recipes;
1530+
var appliedQueryable = queryableRecipes.ApplyQueryKitFilter(input, config);
1531+
var recipes = await appliedQueryable.ToListAsync();
1532+
1533+
// Assert
1534+
recipes.Count.Should().Be(1);
1535+
recipes[0].Id.Should().Be(recipe.Id);
1536+
}
14881537
}

0 commit comments

Comments
 (0)