From da832656ac7e8cc0caf7d4234e3bdfabf1b5ba4d Mon Sep 17 00:00:00 2001 From: Jamess-Lucass <23193271+Jamess-Lucass@users.noreply.github.com> Date: Mon, 4 Nov 2024 22:32:56 +0000 Subject: [PATCH] made contains case insensitive --- src/GoatQuery/src/Evaluator/FilterEvaluator.cs | 4 ++-- src/GoatQuery/tests/Filter/FilterTest.cs | 4 ++-- src/GoatQuery/tests/Top/TopTest.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/GoatQuery/src/Evaluator/FilterEvaluator.cs b/src/GoatQuery/src/Evaluator/FilterEvaluator.cs index e9df1b4..45d2b20 100644 --- a/src/GoatQuery/src/Evaluator/FilterEvaluator.cs +++ b/src/GoatQuery/src/Evaluator/FilterEvaluator.cs @@ -64,9 +64,9 @@ public static Result Evaluate(QueryExpression expression, ParameterE case Keywords.Contains: var identifier = (Identifier)exp.Left; - var method = identifier.Value.GetType().GetMethod("Contains", new[] { value?.Value.GetType() }); + var method = identifier.Value.GetType().GetMethod("Contains", new[] { value?.Value.GetType(), typeof(StringComparison) }); - return Expression.Call(property, method, value); + return Expression.Call(property, method, value, Expression.Constant(StringComparison.OrdinalIgnoreCase)); case Keywords.Lt: return Expression.LessThan(property, value); case Keywords.Lte: diff --git a/src/GoatQuery/tests/Filter/FilterTest.cs b/src/GoatQuery/tests/Filter/FilterTest.cs index 8e48b84..3380f56 100644 --- a/src/GoatQuery/tests/Filter/FilterTest.cs +++ b/src/GoatQuery/tests/Filter/FilterTest.cs @@ -61,12 +61,12 @@ public static IEnumerable Parameters() yield return new object[] { "firstName contains 'a'", - new[] { _users["Jane"], _users["Harry"] } + new[] { _users["Jane"], _users["Apple"], _users["Harry"] } }; yield return new object[] { "Age ne 1 and firstName contains 'a'", - Array.Empty() + new[] { _users["Apple"] } }; yield return new object[] { diff --git a/src/GoatQuery/tests/Top/TopTest.cs b/src/GoatQuery/tests/Top/TopTest.cs index 30a7368..eaa5f9b 100644 --- a/src/GoatQuery/tests/Top/TopTest.cs +++ b/src/GoatQuery/tests/Top/TopTest.cs @@ -70,7 +70,7 @@ public void Test_TopWithMaxTop(int top, int expectedCount) [InlineData(5)] [InlineData(100)] [InlineData(100_000)] - public void Test_TopWithMaxTopThrowsException(int top) + public void Test_TopWithMaxTopReturnsError(int top) { var users = new List{ new User { Age = 1, Firstname = "Jane" },