Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for FromSql with DbParameter without name prefix #16362

Merged
merged 1 commit into from
Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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"));
}
divega marked this conversation as resolved.
Show resolved Hide resolved
}

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

Expand Down Expand Up @@ -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");
}

Expand Down