From 9e3b10d68188c9518cfc5bb3cb0050968adadd99 Mon Sep 17 00:00:00 2001 From: Diego Vega Date: Sun, 30 Jun 2019 16:44:30 -0700 Subject: [PATCH] Add tests for FromSql with DbParameter without name prefix Closes #14173 --- .../Query/FromSqlQueryTestBase.cs | 36 ++++++++++++++++++- .../Query/FromSqlQuerySqlServerTest.cs | 19 ++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/test/EFCore.Relational.Specification.Tests/Query/FromSqlQueryTestBase.cs b/test/EFCore.Relational.Specification.Tests/Query/FromSqlQueryTestBase.cs index ba8aef0ab2d..1670118aa06 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/FromSqlQueryTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/FromSqlQueryTestBase.cs @@ -733,6 +733,21 @@ public virtual void FromSqlRaw_with_dbParameter() } } + [Fact] + public virtual void FromSqlRaw_with_dbParameter_without_name_prefix() + { + using (var context = CreateContext()) + { + var parameter = CreateDbParameter("city", "London"); + + var actual = context.Customers.FromSqlRaw(NormalizeDelimetersInRawString("SELECT * FROM [Customers] WHERE [City] = @city"), parameter) + .ToArray(); + + Assert.Equal(6, actual.Length); + Assert.True(actual.All(c => c.City == "London")); + } + } + [ConditionalFact] public virtual void FromSqlRaw_with_dbParameter_mixed() { @@ -904,9 +919,28 @@ public virtual void FromSqlInterpolated_with_inlined_db_parameter() { var parameter = CreateDbParameter("@somename", "ALFKI"); - var query = context.Customers + var actual = context.Customers .FromSqlInterpolated(NormalizeDelimetersInInterpolatedString($"SELECT * FROM [Customers] WHERE [CustomerID] = {parameter}")) .ToList(); + + Assert.Equal(1, actual.Count); + Assert.True(actual.All(c => c.City == "Berlin")); + } + } + + [ConditionalFact] + public virtual void FromSqlInterpolated_with_inlined_db_parameter_without_name_prefix() + { + using (var context = CreateContext()) + { + var parameter = CreateDbParameter("somename", "ALFKI"); + + var actual = context.Customers + .FromSqlInterpolated(NormalizeDelimetersInInterpolatedString($"SELECT * FROM [Customers] WHERE [CustomerID] = {parameter}")) + .ToList(); + + Assert.Equal(1, actual.Count); + Assert.True(actual.All(c => c.City == "Berlin")); } } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/FromSqlQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/FromSqlQuerySqlServerTest.cs index 5662ffae5ca..fd94b912598 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/FromSqlQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/FromSqlQuerySqlServerTest.cs @@ -409,6 +409,15 @@ public override void FromSqlRaw_with_dbParameter() AssertSql( @"@city='London' (Nullable = false) (Size = 6) +SELECT * FROM ""Customers"" WHERE ""City"" = @city"); + } + + public override void FromSqlRaw_with_dbParameter_without_name_prefix() + { + base.FromSqlRaw_with_dbParameter_without_name_prefix(); + AssertSql( + @"city='London' (Nullable = false) (Size = 6) + SELECT * FROM ""Customers"" WHERE ""City"" = @city"); } @@ -481,6 +490,16 @@ public override void FromSqlInterpolated_with_inlined_db_parameter() AssertSql( @"@somename='ALFKI' (Nullable = false) (Size = 5) +SELECT * FROM ""Customers"" WHERE ""CustomerID"" = @somename"); + } + + public override void FromSqlInterpolated_with_inlined_db_parameter_without_name_prefix() + { + base.FromSqlInterpolated_with_inlined_db_parameter_without_name_prefix(); + + AssertSql( + @"somename='ALFKI' (Nullable = false) (Size = 5) + SELECT * FROM ""Customers"" WHERE ""CustomerID"" = @somename"); }