From e0f2d8f986789bee65c42fcd7c3a19350f737222 Mon Sep 17 00:00:00 2001 From: Arthur Vickers Date: Mon, 17 Aug 2020 14:04:23 -0700 Subject: [PATCH] Make query string tests separate Fix issue trying to execute non-executable SQL --- .../TestUtilities/RelationalQueryAsserter.cs | 10 +++++++++- .../Query/NorthwindIncludeQuerySqlServerTest.cs | 16 ++++++++++++++++ .../NorthwindSplitIncludeQuerySqlServerTest.cs | 4 ++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/test/EFCore.Relational.Specification.Tests/TestUtilities/RelationalQueryAsserter.cs b/test/EFCore.Relational.Specification.Tests/TestUtilities/RelationalQueryAsserter.cs index 44f9e84e0ac..97794decb64 100644 --- a/test/EFCore.Relational.Specification.Tests/TestUtilities/RelationalQueryAsserter.cs +++ b/test/EFCore.Relational.Specification.Tests/TestUtilities/RelationalQueryAsserter.cs @@ -5,6 +5,7 @@ using System.Data.Common; using System.Linq; using System.Linq.Expressions; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Xunit; @@ -53,9 +54,16 @@ private static void ExecuteTheirDbCommand( { var (connection, transaction, timeout, expectedCount) = commandDependencies; + var queryString = queryable.ToQueryString(); + + if (queryString.EndsWith(RelationalStrings.SplitQueryString, StringComparison.Ordinal)) + { + queryString = queryString.Substring(0, queryString.Length - RelationalStrings.SplitQueryString.Length); + } + using var command = connection.CreateCommand(); command.Transaction = transaction; - command.CommandText = queryable.ToQueryString(); + command.CommandText = queryString; command.CommandTimeout = timeout; var count = ExecuteReader(command); diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindIncludeQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindIncludeQuerySqlServerTest.cs index 36168657b0f..eb2b2682a48 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindIncludeQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindIncludeQuerySqlServerTest.cs @@ -162,6 +162,22 @@ FROM [Orders] AS [o] ignoreWhiteSpaceDifferences: true); } + [ConditionalFact] + public void ToQueryString_for_include_reference_and_collection() + { + using var context = CreateContext(); + + Assert.Equal( + @"SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate], [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region], [o0].[OrderID], [o0].[ProductID], [o0].[Discount], [o0].[Quantity], [o0].[UnitPrice] +FROM [Orders] AS [o] +LEFT JOIN [Customers] AS [c] ON [o].[CustomerID] = [c].[CustomerID] +LEFT JOIN [Order Details] AS [o0] ON [o].[OrderID] = [o0].[OrderID] +ORDER BY [o].[OrderID], [c].[CustomerID], [o0].[OrderID], [o0].[ProductID]", + context.Set().Include(o => o.Customer).Include(o => o.OrderDetails).ToQueryString(), + ignoreLineEndingDifferences: true, + ignoreWhiteSpaceDifferences: true); + } + public override async Task Include_references_multi_level(bool async) { await base.Include_references_multi_level(async); diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSplitIncludeQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSplitIncludeQuerySqlServerTest.cs index 92bbef47ec6..19fbf93c19b 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSplitIncludeQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSplitIncludeQuerySqlServerTest.cs @@ -180,7 +180,11 @@ FROM [Orders] AS [o] LEFT JOIN [Customers] AS [c] ON [o].[CustomerID] = [c].[CustomerID] INNER JOIN [Order Details] AS [o0] ON [o].[OrderID] = [o0].[OrderID] ORDER BY [o].[OrderID], [c].[CustomerID]"); + } + [ConditionalFact] + public virtual void ToQueryString_for_include_reference_and_collection() + { using var context = CreateContext(); Assert.Equal(