Skip to content

Commit

Permalink
Add test for ExecuteUpdate with two inner joins
Browse files Browse the repository at this point in the history
And fixup for #29349
  • Loading branch information
roji committed Nov 9, 2022
1 parent d4aa1ea commit b93b368
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public SqlServerObjectToStringTranslator(ISqlExpressionFactory sqlExpressionFact
return null;
}

if(instance.TypeMapping is not null && instance.TypeMapping.ClrType == typeof(string))
if (instance.TypeMapping?.ClrType == typeof(string))
{
return instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public SqliteObjectToStringTranslator(ISqlExpressionFactory sqlExpressionFactory
return null;
}

if (instance.TypeMapping is not null && instance.TypeMapping.ClrType == typeof(string))
if (instance.TypeMapping?.ClrType == typeof(string))
{
return instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,19 @@ public virtual Task Update_Where_Join_set_property_from_joined_single_result_sca
}
}));

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Update_with_two_inner_joins(bool async)
=> AssertUpdate(
async,
ss => ss
.Set<OrderDetail>()
.Where(od => od.Product.Discontinued && od.Order.OrderDate > new DateTime(1990, 1, 1)),
e => e,
s => s.SetProperty(od => od.Quantity, 1),
rowsAffectedCount: 228,
(b, a) => Assert.All(a, od => Assert.Equal(1, od.Quantity)));

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore.TestModels.Northwind;

namespace Microsoft.EntityFrameworkCore.BulkUpdates;

public class NorthwindBulkUpdatesSqlServerTest : NorthwindBulkUpdatesTestBase<NorthwindBulkUpdatesSqlServerFixture<NoopModelCustomizer>>
Expand Down Expand Up @@ -1458,6 +1460,23 @@ WHERE [c].[CustomerID] LIKE N'F%'
""");
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public override async Task Update_with_two_inner_joins(bool async)
{
await base.Update_with_two_inner_joins(async);

AssertExecuteUpdateSql(
"""
UPDATE [o]
SET [o].[Quantity] = CAST(1 AS smallint)
FROM [Order Details] AS [o]
INNER JOIN [Products] AS [p] ON [o].[ProductID] = [p].[ProductID]
INNER JOIN [Orders] AS [o0] ON [o].[OrderID] = [o0].[OrderID]
WHERE [p].[Discontinued] = CAST(1 AS bit) AND [o0].[OrderDate] > '1990-01-01T00:00:00.000'
""");
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4099,8 +4099,11 @@ public override async Task ToString_string_property_projection(bool async)
{
await base.ToString_string_property_projection(async);

AssertSql(@"SELECT [w].[Name]
FROM [Weapons] AS [w]");
AssertSql(
"""
SELECT [w].[Name]
FROM [Weapons] AS [w]
""");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12499,8 +12499,11 @@ public override async Task ToString_string_property_projection(bool async)
{
await base.ToString_string_property_projection(async);

AssertSql(@"SELECT [w].[Name]
FROM [Weapons] AS [w]");
AssertSql(
"""
SELECT [w].[Name]
FROM [Weapons] AS [w]
""");
}

public override async Task ToString_boolean_property_non_nullable(bool async)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10738,8 +10738,11 @@ public override async Task ToString_string_property_projection(bool async)
{
await base.ToString_string_property_projection(async);

AssertSql(@"SELECT [w].[Name]
FROM [Weapons] AS [w]");
AssertSql(
"""
SELECT [w].[Name]
FROM [Weapons] AS [w]
""");
}

public override async Task ToString_boolean_property_non_nullable(bool async)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9008,8 +9008,11 @@ public override async Task ToString_string_property_projection(bool async)
{
await base.ToString_string_property_projection(async);

AssertSql(@"SELECT [w].[Name]
FROM [Weapons] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [w]");
AssertSql(
"""
SELECT [w].[Name]
FROM [Weapons] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [w]
""");
}

public override async Task ToString_boolean_property_non_nullable(bool async)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore.Sqlite.Internal;
using Microsoft.EntityFrameworkCore.TestModels.Northwind;

namespace Microsoft.EntityFrameworkCore.BulkUpdates;

Expand Down Expand Up @@ -1365,6 +1366,17 @@ public override async Task Update_Where_Join_set_property_from_joined_single_res
ORDER BY "o"."OrderDate" DESC
LIMIT 1)) AS INTEGER) AS TEXT)
WHERE "c"."CustomerID" LIKE 'F%'
""");
}

[ConditionalTheory(Skip = "Issue#28886")]
public override async Task Update_with_two_inner_joins(bool async)
{
await base.Update_with_two_inner_joins(async);

AssertExecuteUpdateSql(
"""

""");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3095,8 +3095,11 @@ public override async Task ToString_string_property_projection(bool async)
{
await base.ToString_string_property_projection(async);

AssertSql(@"SELECT ""w"".""Name""
FROM ""Weapons"" AS ""w""");
AssertSql(
"""
SELECT "w"."Name"
FROM "Weapons" AS "w"
""");
}

public override async Task ToString_boolean_property_non_nullable(bool async)
Expand Down

0 comments on commit b93b368

Please sign in to comment.