QueryKit icon indicating copy to clipboard operation
QueryKit copied to clipboard

Add nested collection support

Open pdevito3 opened this issue 2 years ago • 0 comments

ex:

    [Fact]
    public async Task can_filter_by_string_for_nested_collection()
    {
        // Arrange
        var testingServiceScope = new TestingServiceScope();
        var faker = new Faker();
        var fakePreparationOne = new IngredientPreparation()
        {
            Text = faker.Lorem.Sentence()
        };
        var fakeIngredientOne = new FakeIngredientBuilder()
            .Build();
        fakeIngredientOne.AddPreparation(fakePreparationOne);
        var fakeRecipeOne = new FakeRecipeBuilder().Build();
        fakeRecipeOne.AddIngredient(fakeIngredientOne);
        
        var fakeIngredientTwo = new FakeIngredientBuilder()
            .WithName(faker.Lorem.Sentence())
            .Build();
        var fakeRecipeTwo = new FakeRecipeBuilder().Build();
        fakeRecipeTwo.AddIngredient(fakeIngredientTwo);
        await testingServiceScope.InsertAsync(fakeRecipeOne, fakeRecipeTwo);
        
        var input = $"""Ingredients.Preparations.Text == "{fakePreparationOne.Text}" """;

        // Act
        var queryableRecipes = testingServiceScope.DbContext().Recipes;
        var appliedQueryable = queryableRecipes.ApplyQueryKitFilter(input);
        // var appliedQueryable = queryableRecipes.Where(x => x.Ingredients.SelectMany(y => y.Preparations).Select(y => y.Text).Any(z => (z == fakePreparationOne.Text)));
        var recipes = await appliedQueryable.ToListAsync();

        // Assert
        recipes.Count.Should().Be(1);
        recipes[0].Id.Should().Be(fakeRecipeOne.Id);
    }

pdevito3 avatar Jul 24 '23 03:07 pdevito3