Skip to content

Commit 6b9d491

Browse files
authored
Fix tests for Azure SQL and SQL Server 2025 (#36631)
Part of #35884
1 parent 6dc49bf commit 6b9d491

20 files changed

+786
-554
lines changed

test/EFCore.SqlServer.FunctionalTests/Query/AdHocJsonQuerySqlServerTestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ INSERT INTO [Entities] ([Id], [Scenario], [OptionalReference], [RequiredReferenc
444444

445445
#region EnumLegacyValues
446446

447-
[ConditionalTheory, MemberData(nameof(IsAsyncData))]
447+
[ConditionalTheory(Skip = "#36626"), MemberData(nameof(IsAsyncData))]
448448
public virtual async Task Read_enum_property_with_legacy_values(bool async)
449449
{
450450
var contextFactory = await InitializeAsync<DbContext>(

test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServer160Test.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4905,6 +4905,6 @@ protected override string StoreName
49054905
=> "ComplexNavigations160";
49064906

49074907
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
4908-
=> base.AddOptions(builder).UseSqlServer(b => b.UseCompatibilityLevel(160));
4908+
=> base.AddOptions(builder).UseSqlServerCompatibilityLevel(160);
49094909
}
49104910
}

test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServer160Test.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8525,6 +8525,6 @@ protected override string StoreName
85258525
=> "ComplexNavigationsOwned160";
85268526

85278527
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
8528-
=> base.AddOptions(builder).UseSqlServer(b => b.UseCompatibilityLevel(160));
8528+
=> base.AddOptions(builder).UseSqlServerCompatibilityLevel(160);
85298529
}
85308530
}

test/EFCore.SqlServer.FunctionalTests/Query/JsonQueryJsonTypeSqlServerTest.cs

Lines changed: 158 additions & 250 deletions
Large diffs are not rendered by default.

test/EFCore.SqlServer.FunctionalTests/Query/NorthwindDbFunctionsQuerySqlServer160Test.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,9 @@ private void AssertSql(params string[] expected)
13751375
public class Fixture160 : NorthwindQuerySqlServerFixture<NoopModelCustomizer>
13761376
{
13771377
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
1378-
=> base.AddOptions(builder).UseSqlServer(b => b.UseCompatibilityLevel(160));
1378+
{
1379+
var options = base.AddOptions(builder);
1380+
return options.UseSqlServerCompatibilityLevel(160);
1381+
}
13791382
}
13801383
}

test/EFCore.SqlServer.FunctionalTests/Query/NorthwindFunctionsQuerySqlServer160Test.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,6 @@ protected override void ClearLog()
225225
public class Fixture160 : NorthwindQuerySqlServerFixture<NoopModelCustomizer>
226226
{
227227
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
228-
=> base.AddOptions(builder).UseSqlServer(b => b.UseCompatibilityLevel(160));
228+
=> base.AddOptions(builder).UseSqlServerCompatibilityLevel(160);
229229
}
230230
}

test/EFCore.SqlServer.FunctionalTests/Query/PrecompiledSqlPregenerationQuerySqlServerTest.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -254,16 +254,9 @@ protected override ITestStoreFactory TestStoreFactory
254254
=> SqlServerTestStoreFactory.Instance;
255255

256256
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
257-
{
258-
builder = base.AddOptions(builder);
259-
260257
// TODO: Figure out if there's a nice way to continue using the retrying strategy
261-
var sqlServerOptionsBuilder = new SqlServerDbContextOptionsBuilder(builder);
262-
sqlServerOptionsBuilder
263-
.UseCompatibilityLevel(120)
264-
.ExecutionStrategy(d => new NonRetryingExecutionStrategy(d));
265-
return builder;
266-
}
258+
=> base.AddOptions(builder).UseSqlServerCompatibilityLevel(120)
259+
.ConfigureSqlEngine(b => b.ExecutionStrategy(d => new NonRetryingExecutionStrategy(d)));
267260

268261
public override PrecompiledQueryTestHelpers PrecompiledQueryTestHelpers
269262
=> SqlServerPrecompiledQueryTestHelpers.Instance;

test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQueryOldSqlServerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1542,6 +1542,6 @@ protected override ITestStoreFactory TestStoreFactory
15421542

15431543
// Compatibility level 120 (SQL Server 2014) doesn't support OPENJSON
15441544
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
1545-
=> base.AddOptions(builder).UseSqlServer(o => o.UseCompatibilityLevel(120));
1545+
=> base.AddOptions(builder).UseSqlServerCompatibilityLevel(120);
15461546
}
15471547
}

