Skip to content

Commit

Permalink
Add tests for FromSql with DbParameter without name prefix
Browse files Browse the repository at this point in the history
Closes #14173
  • Loading branch information
divega committed Jul 1, 2019
1 parent c520ecf commit 5825d04
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
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"));
}
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ protected override DbParameter CreateDbParameter(string name, object value)
ParameterName = name,
Value = value
};

}
}

0 comments on commit 5825d04

Please sign in to comment.