Skip to content

Commit

Permalink
Make query string tests separate
Browse files Browse the repository at this point in the history
Fix issue trying to execute non-executable SQL
  • Loading branch information
ajcvickers committed Aug 18, 2020
1 parent e4f094b commit b451e5c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Order>().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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,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(
Expand Down

0 comments on commit b451e5c

Please sign in to comment.