Skip to content

Commit de5c810

Browse files
Feat/case insensitivity (#44)
1 parent c753264 commit de5c810

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

src/Extensions/QueryableExtension.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ public static (IQueryable, int?) Apply<T>(this IQueryable<T> queryable, Query qu
6161
}
6262
else
6363
{
64-
where.Append($"{property} {_filterOperations[operand]} {value}");
64+
where.Append($"{property}.ToLower() {_filterOperations[operand]} {value}.ToLower()");
6565
}
6666
}
6767

68+
Console.WriteLine(where.ToString());
69+
6870
result = result.Where(where.ToString());
6971
}
7072

tests/Tests.cs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,20 @@ public void Test_QueryWithFilterEquals()
219219
var (result, _) = _context.Users.AsQueryable().Apply(query, null);
220220
var sql = result.ToQueryString();
221221

222-
var expectedSql = _context.Users.AsQueryable().Where(x => x.Firstname == "goat").ToQueryString();
222+
var expectedSql = _context.Users.AsQueryable().Where(x => x.Firstname.ToLower() == "goat".ToLower()).ToQueryString();
223+
224+
Assert.Equal(expectedSql, sql);
225+
}
226+
227+
[Fact]
228+
public void Test_QueryWithFilterEqualsCaseInsensitivity()
229+
{
230+
var query = new Query() { Filter = "firstname eq 'goat'" };
231+
232+
var (result, _) = _context.Users.AsQueryable().Apply(query, null);
233+
var sql = result.ToQueryString();
234+
235+
var expectedSql = _context.Users.AsQueryable().Where(x => x.Firstname.ToLower() == "goat".ToLower()).ToQueryString();
223236

224237
Assert.Equal(expectedSql, sql);
225238
}
@@ -232,7 +245,7 @@ public void Test_QueryWithFilterNotEquals()
232245
var (result, _) = _context.Users.AsQueryable().Apply(query, null);
233246
var sql = result.ToQueryString();
234247

235-
var expectedSql = _context.Users.AsQueryable().Where(x => x.Firstname != "goat").ToQueryString();
248+
var expectedSql = _context.Users.AsQueryable().Where(x => x.Firstname.ToLower() != "goat".ToLower()).ToQueryString();
236249

237250
Assert.Equal(expectedSql, sql);
238251
}
@@ -245,7 +258,7 @@ public void Test_QueryWithFilterEqualsAndEquals()
245258
var (result, _) = _context.Users.AsQueryable().Apply(query, null);
246259
var sql = result.ToQueryString();
247260

248-
var expectedSql = _context.Users.AsQueryable().Where(x => x.Firstname == "goat" && x.Lastname == "query").ToQueryString();
261+
var expectedSql = _context.Users.AsQueryable().Where(x => x.Firstname.ToLower() == "goat".ToLower() && x.Lastname.ToLower() == "query".ToLower()).ToQueryString();
249262

250263
Assert.Equal(expectedSql, sql);
251264
}
@@ -258,7 +271,7 @@ public void Test_QueryWithFilterEqualsAndNotEquals()
258271
var (result, _) = _context.Users.AsQueryable().Apply(query, null);
259272
var sql = result.ToQueryString();
260273

261-
var expectedSql = _context.Users.AsQueryable().Where(x => x.Firstname == "goat" && x.Lastname != "query").ToQueryString();
274+
var expectedSql = _context.Users.AsQueryable().Where(x => x.Firstname.ToLower() == "goat".ToLower() && x.Lastname.ToLower() != "query".ToLower()).ToQueryString();
262275

263276
Assert.Equal(expectedSql, sql);
264277
}
@@ -287,7 +300,7 @@ public void Test_QueryWithFilterContainsAndEquals()
287300
var sql = result.ToQueryString();
288301

289302
var expectedSql = _context.Users.AsQueryable()
290-
.Where(x => x.Firstname.Contains("goat") && x.Lastname == "query")
303+
.Where(x => x.Firstname.Contains("goat") && x.Lastname.ToLower() == "query".ToLower())
291304
.ToQueryString();
292305

293306
Assert.Equal(expectedSql, sql);
@@ -302,7 +315,7 @@ public void Test_QueryWithFilterContainsOrEquals()
302315
var sql = result.ToQueryString();
303316

304317
var expectedSql = _context.Users.AsQueryable()
305-
.Where(x => x.Firstname.Contains("goat") || x.Lastname == "query")
318+
.Where(x => x.Firstname.Contains("goat") || x.Lastname.ToLower() == "query".ToLower())
306319
.ToQueryString();
307320

308321
Assert.Equal(expectedSql, sql);
@@ -317,7 +330,7 @@ public void Test_QueryWithFilterEqualsWithConjunction()
317330
var sql = result.ToQueryString();
318331

319332
var expectedSql = _context.Users.AsQueryable()
320-
.Where(x => x.Firstname == "goatand")
333+
.Where(x => x.Firstname.ToLower() == "goatand".ToLower())
321334
.ToQueryString();
322335

323336
Assert.Equal(expectedSql, sql);
@@ -332,7 +345,7 @@ public void Test_QueryWithFilterEqualsWithConjunctionAndSpaces()
332345
var sql = result.ToQueryString();
333346

334347
var expectedSql = _context.Users.AsQueryable()
335-
.Where(x => x.Firstname == " and " || x.Lastname == " and or ")
348+
.Where(x => x.Firstname.ToLower() == " and ".ToLower() || x.Lastname.ToLower() == " and or ".ToLower())
336349
.ToQueryString();
337350

338351
Assert.Equal(expectedSql, sql);
@@ -347,7 +360,7 @@ public void Test_QueryWithFilterCustomJsonPropertyName()
347360
var sql = result.ToQueryString();
348361

349362
var expectedSql = _context.Users.AsQueryable()
350-
.Where(x => x.UserName == "John")
363+
.Where(x => x.UserName.ToLower() == "John".ToLower())
351364
.ToQueryString();
352365

353366
Assert.Equal(expectedSql, sql);
@@ -362,7 +375,7 @@ public void Test_QueryWithFilterCustomColumnName()
362375
var sql = result.ToQueryString();
363376

364377
var expectedSql = _context.Users.AsQueryable()
365-
.Where(x => x.Gender == "Male")
378+
.Where(x => x.Gender.ToLower() == "Male".ToLower())
366379
.ToQueryString();
367380

368381
Assert.Equal(expectedSql, sql);

0 commit comments

Comments
 (0)