test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServer160Test.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2261,7 +2261,7 @@ protected override ITestStoreFactory TestStoreFactory
22612261
=> SqlServerTestStoreFactory.Instance;
22622262

22632263
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
2264-
=> base.AddOptions(builder).UseSqlServer(b => b.UseCompatibilityLevel(160));
2264+
=> base.AddOptions(builder).UseSqlServerCompatibilityLevel(160);
22652265

22662266
protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context)
22672267
{

test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerJsonTypeTest.cs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public override async Task Parameter_collection_Count_with_column_predicate_with
9090
FROM [PrimitiveCollectionsEntity] AS [p]
9191
WHERE (
9292
SELECT COUNT(*)
93-
FROM (VALUES (2), (999), (1000)) AS [i]([Value])
93+
FROM (VALUES (CAST(2 AS int)), (999), (1000)) AS [i]([Value])
9494
WHERE [i].[Value] > [p].[Id]) = 2
9595
""");
9696
}
@@ -1130,7 +1130,7 @@ public override async Task Column_collection_index_int()
11301130
"""
11311131
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[NullableWrappedId], [p].[NullableWrappedIdWithNullableComparer], [p].[String], [p].[Strings], [p].[WrappedId]
11321132
FROM [PrimitiveCollectionsEntity] AS [p]
1133-
WHERE CAST(JSON_VALUE([p].[Ints], '$[1]') AS int) = 10
1133+
WHERE JSON_VALUE([p].[Ints], '$[1]' RETURNING int) = 10
11341134
""");
11351135
}
11361136

@@ -1142,7 +1142,7 @@ public override async Task Column_collection_index_string()
11421142
"""
11431143
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[NullableWrappedId], [p].[NullableWrappedIdWithNullableComparer], [p].[String], [p].[Strings], [p].[WrappedId]
11441144
FROM [PrimitiveCollectionsEntity] AS [p]
1145-
WHERE JSON_VALUE([p].[Strings], '$[1]') = N'10'
1145+
WHERE JSON_VALUE([p].[Strings], '$[1]' RETURNING nvarchar(max)) = N'10'
11461146
""");
11471147
}
11481148

@@ -1154,7 +1154,7 @@ public override async Task Column_collection_index_datetime()
11541154
"""
11551155
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[NullableWrappedId], [p].[NullableWrappedIdWithNullableComparer], [p].[String], [p].[Strings], [p].[WrappedId]
11561156
FROM [PrimitiveCollectionsEntity] AS [p]
1157-
WHERE CAST(JSON_VALUE([p].[DateTimes], '$[1]') AS datetime2) = '2020-01-10T12:30:00.0000000Z'
1157+
WHERE JSON_VALUE([p].[DateTimes], '$[1]' RETURNING datetime2) = '2020-01-10T12:30:00.0000000Z'
11581158
""");
11591159
}
11601160

@@ -1166,7 +1166,7 @@ public override async Task Column_collection_index_beyond_end()
11661166
"""
11671167
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[NullableWrappedId], [p].[NullableWrappedIdWithNullableComparer], [p].[String], [p].[Strings], [p].[WrappedId]
11681168
FROM [PrimitiveCollectionsEntity] AS [p]
1169-
WHERE CAST(JSON_VALUE([p].[Ints], '$[999]') AS int) = 10
1169+
WHERE JSON_VALUE([p].[Ints], '$[999]' RETURNING int) = 10
11701170
""");
11711171
}
11721172

@@ -1179,7 +1179,7 @@ public override async Task Nullable_reference_column_collection_index_equals_nul
11791179
"""
11801180
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[NullableWrappedId], [p].[NullableWrappedIdWithNullableComparer], [p].[String], [p].[Strings], [p].[WrappedId]
11811181
FROM [PrimitiveCollectionsEntity] AS [p]
1182-
WHERE JSON_VALUE([p].[NullableStrings], '$[2]') = [p].[NullableString] OR (JSON_VALUE([p].[NullableStrings], '$[2]') IS NULL AND [p].[NullableString] IS NULL)
1182+
WHERE JSON_VALUE([p].[NullableStrings], '$[2]' RETURNING nvarchar(max)) = [p].[NullableString] OR (JSON_VALUE([p].[NullableStrings], '$[2]' RETURNING nvarchar(max)) IS NULL AND [p].[NullableString] IS NULL)
11831183
""");
11841184
}
11851185

@@ -1193,7 +1193,7 @@ public override async Task Non_nullable_reference_column_collection_index_equals
11931193
FROM [PrimitiveCollectionsEntity] AS [p]
11941194
WHERE EXISTS (
11951195
SELECT 1
1196-
FROM OPENJSON([p].[Strings]) AS [s]) AND JSON_VALUE([p].[Strings], '$[1]') = [p].[NullableString]
1196+
FROM OPENJSON([p].[Strings]) AS [s]) AND JSON_VALUE([p].[Strings], '$[1]' RETURNING nvarchar(max)) = [p].[NullableString]
11971197
""");
11981198
}
11991199

