From cbe4ac934cb1ca23f6806bab4a0d681712bedf8a Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Wed, 31 Jul 2019 18:27:20 +0200 Subject: [PATCH] Additional testing --- .../SimpleQueryCosmosTest.SetOperations.cs | 3 +- .../Query/SimpleQueryInMemoryTest.cs | 2 +- .../SimpleQueryTestBase.SetOperations.cs | 51 +++++++++++++++---- .../SimpleQuerySqlServerTest.SetOperations.cs | 15 ------ 4 files changed, 44 insertions(+), 27 deletions(-) diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/SimpleQueryCosmosTest.SetOperations.cs b/test/EFCore.Cosmos.FunctionalTests/Query/SimpleQueryCosmosTest.SetOperations.cs index 4a378153466..1162737d6da 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/SimpleQueryCosmosTest.SetOperations.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/SimpleQueryCosmosTest.SetOperations.cs @@ -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; } } diff --git a/test/EFCore.InMemory.FunctionalTests/Query/SimpleQueryInMemoryTest.cs b/test/EFCore.InMemory.FunctionalTests/Query/SimpleQueryInMemoryTest.cs index a0bc648a979..6fcc725f12f 100644 --- a/test/EFCore.InMemory.FunctionalTests/Query/SimpleQueryInMemoryTest.cs +++ b/test/EFCore.InMemory.FunctionalTests/Query/SimpleQueryInMemoryTest.cs @@ -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); } diff --git a/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.SetOperations.cs b/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.SetOperations.cs index 9beba4f02cb..5f6d039bd7e 100644 --- a/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.SetOperations.cs +++ b/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.SetOperations.cs @@ -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; @@ -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(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(isAsync, os => left(os).Union(right(os))); + + static Func, IQueryable> 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 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" + }; } } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/SimpleQuerySqlServerTest.SetOperations.cs b/test/EFCore.SqlServer.FunctionalTests/Query/SimpleQuerySqlServerTest.SetOperations.cs index f8dcb278038..2a73059a56c 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/SimpleQuerySqlServerTest.SetOperations.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/SimpleQuerySqlServerTest.SetOperations.cs @@ -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"); - } } }