diff --git a/build.proj b/build.proj index 6313880f30..7d39fa93d3 100644 --- a/build.proj +++ b/build.proj @@ -67,14 +67,9 @@ - - - - - @@ -102,8 +97,8 @@ - - + + @@ -116,7 +111,6 @@ - @@ -126,7 +120,6 @@ - @@ -174,11 +167,6 @@ - - - - - @@ -197,11 +185,6 @@ - - - - - @@ -234,17 +217,15 @@ $(DotnetPath)dotnet test "@(UnitTestsProj)" - --no-build - -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($(TestCommand), "\s+", " ")) @@ -255,17 +236,15 @@ $(DotnetPath)dotnet test "@(UnitTestsProj)" - --no-build - -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($(TestCommand), "\s+", " ")) diff --git a/src/Microsoft.Data.SqlClient.sln b/src/Microsoft.Data.SqlClient.sln index 7f2deaa020..526eb4c06b 100644 --- a/src/Microsoft.Data.SqlClient.sln +++ b/src/Microsoft.Data.SqlClient.sln @@ -318,6 +318,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 @@ -658,6 +660,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 @@ -715,6 +729,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/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csproj index 9bfceb3dc0..4adf180433 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 + + + @@ -60,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/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 a105ccdf29..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 @@ -1,71 +1,81 @@  + UnitTests - netfx - netcoreapp - win - $(ObjFolder)$(Configuration).$(Platform).$(AssemblyName) - $(BinFolder)$(Configuration).$(Platform).$(AssemblyName) + true enable - + + - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - + + Microsoft.Data.SqlClient.UnitTests.Resources.resources + ResXFileCodeGenerator + Resources.Designer.cs + + + True + True + Resources.resx + + + PreserveNewest + xunit.runner.json + + + + + + + + + + + + + + + + + + + + + + - - - - - - - + - - - - - - - PreserveNewest - %(Filename)%(Extension) - - - - - PreserveNewest - xunit.runner.json - - - - - - True - True - Resources.resx - - - ResXFileCodeGenerator - Resources.Designer.cs - + + + + + + + + + + + + + + + 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,