@@ -1221,11 +1221,7 @@ public override async Task Inline_collection_index_Column_with_EF_Constant()
12211221
"""
12221222
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[NullableWrappedId], [p].[NullableWrappedIdWithNullableComparer], [p].[String], [p].[Strings], [p].[WrappedId]
12231223
FROM [PrimitiveCollectionsEntity] AS [p]
1224-
WHERE (
1225-
SELECT [i].[Value]
1226-
FROM (VALUES (0, CAST(1 AS int)), (1, 2), (2, 3)) AS [i]([_ord], [Value])
1227-
ORDER BY [i].[_ord]
1228-
OFFSET [p].[Int] ROWS FETCH NEXT 1 ROWS ONLY) = 1
1224+
WHERE CAST(JSON_VALUE(N'[1,2,3]', '$[' + CAST([p].[Int] AS nvarchar(max)) + ']') AS int) = 1
12291225
""");
12301226
}
12311227

@@ -1299,7 +1295,7 @@ public override async Task Column_collection_ElementAt()
12991295
"""
13001296
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[NullableWrappedId], [p].[NullableWrappedIdWithNullableComparer], [p].[String], [p].[Strings], [p].[WrappedId]
13011297
FROM [PrimitiveCollectionsEntity] AS [p]
1302-
WHERE CAST(JSON_VALUE([p].[Ints], '$[1]') AS int) = 10
1298+
WHERE JSON_VALUE([p].[Ints], '$[1]' RETURNING int) = 10
13031299
""");
13041300
}
13051301

@@ -1827,7 +1823,7 @@ SELECT COUNT(*)
18271823
SELECT [i1].[Value]
18281824
FROM (
18291825
SELECT [i].[Value]
1830-
FROM (VALUES (1, @ints1), (2, @ints2)) AS [i]([_ord], [Value])
1826+
FROM (VALUES (0, @ints1), (1, @ints2)) AS [i]([_ord], [Value])
18311827
ORDER BY [i].[_ord]
18321828
OFFSET 1 ROWS
18331829
) AS [i1]
@@ -1917,7 +1913,7 @@ FROM [PrimitiveCollectionsEntity] AS [p]
19171913
SELECT COUNT(*)
19181914
FROM (
19191915
SELECT [i].[Value] AS [Value0]
1920-
FROM (VALUES (1, @ints1), (2, @ints2)) AS [i]([_ord], [Value])
1916+
FROM (VALUES (0, @ints1), (1, @ints2)) AS [i]([_ord], [Value])
19211917
ORDER BY [i].[_ord]
19221918
OFFSET 1 ROWS
19231919
) AS [i0]
@@ -2147,7 +2143,7 @@ public override async Task Project_primitive_collections_element()
21472143

21482144
AssertSql(
21492145
"""
2150-
SELECT CAST(JSON_VALUE([p].[Ints], '$[0]') AS int) AS [Indexer], CAST(JSON_VALUE([p].[DateTimes], '$[0]') AS datetime2) AS [EnumerableElementAt], JSON_VALUE([p].[Strings], '$[1]') AS [QueryableElementAt]
2146+
SELECT JSON_VALUE([p].[Ints], '$[0]' RETURNING int) AS [Indexer], JSON_VALUE([p].[DateTimes], '$[0]' RETURNING datetime2) AS [EnumerableElementAt], JSON_VALUE([p].[Strings], '$[1]' RETURNING nvarchar(max)) AS [QueryableElementAt]
21512147
FROM [PrimitiveCollectionsEntity] AS [p]
21522148
WHERE [p].[Id] < 4
21532149
ORDER BY [p].[Id]
@@ -2268,8 +2264,10 @@ protected override ITestStoreFactory TestStoreFactory
22682264
=> SqlServerTestStoreFactory.Instance;
22692265

22702266
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
2271-
=> base.AddOptions(builder)
2272-
.UseSqlServer(b => b.UseCompatibilityLevel(160));
2267+
{
2268+
var options = base.AddOptions(builder);
2269+
return options.UseSqlServerCompatibilityLevel(160);
2270+
}
22732271

22742272
protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context)
22752273
{

0 commit comments

Comments
 (0)