Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ejsmith committed Oct 21, 2024
1 parent 0a1fcc3 commit e36255a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public static string ToDynamicLinqString(this TermNode node, ISqlQueryVisitorCon
searchTerm = new SearchTerm
{
FieldInfo = fieldInfo,
Tokens = [node.Term],
Term = node.Term,
Operator = SqlSearchOperator.StartsWith
};
fieldTerms[fieldInfo] = searchTerm;
Expand Down
15 changes: 12 additions & 3 deletions tests/Foundatio.Parsers.SqlQueries.Tests/SqlQueryParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ public async Task CanSearchDefaultFields()

var context = parser.GetContext(db.Employees.EntityType);

string sqlExpected = db.Employees.Where(e => e.FullName == "John Doe" || e.Title == "John Doe").ToQueryString();
string sqlActual = db.Employees.Where("""FullName = "John Doe" || Title = "John Doe" """).ToQueryString();
string sqlExpected = db.Employees.Where(e => e.FullName.StartsWith("John") || e.Title.StartsWith("John")).ToQueryString();
string sqlActual = db.Employees.Where("""FullName.StartsWith("John") || Title.StartsWith("John") """).ToQueryString();
Assert.Equal(sqlExpected, sqlActual);
string sql = await parser.ToDynamicLinqAsync("John Doe", context);
string sql = await parser.ToDynamicLinqAsync("John", context);
sqlActual = db.Employees.Where(sql).ToQueryString();
var results = await db.Employees.Where(sql).ToListAsync();
Assert.Single(results);
Expand All @@ -90,6 +90,9 @@ public async Task CanSearchWithTokenizer()
parser.Configuration.SetDefaultFields(["NationalPhoneNumber"]);
parser.Configuration.SetSearchTokenizer(s =>
{
if (String.IsNullOrWhiteSpace(s.Term))
return;

if (s.FieldInfo.Field != "NationalPhoneNumber")
return;

Expand All @@ -116,6 +119,12 @@ public async Task CanSearchWithTokenizer()
results = await db.Employees.Where(sql).ToListAsync();
Assert.Single(results);
Assert.Equal(sqlExpected, sqlActual);

sql = await parser.ToDynamicLinqAsync("21422", context);
_logger.LogInformation(sql);
sqlActual = db.Employees.Where(sql).ToQueryString();
results = await db.Employees.Where(sql).ToListAsync();
Assert.Single(results);
}

[Fact]
Expand Down

0 comments on commit e36255a

Please sign in to comment.