From 1a1cf8cbe8760e4d4b3f5f810c27effcb1cc6623 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Thu, 18 Dec 2025 18:30:14 -0600 Subject: [PATCH 1/8] Unit test project is building with reference to common project now. However, many tests are failing due to runtime issues in common project MDS. --- .../src/Microsoft.Data.SqlClient.csproj | 8 +- .../Microsoft.Data.SqlClient.UnitTests.csproj | 98 ++++++++++--------- 2 files changed, 57 insertions(+), 49 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csproj index 9bfceb3dc0..9c7ecf021d 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csproj @@ -15,7 +15,13 @@ $(SigningKeyPath) - + + + + <_Parameter1>UnitTests + + + diff --git a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj index a105ccdf29..f99d26241e 100644 --- a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj +++ b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj @@ -1,71 +1,73 @@  + UnitTests - netfx - netcoreapp - win - $(ObjFolder)$(Configuration).$(Platform).$(AssemblyName) - $(BinFolder)$(Configuration).$(Platform).$(AssemblyName) + true enable - + + - + + ResXFileCodeGenerator + Resources.Designer.cs + + + True + True + Resources.resx + + + PreserveNewest + xunit.runner.json + + + + + + PreserveNewest + %(Filename)%(Extension) + + + + + + + + + + + + - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - + + - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - - + - - - - - - - - - - - - - PreserveNewest - %(Filename)%(Extension) - - - - - PreserveNewest - xunit.runner.json - - - - - - True - True - Resources.resx - - - ResXFileCodeGenerator - Resources.Designer.cs - + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + From 7ecc07de5fb232bacdb2b8dd541ca2f8c36c27c6 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Mon, 29 Dec 2025 18:28:17 -0600 Subject: [PATCH 2/8] Directly expose exceptions in connection failover tests --- .../ConnectionFailoverTests.cs | 33 +++++++------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/tests/UnitTests/SimulatedServerTests/ConnectionFailoverTests.cs b/src/Microsoft.Data.SqlClient/tests/UnitTests/SimulatedServerTests/ConnectionFailoverTests.cs index 8f7351784d..d23fc9c532 100644 --- a/src/Microsoft.Data.SqlClient/tests/UnitTests/SimulatedServerTests/ConnectionFailoverTests.cs +++ b/src/Microsoft.Data.SqlClient/tests/UnitTests/SimulatedServerTests/ConnectionFailoverTests.cs @@ -181,10 +181,12 @@ public void NetworkTimeout_ShouldFail() using SqlConnection connection = new(builder.ConnectionString); // Act - var e = Assert.Throws(() => connection.Open()); + Action action = () => connection.Open(); // Assert - Assert.Contains("Connection Timeout Expired", e.Message); + SqlException exception = Assert.Throws(action); + Assert.Contains("Connection Timeout Expired", exception.Message); + Assert.Equal(ConnectionState.Closed, connection.State); Assert.Equal(1, server.PreLoginCount); Assert.Equal(0, failoverServer.PreLoginCount); @@ -214,7 +216,7 @@ public void NetworkDelay_ShouldConnectToPrimary() SqlConnectionStringBuilder builder = new() { DataSource = "localhost," + server.EndPoint.Port, - InitialCatalog = "master",// Required for failover partner to work + InitialCatalog = "master", // Required for failover partner to work ConnectTimeout = 5, Encrypt = false, MultiSubnetFailover = false, @@ -223,15 +225,9 @@ public void NetworkDelay_ShouldConnectToPrimary() #endif }; using SqlConnection connection = new(builder.ConnectionString); - try - { - // Act - connection.Open(); - } - catch (Exception e) - { - Assert.Fail(e.Message); - } + + // Act + connection.Open(); // Assert // On the first connection attempt, no failover partner information is available, @@ -274,15 +270,10 @@ public void NetworkError_WithUserProvidedPartner_RetryDisabled_ShouldConnectToFa Encrypt = false, }; using SqlConnection connection = new(builder.ConnectionString); - try - { - // Act - connection.Open(); - } - catch (Exception e) - { - Assert.Fail(e.Message); - } + + // Act + connection.Open(); + // Assert // On the first connection attempt, failover partner information is available in the connection string, From ce7dc3c25e31078d1ebc6cfd98df6f05dfbbbf84 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Tue, 30 Dec 2025 18:24:41 -0600 Subject: [PATCH 3/8] Fix resource issues in common project, fix SNI issues in unit test project, fix resource issues in unit test project. --- .../src/Microsoft.Data.SqlClient.csproj | 20 +++++++ .../Microsoft.Data.SqlClient.UnitTests.csproj | 60 +++++++++++-------- 2 files changed, 54 insertions(+), 26 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csproj index 9c7ecf021d..4adf180433 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csproj @@ -66,6 +66,26 @@ + + + + Microsoft.Data.SqlClient.Resources.Strings.resources + ResXFileCodeGenerator + Strings.Designer.cs + System + + + + + Microsoft.Data.SqlClient.Resources.%(Filename).resources + + + + + True + True + Strings.resx + diff --git a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj index f99d26241e..a024aa13b5 100644 --- a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj +++ b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj @@ -10,6 +10,7 @@ + Microsoft.Data.SqlClient.UnitTests.Resources.resources ResXFileCodeGenerator Resources.Designer.cs @@ -22,14 +23,6 @@ PreserveNewest xunit.runner.json - - - - - PreserveNewest - %(Filename)%(Extension) - @@ -38,21 +31,26 @@ - - + + + + + + + - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - + + @@ -60,14 +58,24 @@ - - - + + + + + + + + + + - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - + + + + From e3d0f76aee9f56c67f9e3ddcbb32bab4b1539136 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Wed, 7 Jan 2026 18:42:02 -0600 Subject: [PATCH 4/8] Reference new TestCommon project from UnitTests --- build.proj | 5 --- src/Microsoft.Data.SqlClient.sln | 15 +++++++ ...Microsoft.Data.SqlClient.TestCommon.csproj | 41 +++++++++++++++++++ .../Microsoft.Data.SqlClient.UnitTests.csproj | 4 +- 4 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 src/Microsoft.Data.SqlClient/tests/Common/Microsoft.Data.SqlClient.TestCommon.csproj diff --git a/build.proj b/build.proj index 6313880f30..59d33cb8c6 100644 --- a/build.proj +++ b/build.proj @@ -67,14 +67,9 @@ - - - - - diff --git a/src/Microsoft.Data.SqlClient.sln b/src/Microsoft.Data.SqlClient.sln index 8b4f420f19..b7367171a3 100644 --- a/src/Microsoft.Data.SqlClient.sln +++ b/src/Microsoft.Data.SqlClient.sln @@ -317,6 +317,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlClient.Stress.Tests", "M EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Data.SqlClient.Samples", "..\doc\Samples\Microsoft.Data.SqlClient.Samples.csproj", "{C09B9D2F-E463-BEBD-34E4-E8F2C201A277}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Data.SqlClient.TestCommon", "Microsoft.Data.SqlClient\tests\Common\Microsoft.Data.SqlClient.TestCommon.csproj", "{3FF03FA9-E3C3-49E3-9DCB-C703A5B0278B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -657,6 +659,18 @@ Global {C09B9D2F-E463-BEBD-34E4-E8F2C201A277}.Release|Any CPU.ActiveCfg = Release|Any CPU {C09B9D2F-E463-BEBD-34E4-E8F2C201A277}.Release|x64.ActiveCfg = Release|x64 {C09B9D2F-E463-BEBD-34E4-E8F2C201A277}.Release|x86.ActiveCfg = Release|x86 + {3FF03FA9-E3C3-49E3-9DCB-C703A5B0278B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3FF03FA9-E3C3-49E3-9DCB-C703A5B0278B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3FF03FA9-E3C3-49E3-9DCB-C703A5B0278B}.Debug|x64.ActiveCfg = Debug|x64 + {3FF03FA9-E3C3-49E3-9DCB-C703A5B0278B}.Debug|x64.Build.0 = Debug|x64 + {3FF03FA9-E3C3-49E3-9DCB-C703A5B0278B}.Debug|x86.ActiveCfg = Debug|x86 + {3FF03FA9-E3C3-49E3-9DCB-C703A5B0278B}.Debug|x86.Build.0 = Debug|x86 + {3FF03FA9-E3C3-49E3-9DCB-C703A5B0278B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3FF03FA9-E3C3-49E3-9DCB-C703A5B0278B}.Release|Any CPU.Build.0 = Release|Any CPU + {3FF03FA9-E3C3-49E3-9DCB-C703A5B0278B}.Release|x64.ActiveCfg = Release|x64 + {3FF03FA9-E3C3-49E3-9DCB-C703A5B0278B}.Release|x64.Build.0 = Release|x64 + {3FF03FA9-E3C3-49E3-9DCB-C703A5B0278B}.Release|x86.ActiveCfg = Release|x86 + {3FF03FA9-E3C3-49E3-9DCB-C703A5B0278B}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -714,6 +728,7 @@ Global {4A9C11F4-9577-ABEC-C070-83A194746D9B} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} {FAA1E517-581A-D3DC-BAC9-FAD1D5A5142C} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} {C09B9D2F-E463-BEBD-34E4-E8F2C201A277} = {ED952CF7-84DF-437A-B066-F516E9BE1C2C} + {3FF03FA9-E3C3-49E3-9DCB-C703A5B0278B} = {0CC4817A-12F3-4357-912C-09315FAAD008} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {01D48116-37A2-4D33-B9EC-94793C702431} diff --git a/src/Microsoft.Data.SqlClient/tests/Common/Microsoft.Data.SqlClient.TestCommon.csproj b/src/Microsoft.Data.SqlClient/tests/Common/Microsoft.Data.SqlClient.TestCommon.csproj new file mode 100644 index 0000000000..4c5c10a8a9 --- /dev/null +++ b/src/Microsoft.Data.SqlClient/tests/Common/Microsoft.Data.SqlClient.TestCommon.csproj @@ -0,0 +1,41 @@ + + + Microsoft.Data.SqlClient.TestCommon + Microsoft.Data.SqlClient.TestCommon + enable + + + + + + PreserveNewest + xunit.runner.json + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj index a024aa13b5..90dcc1a8af 100644 --- a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj +++ b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj @@ -55,7 +55,7 @@ - + @@ -76,6 +76,6 @@ - + From 666214002d5b88ad5c9f58bdc5c956169ae5b829 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Thu, 8 Jan 2026 18:22:27 -0600 Subject: [PATCH 5/8] patch to make unit test builds work --- build.proj | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/build.proj b/build.proj index 59d33cb8c6..b6608bf46c 100644 --- a/build.proj +++ b/build.proj @@ -97,8 +97,8 @@ - - + + @@ -111,7 +111,6 @@ - @@ -169,11 +168,6 @@ - - - - - @@ -192,11 +186,6 @@ - - - - - @@ -229,7 +218,6 @@ $(DotnetPath)dotnet test "@(UnitTestsProj)" - --no-build -v n -p:Configuration=$(Configuration) -p:Target$(TFGroup)Version=$(TF) @@ -250,7 +238,6 @@ $(DotnetPath)dotnet test "@(UnitTestsProj)" - --no-build -v n -p:Configuration=$(Configuration) -p:TargetNetCoreVersion=$(TF) From 6caf93720bcc22db3a63e793d1d3ce2aa24e3200 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Fri, 9 Jan 2026 14:10:52 -0600 Subject: [PATCH 6/8] Remove unit test project from restore targets --- build.proj | 1 - 1 file changed, 1 deletion(-) diff --git a/build.proj b/build.proj index b6608bf46c..c2f6f3b659 100644 --- a/build.proj +++ b/build.proj @@ -120,7 +120,6 @@ - From fb206f626f44d35a5f1ed43b993a358632dcf4d3 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Fri, 9 Jan 2026 18:31:28 -0600 Subject: [PATCH 7/8] TF -> -f --- build.proj | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/build.proj b/build.proj index c2f6f3b659..f3a9884b63 100644 --- a/build.proj +++ b/build.proj @@ -217,16 +217,15 @@ $(DotnetPath)dotnet test "@(UnitTestsProj)" - -v n + -f $(TF) -p:Configuration=$(Configuration) - -p:Target$(TFGroup)Version=$(TF) - -p:TestTargetOS=Windows$(TargetGroup) $(CollectStatement) --results-directory $(ResultsDirectory) --filter "$(FilterStatement)" --logger:"trx;LogFilePrefix=Unit-Windows$(TargetGroup)-$(TestSet)" - $(TestCommand.Replace($([System.Environment]::NewLine), " ")) + + $([System.Text.RegularExpressions.Regex]::Replace($(DotnetCommand), "\s+", " ")) @@ -237,16 +236,15 @@ $(DotnetPath)dotnet test "@(UnitTestsProj)" - -v n + -f $(TF) -p:Configuration=$(Configuration) - -p:TargetNetCoreVersion=$(TF) - -p:TestTargetOS=Unixnetcoreapp $(CollectStatement) --results-directory $(ResultsDirectory) --filter "$(FilterStatement)" --logger:"trx;LogFilePrefix=Unit-Unixnetcoreapp-$(TestSet)" - $(TestCommand.Replace($([System.Environment]::NewLine), " ")) + + $([System.Text.RegularExpressions.Regex]::Replace($(DotnetCommand), "\s+", " ")) From 2c83f0b305b97703c2fd8655988b9af7d7e42b0e Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Fri, 9 Jan 2026 18:48:01 -0600 Subject: [PATCH 8/8] Whoops --- build.proj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.proj b/build.proj index f3a9884b63..7d39fa93d3 100644 --- a/build.proj +++ b/build.proj @@ -225,7 +225,7 @@ --logger:"trx;LogFilePrefix=Unit-Windows$(TargetGroup)-$(TestSet)" - $([System.Text.RegularExpressions.Regex]::Replace($(DotnetCommand), "\s+", " ")) + $([System.Text.RegularExpressions.Regex]::Replace($(TestCommand), "\s+", " ")) @@ -244,7 +244,7 @@ --logger:"trx;LogFilePrefix=Unit-Unixnetcoreapp-$(TestSet)" - $([System.Text.RegularExpressions.Regex]::Replace($(DotnetCommand), "\s+", " ")) + $([System.Text.RegularExpressions.Regex]::Replace($(TestCommand), "\s+", " "))