Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions QueryKit.IntegrationTests/Tests/PropertyResolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace QueryKit.IntegrationTests.Tests;
using FluentAssertions;
using Microsoft.EntityFrameworkCore;
using SharedTestingHelper.Fakes;
using SharedTestingHelper.Fakes.Author;
using SharedTestingHelper.Fakes.Recipes;
using WebApiTestProject.Entities;

public class PropertyResolverTests : TestBase
Expand Down Expand Up @@ -151,6 +153,33 @@ public async Task property_is_not_prevented_by_another_property_whose_query_name
people[0].Id.Should().Be(fakePerson.Id);
}

[Fact]
public async Task property_path_on_the_right_side_is_compared()
{
// Arrange
var testingServiceScope = new TestingServiceScope();
var name = Guid.NewGuid().ToString();
var matchingRecipe = new FakeRecipeBuilder()
.WithTitle(name)
.Build();
matchingRecipe.SetAuthor(new FakeAuthorBuilder().WithName(name).Build());
var otherRecipe = new FakeRecipeBuilder()
.WithTitle(name)
.Build();
otherRecipe.SetAuthor(new FakeAuthorBuilder().WithName(Guid.NewGuid().ToString()).Build());
await testingServiceScope.InsertAsync(matchingRecipe, otherRecipe);

var input = $"""Title == "{name}" && Title == Author.Name""";

// Act
var recipes = await testingServiceScope.DbContext().Recipes
.ApplyQueryKitFilter(input)
.ToListAsync();

// Assert
recipes.Should().ContainSingle(x => x.Id == matchingRecipe.Id);
}

[Theory]
[InlineData("first-name")]
[InlineData("_first")]
Expand Down
18 changes: 3 additions & 15 deletions QueryKit.UnitTests/PropertyResolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -688,25 +688,13 @@ public void alias_replacement_replaces_a_query_name_in_a_nested_path()
}

[Fact]
public void property_path_on_the_right_side_throws()
public void property_path_on_the_right_side_is_compared()
{
var input = """Title == Author.Name""";

var act = () => FilterParser.ParseFilter<Recipe>(input);
var filterExpression = FilterParser.ParseFilter<Recipe>(input);

act.Should().Throw<ParsingException>()
.WithInnerException<InvalidOperationException>()
.WithMessage("*Equal is not defined for the types 'System.String' and*Author*");
}

[Fact]
public void unquoted_dotted_word_on_the_right_side_throws()
{
var input = """Title == foo.bar""";

var act = () => FilterParser.ParseFilter<Recipe>(input);

act.Should().Throw<ParsingException>().WithMessage("*Line 1, Column 13*");
filterExpression.ToDisplayString().Should().Be("x => (x.Title == x.Author.Name)");
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion QueryKit/FilterParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ from closingBracket in Parse.Char(']')
.XOr(NumberParser.Select(v => new RightSideValue(v, false, CultureNumberPrefix(v))))
.XOr((RawStringLiteralParser.Or(DoubleQuoteParser)).Select(v => new RightSideValue(v, true)))
.XOr(SquareBracketParser)
.XOr(Identifier.Select(v => new RightSideValue(v, false))); // Keep this last to try property paths only if nothing else matches
.XOr(Identifier.DelimitedBy(Parse.Char('.')).Select(v => new RightSideValue(string.Join(".", v), false))); // Keep this last to try property paths only if nothing else matches

private static readonly Parser<RightSideValue> RightSideValueParser =
from atSign in Parse.Char('@').Optional()
Expand Down
Loading