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
19 changes: 19 additions & 0 deletions QueryKit.IntegrationTests/Tests/FilterParsingRegressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace QueryKit.IntegrationTests.Tests;
using System.Globalization;
using System.Linq.Expressions;
using Configuration;
using Exceptions;
using FluentAssertions;
using Microsoft.EntityFrameworkCore;
using Operators;
Expand Down Expand Up @@ -324,4 +325,22 @@ public async Task has_returns_matching_rows(string input, string[] expectedTitle
// Assert
recipes.Select(x => x.Title[prefix.Length..]).Should().BeEquivalentTo(expectedTitles);
}

[Theory]
[InlineData("""Age == "abc" """)]
[InlineData("""Age == abc""")]
[InlineData("""Rating > "abc" """)]
[InlineData("""Rating > abc""")]
public async Task invalid_value_throws_parsing_exception(string input)
{
// Arrange
var testingServiceScope = new TestingServiceScope();

// Act
var queryablePeople = testingServiceScope.DbContext().People;
var act = async () => await queryablePeople.ApplyQueryKitFilter(input).ToListAsync();

// Assert
await act.Should().ThrowAsync<ParsingException>();
}
}
4 changes: 2 additions & 2 deletions QueryKit.UnitTests/DotNumberCultureTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public void dot_number_on_an_integer_property_throws_parsing_exception(string cu
[InlineData("de-DE", "Rating ^^ [\"4.0\"]")]
[InlineData("de-DE", "Rating > @4.4")]
[InlineData("de-DE", "HaveMadeItMyself == 4.4")]
public void number_that_v1_14_2_also_converted_throws_format_exception(string cultureName, string input)
public void number_that_v1_14_2_also_converted_throws_parsing_exception(string cultureName, string input)
{
var act = () => WithCulture(cultureName, () => FilterParser.ParseFilter<Recipe>(input));

act.Should().ThrowExactly<FormatException>();
act.Should().ThrowExactly<ParsingException>().WithInnerExceptionExactly<FormatException>();
}

[Fact]
Expand Down
17 changes: 17 additions & 0 deletions QueryKit.UnitTests/FilterParsingRegressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,23 @@ public void whitespace_around_a_group_gives_the_same_filter(string input, string
result.Should().Equal(expectedResult);
}

[Theory]
[InlineData("""Age == "abc" """)]
[InlineData("""Age == abc""")]
[InlineData("""Rating > "abc" """)]
[InlineData("""Rating > abc""")]
[InlineData("""Age == 99999999999""")]
[InlineData("""Id == "abc" """)]
[InlineData("""SpecificDateTime == "abc" """)]
[InlineData("""Favorite == "abc" """)]
[InlineData("""Age ^^ ["abc"]""")]
public void invalid_value_throws_parsing_exception(string input)
{
var act = () => FilterParser.ParseFilter<TestingPerson>(input);

act.Should().Throw<ParsingException>();
}

private static TResult WithCulture<TResult>(string cultureName, Func<TResult> action)
{
var originalCulture = CultureInfo.CurrentCulture;
Expand Down
4 changes: 2 additions & 2 deletions QueryKit.UnitTests/QueryNameOverUnknownTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{
private static readonly QueryKitConfiguration Config = new(config =>
{
config.DerivedProperty<TestingPerson>(x => x.Age * 2).HasQueryName("double age");

Check warning on line 15 in QueryKit.UnitTests/QueryNameOverUnknownTests.cs

View workflow job for this annotation

GitHub Actions / test

Possible null reference return.

Check warning on line 15 in QueryKit.UnitTests/QueryNameOverUnknownTests.cs

View workflow job for this annotation

GitHub Actions / test

Possible null reference return.

Check warning on line 15 in QueryKit.UnitTests/QueryNameOverUnknownTests.cs

View workflow job for this annotation

GitHub Actions / test

Possible null reference return.

Check warning on line 15 in QueryKit.UnitTests/QueryNameOverUnknownTests.cs

View workflow job for this annotation

GitHub Actions / test

Possible null reference return.
config.DerivedProperty<TestingPerson>(x => x.FirstName + " " + x.LastName).HasQueryName("full-name");
config.CustomOperation<TestingPerson>((x, op, value) => x.Age > 17).HasQueryName("is adult");
});
Expand Down Expand Up @@ -43,11 +43,11 @@
}

[Fact]
public void failure_before_the_query_name_throws_its_own_format_exception()
public void failure_before_the_query_name_throws_its_own_parsing_exception()
{
var act = () => FilterParser.ParseFilter<TestingPerson>("""Age > "x" && is adult == true""", Config);

act.Should().ThrowExactly<FormatException>();
act.Should().ThrowExactly<ParsingException>().WithInnerExceptionExactly<FormatException>();
}

[Fact]
Expand Down
8 changes: 8 additions & 0 deletions QueryKit/FilterParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ public static Expression<Func<T, bool>> ParseFilter<T>(string input, IQueryKitCo
{
throw new ParsingException(e);
}
catch (FormatException e)
{
throw new ParsingException(e);
}
catch (OverflowException e)
{
throw new ParsingException(e);
}
finally
{
FilterValue.Parameterize = parameterizeBefore;
Expand Down
Loading