From 27032e2ace14956588f54519acfa59288fc6637f Mon Sep 17 00:00:00 2001 From: Malcolm Daigle Date: Wed, 4 Feb 2026 10:45:44 -0800 Subject: [PATCH 1/2] Convert OutputParameterTests to xunit assertion. --- ...icrosoft.Data.SqlClient.ManualTests.csproj | 17 --- .../SQL/ParameterTest/OutputParameter.cs | 49 ------ .../SQL/ParameterTest/OutputParameterTests.cs | 140 ++++-------------- .../OutputParameter_DebugMode.bsl | 3 - .../OutputParameter_DebugMode_Azure.bsl | 3 - .../OutputParameter_ReleaseMode.bsl | 3 - .../OutputParameter_ReleaseMode_Azure.bsl | 3 - 7 files changed, 25 insertions(+), 193 deletions(-) delete mode 100644 src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameter.cs delete mode 100644 src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameter_DebugMode.bsl delete mode 100644 src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameter_DebugMode_Azure.bsl delete mode 100644 src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameter_ReleaseMode.bsl delete mode 100644 src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameter_ReleaseMode_Azure.bsl diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTests.csproj b/src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTests.csproj index efc10126aa..7ae352c028 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTests.csproj +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTests.csproj @@ -191,7 +191,6 @@ - @@ -326,22 +325,6 @@ PreserveNewest DateTimeVariant_ReleaseMode_Azure.bsl - - PreserveNewest - OutputParameter_DebugMode.bsl - - - PreserveNewest - OutputParameter_DebugMode_Azure.bsl - - - PreserveNewest - OutputParameter_ReleaseMode.bsl - - - PreserveNewest - OutputParameter_ReleaseMode_Azure.bsl - diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameter.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameter.cs deleted file mode 100644 index 6af1a39e1d..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameter.cs +++ /dev/null @@ -1,49 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Data; - -namespace Microsoft.Data.SqlClient.ManualTesting.Tests -{ - public static class OutputParameter - { - public static void Run(string connectionString) - { - Console.WriteLine("Starting 'OutputParameter' tests"); - InvalidValueInOutParam(connectionString); - } - - // Changing the value of an output parameter to a value of different type throws System.FormatException - // You should be able to set an Output SqlParameter to an invalid value (e.g. a string in a decimal param) since we clear its value before starting - private static void InvalidValueInOutParam(string connectionString) - { - Console.WriteLine("Test setting output SqlParameter to an invalid value"); - - using (var connection = new SqlConnection(connectionString)) - { - connection.Open(); - - // Command simply set the outparam - using var command = new SqlCommand("SET @decimal = 1.23", connection); - - // Create valid param - var decimalParam = new SqlParameter("decimal", new decimal(2.34)) { SqlDbType = SqlDbType.Decimal, Direction = ParameterDirection.Output, Scale = 2, Precision = 5 }; - command.Parameters.Add(decimalParam); - // Set value of param to invalid value - decimalParam.Value = "Not a decimal"; - - // Execute - command.ExecuteNonQuery(); - // Validate - if (((decimal)decimalParam.Value) != new decimal(1.23)) - { - Console.WriteLine("FAIL: Value is incorrect: {0}", decimalParam.Value); - } - } - - Console.WriteLine("Done"); - } - } -} diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameterTests.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameterTests.cs index 7719ed2c01..a599140d71 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameterTests.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameterTests.cs @@ -2,20 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Globalization; -using System.IO; -using System.Text; -using System.Threading; +using System.Data; using Xunit; namespace Microsoft.Data.SqlClient.ManualTesting.Tests { /// /// Tests for output parameters. - /// These tests run independently with their own baseline comparison. /// - [Collection("ParameterBaselineTests")] public class OutputParameterTests { private readonly string _connStr; @@ -25,122 +19,38 @@ public OutputParameterTests() _connStr = DataTestUtility.TCPConnectionString; } - [Trait("Category", "flaky")] + /// + /// Tests that setting an output SqlParameter to an invalid value (e.g. a string in a decimal param) + /// doesn't throw, since the value is cleared before execution starts. + /// The output value should be correctly set by SQL Server after execution. + /// [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))] - public void OutputParameterTest() + public void InvalidValueInOutputParameter_ShouldSucceed() { - Assert.True(RunTestAndCompareWithBaseline()); - } - - private bool RunTestAndCompareWithBaseline() - { - CultureInfo previousCulture = Thread.CurrentThread.CurrentCulture; - Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); - try - { - string outputPath = "OutputParameter.out"; - string baselinePath; -#if DEBUG - if (DataTestUtility.IsNotAzureServer() || DataTestUtility.IsManagedInstance) - { - baselinePath = "OutputParameter_DebugMode.bsl"; - } - else - { - baselinePath = "OutputParameter_DebugMode_Azure.bsl"; - } -#else - if (DataTestUtility.IsNotAzureServer() || DataTestUtility.IsManagedInstance) - { - baselinePath = "OutputParameter_ReleaseMode.bsl"; - } - else - { - baselinePath = "OutputParameter_ReleaseMode_Azure.bsl"; - } -#endif - - var fstream = new FileStream(outputPath, FileMode.Create, FileAccess.Write, FileShare.Read); - var swriter = new StreamWriter(fstream, Encoding.UTF8); - var twriter = new TvpTest.CarriageReturnLineFeedReplacer(swriter); - Console.SetOut(twriter); - - // Run Test - OutputParameter.Run(_connStr); - - Console.Out.Flush(); - Console.Out.Dispose(); - - // Recover the standard output stream - StreamWriter standardOutput = new(Console.OpenStandardOutput()); - standardOutput.AutoFlush = true; - Console.SetOut(standardOutput); + using var connection = new SqlConnection(DataTestUtility.TCPConnectionString); + connection.Open(); - // Compare output file - var comparisonResult = FindDiffFromBaseline(baselinePath, outputPath); + // Command simply sets the output param + using var command = new SqlCommand("SET @decimal = 1.23", connection); - if (string.IsNullOrEmpty(comparisonResult)) + // Create valid param + var decimalParam = new SqlParameter("decimal", new decimal(2.34)) { - return true; - } + SqlDbType = SqlDbType.Decimal, + Direction = ParameterDirection.Output, + Scale = 2, + Precision = 5 + }; + command.Parameters.Add(decimalParam); - Console.WriteLine("OutputParameterTest Failed!"); - Console.WriteLine("Please compare baseline: {0} with output: {1}", Path.GetFullPath(baselinePath), Path.GetFullPath(outputPath)); - Console.WriteLine("Comparison Results:"); - Console.WriteLine(comparisonResult); - return false; - } - finally - { - Thread.CurrentThread.CurrentCulture = previousCulture; - } - } - - private static string FindDiffFromBaseline(string baselinePath, string outputPath) - { - var expectedLines = File.ReadAllLines(baselinePath); - var outputLines = File.ReadAllLines(outputPath); - - var comparisonSb = new StringBuilder(); - - var expectedLength = expectedLines.Length; - var outputLength = outputLines.Length; - var findDiffLength = Math.Min(expectedLength, outputLength); + // Set value of param to invalid value (string instead of decimal) + decimalParam.Value = "Not a decimal"; - for (var lineNo = 0; lineNo < findDiffLength; lineNo++) - { - if (!expectedLines[lineNo].Equals(outputLines[lineNo])) - { - comparisonSb.AppendFormat("** DIFF at line {0} \n", lineNo); - comparisonSb.AppendFormat("A : {0} \n", outputLines[lineNo]); - comparisonSb.AppendFormat("E : {0} \n", expectedLines[lineNo]); - } - } - - var startIndex = findDiffLength - 1; - if (startIndex < 0) - { - startIndex = 0; - } - - if (findDiffLength < expectedLength) - { - comparisonSb.AppendFormat("** MISSING \n"); - for (var lineNo = startIndex; lineNo < expectedLength; lineNo++) - { - comparisonSb.AppendFormat("{0} : {1}", lineNo, expectedLines[lineNo]); - } - } - if (findDiffLength < outputLength) - { - comparisonSb.AppendFormat("** EXTRA \n"); - for (var lineNo = startIndex; lineNo < outputLength; lineNo++) - { - comparisonSb.AppendFormat("{0} : {1}", lineNo, outputLines[lineNo]); - } - } + // Execute - should not throw + command.ExecuteNonQuery(); - return comparisonSb.ToString(); + // Validate - the output value should be set correctly by SQL Server + Assert.Equal(new decimal(1.23), (decimal)decimalParam.Value); } } } diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameter_DebugMode.bsl b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameter_DebugMode.bsl deleted file mode 100644 index 14ce4d701d..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameter_DebugMode.bsl +++ /dev/null @@ -1,3 +0,0 @@ -Starting 'OutputParameter' tests -Test setting output SqlParameter to an invalid value -Done diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameter_DebugMode_Azure.bsl b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameter_DebugMode_Azure.bsl deleted file mode 100644 index 14ce4d701d..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameter_DebugMode_Azure.bsl +++ /dev/null @@ -1,3 +0,0 @@ -Starting 'OutputParameter' tests -Test setting output SqlParameter to an invalid value -Done diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameter_ReleaseMode.bsl b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameter_ReleaseMode.bsl deleted file mode 100644 index 14ce4d701d..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameter_ReleaseMode.bsl +++ /dev/null @@ -1,3 +0,0 @@ -Starting 'OutputParameter' tests -Test setting output SqlParameter to an invalid value -Done diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameter_ReleaseMode_Azure.bsl b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameter_ReleaseMode_Azure.bsl deleted file mode 100644 index 14ce4d701d..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameter_ReleaseMode_Azure.bsl +++ /dev/null @@ -1,3 +0,0 @@ -Starting 'OutputParameter' tests -Test setting output SqlParameter to an invalid value -Done From 304931eae58a64122dd16ccedef9ad0fba4950a4 Mon Sep 17 00:00:00 2001 From: Malcolm Daigle Date: Mon, 2 Mar 2026 16:35:35 -0800 Subject: [PATCH 2/2] Cleanup --- .../SQL/ParameterTest/OutputParameterTests.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameterTests.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameterTests.cs index a599140d71..98e51b812d 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameterTests.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameterTests.cs @@ -12,13 +12,6 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests /// public class OutputParameterTests { - private readonly string _connStr; - - public OutputParameterTests() - { - _connStr = DataTestUtility.TCPConnectionString; - } - /// /// Tests that setting an output SqlParameter to an invalid value (e.g. a string in a decimal param) /// doesn't throw, since the value is cleared before execution starts. @@ -27,6 +20,7 @@ public OutputParameterTests() [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))] public void InvalidValueInOutputParameter_ShouldSucceed() { + // Arrange using var connection = new SqlConnection(DataTestUtility.TCPConnectionString); connection.Open(); @@ -46,9 +40,11 @@ public void InvalidValueInOutputParameter_ShouldSucceed() // Set value of param to invalid value (string instead of decimal) decimalParam.Value = "Not a decimal"; + // Act // Execute - should not throw command.ExecuteNonQuery(); + // Assert // Validate - the output value should be set correctly by SQL Server Assert.Equal(new decimal(1.23), (decimal)decimalParam.Value); }