From cdfff74b39e59d0b397aeabd18968536ba285ae8 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Tue, 22 Oct 2019 19:56:10 +0200 Subject: [PATCH] Add test for set operations over FromSql Also added SQL assertion for unrelated test. Closes #16308 --- .../Query/FromSqlQueryTestBase.cs | 14 +++++++++ .../Query/FromSqlQuerySqlServerTest.cs | 29 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/test/EFCore.Relational.Specification.Tests/Query/FromSqlQueryTestBase.cs b/test/EFCore.Relational.Specification.Tests/Query/FromSqlQueryTestBase.cs index b6113936719..71e21bcc17a 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/FromSqlQueryTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/FromSqlQueryTestBase.cs @@ -1040,6 +1040,20 @@ public virtual void Entity_equality_through_fromsql() } } + [ConditionalFact] + public virtual void FromSqlRaw_with_set_operation() + { + using var context = CreateContext(); + + var actual = context.Set() + .FromSqlRaw(NormalizeDelimetersInRawString("SELECT * FROM [Customers] WHERE [City] = 'London'")) + .Concat(context.Set() + .FromSqlRaw(NormalizeDelimetersInRawString("SELECT * FROM [Customers] WHERE [City] = 'Berlin'"))) + .ToArray(); + + Assert.Equal(7, actual.Length); + } + protected string NormalizeDelimetersInRawString(string sql) => Fixture.TestStore.NormalizeDelimetersInRawString(sql); diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/FromSqlQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/FromSqlQuerySqlServerTest.cs index 1381777102c..8379f3c1209 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/FromSqlQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/FromSqlQuerySqlServerTest.cs @@ -746,6 +746,35 @@ public override void FromSqlRaw_does_not_parameterize_interpolated_string() SELECT * FROM ""Orders"" WHERE ""OrderID"" < @p0"); } + public override void Entity_equality_through_fromsql() + { + base.Entity_equality_through_fromsql(); + + AssertSql( + @"SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM ( + SELECT * FROM ""Orders"" +) AS [o] +LEFT JOIN [Customers] AS [c] ON [o].[CustomerID] = [c].[CustomerID] +WHERE ([c].[CustomerID] = N'VINET') AND [c].[CustomerID] IS NOT NULL"); + } + + public override void FromSqlRaw_with_set_operation() + { + base.FromSqlRaw_with_set_operation(); + + AssertSql( + @"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM ( + SELECT * FROM ""Customers"" WHERE ""City"" = 'London' +) AS [c] +UNION ALL +SELECT [c0].[CustomerID], [c0].[Address], [c0].[City], [c0].[CompanyName], [c0].[ContactName], [c0].[ContactTitle], [c0].[Country], [c0].[Fax], [c0].[Phone], [c0].[PostalCode], [c0].[Region] +FROM ( + SELECT * FROM ""Customers"" WHERE ""City"" = 'Berlin' +) AS [c0]"); + } + protected override DbParameter CreateDbParameter(string name, object value) => new SqlParameter { ParameterName = name, Value = value };