Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/case insensitivity #44

Merged
merged 4 commits into from
Jan 19, 2024
Merged
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
4 changes: 3 additions & 1 deletion src/Extensions/QueryableExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ public static (IQueryable, int?) Apply<T>(this IQueryable<T> queryable, Query qu
}
else
{
where.Append($"{property} {_filterOperations[operand]} {value}");
where.Append($"{property}.ToLower() {_filterOperations[operand]} {value}.ToLower()");
}
}

Console.WriteLine(where.ToString());

result = result.Where(where.ToString());
}

Expand Down
33 changes: 23 additions & 10 deletions tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,20 @@ public void Test_QueryWithFilterEquals()
var (result, _) = _context.Users.AsQueryable().Apply(query, null);
var sql = result.ToQueryString();

var expectedSql = _context.Users.AsQueryable().Where(x => x.Firstname == "goat").ToQueryString();
var expectedSql = _context.Users.AsQueryable().Where(x => x.Firstname.ToLower() == "goat".ToLower()).ToQueryString();

Assert.Equal(expectedSql, sql);
}

[Fact]
public void Test_QueryWithFilterEqualsCaseInsensitivity()
{
var query = new Query() { Filter = "firstname eq 'goat'" };

var (result, _) = _context.Users.AsQueryable().Apply(query, null);
var sql = result.ToQueryString();

var expectedSql = _context.Users.AsQueryable().Where(x => x.Firstname.ToLower() == "goat".ToLower()).ToQueryString();

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

var expectedSql = _context.Users.AsQueryable().Where(x => x.Firstname != "goat").ToQueryString();
var expectedSql = _context.Users.AsQueryable().Where(x => x.Firstname.ToLower() != "goat".ToLower()).ToQueryString();

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

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

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

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

Assert.Equal(expectedSql, sql);
}
Expand Down Expand Up @@ -287,7 +300,7 @@ public void Test_QueryWithFilterContainsAndEquals()
var sql = result.ToQueryString();

var expectedSql = _context.Users.AsQueryable()
.Where(x => x.Firstname.Contains("goat") && x.Lastname == "query")
.Where(x => x.Firstname.Contains("goat") && x.Lastname.ToLower() == "query".ToLower())
.ToQueryString();

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

var expectedSql = _context.Users.AsQueryable()
.Where(x => x.Firstname.Contains("goat") || x.Lastname == "query")
.Where(x => x.Firstname.Contains("goat") || x.Lastname.ToLower() == "query".ToLower())
.ToQueryString();

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

var expectedSql = _context.Users.AsQueryable()
.Where(x => x.Firstname == "goatand")
.Where(x => x.Firstname.ToLower() == "goatand".ToLower())
.ToQueryString();

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

var expectedSql = _context.Users.AsQueryable()
.Where(x => x.Firstname == " and " || x.Lastname == " and or ")
.Where(x => x.Firstname.ToLower() == " and ".ToLower() || x.Lastname.ToLower() == " and or ".ToLower())
.ToQueryString();

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

var expectedSql = _context.Users.AsQueryable()
.Where(x => x.UserName == "John")
.Where(x => x.UserName.ToLower() == "John".ToLower())
.ToQueryString();

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

var expectedSql = _context.Users.AsQueryable()
.Where(x => x.Gender == "Male")
.Where(x => x.Gender.ToLower() == "Male".ToLower())
.ToQueryString();

Assert.Equal(expectedSql, sql);
Expand Down