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..98e51b812d 100644
--- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameterTests.cs
+++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/OutputParameterTests.cs
@@ -2,145 +2,51 @@
// 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;
-
- 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()
- {
- 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);
-
- // Compare output file
- var comparisonResult = FindDiffFromBaseline(baselinePath, outputPath);
-
- if (string.IsNullOrEmpty(comparisonResult))
- {
- return true;
- }
-
- 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)
+ public void InvalidValueInOutputParameter_ShouldSucceed()
{
- var expectedLines = File.ReadAllLines(baselinePath);
- var outputLines = File.ReadAllLines(outputPath);
-
- var comparisonSb = new StringBuilder();
+ // Arrange
+ using var connection = new SqlConnection(DataTestUtility.TCPConnectionString);
+ connection.Open();
- var expectedLength = expectedLines.Length;
- var outputLength = outputLines.Length;
- var findDiffLength = Math.Min(expectedLength, outputLength);
+ // Command simply sets the output param
+ using var command = new SqlCommand("SET @decimal = 1.23", connection);
- for (var lineNo = 0; lineNo < findDiffLength; lineNo++)
+ // Create valid param
+ var decimalParam = new SqlParameter("decimal", new decimal(2.34))
{
- 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]);
- }
- }
+ SqlDbType = SqlDbType.Decimal,
+ Direction = ParameterDirection.Output,
+ Scale = 2,
+ Precision = 5
+ };
+ command.Parameters.Add(decimalParam);
- var startIndex = findDiffLength - 1;
- if (startIndex < 0)
- {
- startIndex = 0;
- }
+ // Set value of param to invalid value (string instead of decimal)
+ decimalParam.Value = "Not a decimal";
- 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]);
- }
- }
+ // Act
+ // Execute - should not throw
+ command.ExecuteNonQuery();
- return comparisonSb.ToString();
+ // Assert
+ // 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