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

Query: Add regression test for #12355 #19197

Merged
merged 2 commits into from
Dec 6, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -3976,6 +3976,12 @@ public override Task SelectMany_correlated_subquery_hard(bool async)
return base.SelectMany_correlated_subquery_hard(async);
}

[ConditionalTheory(Skip = "Issue #17246")]
public override Task Subquery_DefaultIfEmpty_Any(bool async)
{
return base.Subquery_DefaultIfEmpty_Any(async);
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.TestUtilities;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.EntityFrameworkCore.Query
Expand All @@ -16,5 +18,11 @@ public NorthwindGroupByQueryInMemoryTest(
{
//TestLoggerFactory.TestOutputHelper = testOutputHelper;
}

[ConditionalTheory(Skip = "Issue#17536")]
public override Task Join_GroupBy_Aggregate_with_left_join(bool async)
{
return base.Join_GroupBy_Aggregate_with_left_join(async);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1745,6 +1745,42 @@ from g in grouping
entryCount: 63);
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Join_GroupBy_Aggregate_with_left_join(bool async)
{
return AssertQuery(
async,
ss =>
from c in ss.Set<Customer>().Where(c => c.CustomerID.StartsWith("A"))
join a in ss.Set<Order>().GroupBy(o => o.CustomerID)
.Where(g => g.Count() > 5)
.Select(
g => new { CustomerID = g.Key, LastOrderID = g.Max(o => o.OrderID) })
on c.CustomerID equals a.CustomerID into grouping
from g in grouping.DefaultIfEmpty()
select new
{
c,
LastOrderID = (int?)g.LastOrderID
},
ss =>
from c in ss.Set<Customer>().Where(c => c.CustomerID.StartsWith("A"))
join a in ss.Set<Order>().GroupBy(o => o.CustomerID)
.Where(g => g.Count() > 5)
.Select(
g => new { CustomerID = g.Key, LastOrderID = g.Max(o => o.OrderID) })
on c.CustomerID equals a.CustomerID into grouping
from g in grouping.DefaultIfEmpty()
select new
{
c,
LastOrderID = g != null ? g.LastOrderID : (int?)null
},
elementSorter: r => r.c.CustomerID,
entryCount: 4);
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Join_GroupBy_Aggregate_in_subquery(bool async)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5463,5 +5463,18 @@ public virtual Task AsQueryable_in_query_server_evals(bool async)
}

private static Expression<Func<Order, bool>> ValidYear => a => a.OrderDate.Value.Year == 1998;

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Subquery_DefaultIfEmpty_Any(bool async)
{
return AssertAny(
async,
ss => (from e in ss.Set<Employee>()
.Where(e => e.EmployeeID == NonExistentID)
.Select(e => e.EmployeeID)
.DefaultIfEmpty()
select e));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,22 @@ HAVING COUNT(*) > 5
INNER JOIN [Orders] AS [o0] ON [c].[CustomerID] = [o0].[CustomerID]");
}

public override async Task Join_GroupBy_Aggregate_with_left_join(bool async)
{
await base.Join_GroupBy_Aggregate_with_left_join(async);

AssertSql(
@"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region], [t].[c] AS [LastOrderID]
FROM [Customers] AS [c]
LEFT JOIN (
SELECT [o].[CustomerID], MAX([o].[OrderID]) AS [c]
FROM [Orders] AS [o]
GROUP BY [o].[CustomerID]
HAVING COUNT(*) > 5
) AS [t] ON [c].[CustomerID] = [t].[CustomerID]
WHERE [c].[CustomerID] LIKE N'A%'");
}

public override async Task Join_GroupBy_Aggregate_in_subquery(bool async)
{
await base.Join_GroupBy_Aggregate_in_subquery(async);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4691,6 +4691,26 @@ ORDER BY [o].[OrderID]
ORDER BY [c].[CustomerID], [t].[OrderID]");
}

public override async Task Subquery_DefaultIfEmpty_Any(bool async)
{
await base.Subquery_DefaultIfEmpty_Any(async);

AssertSql(
@"SELECT CASE
WHEN EXISTS (
SELECT 1
FROM (
SELECT NULL AS [empty]
) AS [empty]
LEFT JOIN (
SELECT [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title]
FROM [Employees] AS [e]
WHERE [e].[EmployeeID] = -1
) AS [t] ON 1 = 1) THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END");
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down