Skip to content

Commit ddf8a50

Browse files
committed
Merge branch 'develop'
2 parents 49dc69a + 453027b commit ddf8a50

3 files changed

Lines changed: 33 additions & 2 deletions

File tree

QueryKit.IntegrationTests/Tests/DatabaseFilteringTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,37 @@ public async Task can_filter_by_string_for_collection()
7171
recipes[0].Id.Should().Be(fakeRecipeOne.Id);
7272
}
7373

74+
[Fact]
75+
public async Task can_filter_by_numeric_string_for_collection()
76+
{
77+
// Arrange
78+
var testingServiceScope = new TestingServiceScope();
79+
var faker = new Faker();
80+
var fakeIngredientOne = new FakeIngredientBuilder()
81+
.WithName("abc123")
82+
.Build();
83+
var fakeRecipeOne = new FakeRecipeBuilder().Build();
84+
fakeRecipeOne.AddIngredient(fakeIngredientOne);
85+
86+
var fakeIngredientTwo = new FakeIngredientBuilder()
87+
.WithName(faker.Lorem.Sentence())
88+
.Build();
89+
var fakeRecipeTwo = new FakeRecipeBuilder().Build();
90+
fakeRecipeTwo.AddIngredient(fakeIngredientTwo);
91+
await testingServiceScope.InsertAsync(fakeRecipeOne, fakeRecipeTwo);
92+
93+
var input = $"""Ingredients.Name @=* "123" """;
94+
95+
// Act
96+
var queryableRecipes = testingServiceScope.DbContext().Recipes;
97+
var appliedQueryable = queryableRecipes.ApplyQueryKitFilter(input);
98+
var recipes = await appliedQueryable.ToListAsync();
99+
100+
// Assert
101+
recipes.Count.Should().Be(1);
102+
recipes[0].Id.Should().Be(fakeRecipeOne.Id);
103+
}
104+
74105
[Fact]
75106
public async Task can_filter_by_string_for_collection_with_count()
76107
{

QueryKit/FilterParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private static Expression CreateRightExprFromType(Type leftExprType, string righ
171171
var targetType = leftExprType;
172172
if (isEnumerable)
173173
{
174-
if (int.TryParse(right, out var intVal))
174+
if (int.TryParse(right, out var intVal) && targetType.GetGenericArguments().All(arg => arg != typeof(string)))
175175
{
176176
// supports collection count
177177
return Expression.Constant(intVal, typeof(int));

QueryKit/QueryKit.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Nullable>enable</Nullable>
77
<PackageId>QueryKit</PackageId>
88
<PackageTags>QueryKit;Fitler;Filtering;Sort;Sorting</PackageTags>
9-
<Version>0.6.0</Version>
9+
<Version>0.6.1</Version>
1010
<Authors>Paul DeVito</Authors>
1111
<Summary>QueryKit is a .NET library that makes it easier to query your data by providing a fluent and intuitive syntax for filtering and sorting.</Summary>
1212
<Description>QueryKit is a .NET library that makes it easier to query your data by providing a fluent and intuitive syntax for filtering and sorting.</Description>

0 commit comments

Comments
 (0)