Skip to content

Commit

Permalink
Additional testing
Browse files Browse the repository at this point in the history
  • Loading branch information
roji committed Jul 31, 2019
1 parent 71c4e2c commit cbe4ac9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public override void Include_Union_different_includes_throws() {}
public override Task SubSelect_Union(bool isAsync) => Task.CompletedTask;
public override Task Client_eval_Union_FirstOrDefault(bool isAsync) => Task.CompletedTask;
public override Task GroupBy_Select_Union(bool isAsync) => Task.CompletedTask;
public override Task Union_over_different_projection_types(bool isAsync) => Task.CompletedTask;

public override Task Union_over_different_projection_types(bool isAsync, string leftType, string rightType) => Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public override Task GroupBy_Select_Union(bool isAsync)
return Task.CompletedTask; //base.GroupBy_Select_Union(isAsync);
}

public override Task Union_over_different_projection_types(bool isAsync)
public override Task Union_over_different_projection_types(bool isAsync, string leftType, string rightType)
{
return Task.CompletedTask; //base.Union_over_different_projection_types(isAsync);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.TestModels.Northwind;
Expand Down Expand Up @@ -353,14 +354,46 @@ public virtual Task GroupBy_Select_Union(bool isAsync)
.Select(g => new { CustomerID = g.Key, Count = g.Count() })));

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Union_over_different_projection_types(bool isAsync)
=> AssertQuery<Customer>(isAsync, cs => cs
.Where(c => c.City == "Berlin")
.GroupBy(c => c.CustomerID)
.Select(g => new { CustomerID = g.Key, Count = g.Count() })
.Union(cs
.Where(c => c.City == "London")
.Select(c => new { c.CustomerID, Count = c.ContactName.Length })));
[MemberData(nameof(GetSetOperandTestCases))]
public virtual Task Union_over_different_projection_types(bool isAsync, string leftType, string rightType)
{
var (left, right) = (ExpressionGenerator(leftType), ExpressionGenerator(rightType));
return AssertQuery<Order>(isAsync, os => left(os).Union(right(os)));

static Func<IQueryable<Order>, IQueryable<object>> ExpressionGenerator(string expressionType)
{
switch (expressionType)
{
case "Column":
return os => os.Select(o => (object)o.OrderID);
case "Function":
return os => os
.GroupBy(o => o.OrderID)
.Select(g => (object)g.Count());
case "Constant":
return os => os.Select(o => (object)8);
case "Unary":
return os => os.Select(o => (object)-o.OrderID);
case "Binary":
return os => os.Select(o => (object)(o.OrderID + 1));
case "ScalarSubquery":
return os => os.Select(o => (object)o.OrderDetails.Count());
default:
throw new NotSupportedException();
}
}
}

private static IEnumerable<object[]> GetSetOperandTestCases()
=> from async in new[] { true, false }
from leftType in SupportedOperandExpressionType
from rightType in SupportedOperandExpressionType
select new object[] { async, leftType, rightType };

// ReSharper disable once StaticMemberInGenericType
private static readonly string[] SupportedOperandExpressionType =
{
"Column", "Function", "Constant", "Unary", "Binary", "ScalarSubquery"
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -350,20 +350,5 @@ FROM [Customers] AS [c0]
WHERE ([c0].[City] = N'London') AND [c0].[City] IS NOT NULL
GROUP BY [c0].[CustomerID]");
}

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

AssertSql(
@"SELECT [c].[CustomerID], COUNT(*) AS [Count]
FROM [Customers] AS [c]
WHERE ([c].[City] = N'Berlin') AND [c].[City] IS NOT NULL
GROUP BY [c].[CustomerID]
UNION
SELECT [c0].[CustomerID], CAST(LEN([c0].[ContactName]) AS int) AS [Count]
FROM [Customers] AS [c0]
WHERE ([c0].[City] = N'London') AND [c0].[City] IS NOT NULL");
}
}
}

0 comments on commit cbe4ac9

Please sign in to comment.