Skip to content

Commit

Permalink
Add test for set operations over FromSql
Browse files Browse the repository at this point in the history
Closes #16308
  • Loading branch information
roji committed Oct 22, 2019
1 parent 1051fd7 commit 179354c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Customer>()
.FromSqlRaw(NormalizeDelimetersInRawString("SELECT * FROM [Customers] WHERE [City] = 'London'"))
.Concat(context.Set<Customer>()
.FromSqlRaw(NormalizeDelimetersInRawString("SELECT * FROM [Customers] WHERE [City] = 'Berlin'")))
.ToArray();

Assert.Equal(7, actual.Length);
}

protected string NormalizeDelimetersInRawString(string sql)
=> Fixture.TestStore.NormalizeDelimetersInRawString(sql);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down

0 comments on commit 179354c

Please sign in to comment.