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

Fix FreeText tests #21922

Merged
1 commit merged into from
Aug 3, 2020
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void FreeText_throws_for_no_FullText_index()
() => context.Employees.Where(c => EF.Functions.FreeText(c.FirstName, "Fred")).ToArray());
}

[ConditionalFact(Skip = "Issue #18199")]
[ConditionalFact]
[SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)]
public void FreeText_through_navigation()
{
Expand All @@ -204,18 +204,20 @@ public void FreeText_through_navigation()
c => EF.Functions.FreeText(c.Manager.Title, "President")
&& EF.Functions.FreeText(c.Title, "Inside")
&& c.FirstName.Contains("Lau"))
.OrderBy(e => e.EmployeeID)
.LastOrDefault();

Assert.Equal(8u, result.EmployeeID);

AssertSql(
@"SELECT [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title]
@"SELECT TOP(1) [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title]
FROM [Employees] AS [e]
LEFT JOIN [Employees] AS [c.Manager] ON [e].[ReportsTo] = [c.Manager].[EmployeeID]
WHERE ((FREETEXT([c.Manager].[Title], N'President')) AND (FREETEXT([e].[Title], N'Inside'))) AND (CHARINDEX(N'Lau', [e].[FirstName]) > 0)");
LEFT JOIN [Employees] AS [e0] ON [e].[ReportsTo] = [e0].[EmployeeID]
WHERE (FREETEXT([e0].[Title], N'President') AND FREETEXT([e].[Title], N'Inside')) AND ([e].[FirstName] LIKE N'%Lau%')
ORDER BY [e].[EmployeeID] DESC");
}

[ConditionalFact(Skip = "Issue #18199")]
[ConditionalFact]
[SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)]
public void FreeText_through_navigation_with_language_terms()
{
Expand All @@ -225,15 +227,15 @@ public void FreeText_through_navigation_with_language_terms()
c => EF.Functions.FreeText(c.Manager.Title, "President", 1033)
&& EF.Functions.FreeText(c.Title, "Inside", 1031)
&& c.FirstName.Contains("Lau"))
.LastOrDefault();
.FirstOrDefault();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reckon there is only one matching row in the table, but perhaps we should add orderby instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the operator irrelevant here?
What we are testing is translate of FreeText function. So I just added a mix rather than using LastOrDefault everywhere.


Assert.Equal(8u, result.EmployeeID);

AssertSql(
@"SELECT [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title]
@"SELECT TOP(1) [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title]
FROM [Employees] AS [e]
LEFT JOIN [Employees] AS [c.Manager] ON [e].[ReportsTo] = [c.Manager].[EmployeeID]
WHERE ((FREETEXT([c.Manager].[Title], N'President', LANGUAGE 1033)) AND (FREETEXT([e].[Title], N'Inside', LANGUAGE 1031))) AND (CHARINDEX(N'Lau', [e].[FirstName]) > 0)");
LEFT JOIN [Employees] AS [e0] ON [e].[ReportsTo] = [e0].[EmployeeID]
WHERE (FREETEXT([e0].[Title], N'President', LANGUAGE 1033) AND FREETEXT([e].[Title], N'Inside', LANGUAGE 1031)) AND ([e].[FirstName] LIKE N'%Lau%')");
}

[ConditionalFact]
Expand Down Expand Up @@ -414,7 +416,7 @@ FROM [Employees] AS [e]
WHERE CONTAINS([e].[Title], N'NEAR((Sales, President), 1)', LANGUAGE 1033)");
}

[ConditionalFact(Skip = "Issue #18199")]
[ConditionalFact]
[SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)]
public void Contains_through_navigation()
{
Expand All @@ -423,16 +425,16 @@ public void Contains_through_navigation()
.Where(
c => EF.Functions.Contains(c.Manager.Title, "President")
&& EF.Functions.Contains(c.Title, "\"Ins*\""))
.LastOrDefault();
.FirstOrDefault();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Assert.NotNull(result);
Assert.Equal(8u, result.EmployeeID);

AssertSql(
@"SELECT [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title]
@"SELECT TOP(1) [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title]
FROM [Employees] AS [e]
LEFT JOIN [Employees] AS [c.Manager] ON [e].[ReportsTo] = [c.Manager].[EmployeeID]
WHERE (CONTAINS([c.Manager].[Title], N'President')) AND (CONTAINS([e].[Title], N'""Ins*""'))");
LEFT JOIN [Employees] AS [e0] ON [e].[ReportsTo] = [e0].[EmployeeID]
WHERE CONTAINS([e0].[Title], N'President') AND CONTAINS([e].[Title], N'""Ins*""')");
}

[ConditionalTheory]
Expand Down