Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@
<Compile Include="SQL\MirroringTest\ConnectionOnMirroringTest.cs" />
<Compile Include="SQL\ParallelTransactionsTest\ParallelTransactionsTest.cs" />
<Compile Include="SQL\ParameterTest\DateTimeVariantTest.cs" />
<Compile Include="SQL\ParameterTest\OutputParameter.cs" />
<Compile Include="SQL\ParameterTest\ParametersTest.cs" />
<Compile Include="SQL\ParameterTest\SqlAdapterUpdateBatch.cs" />
<Compile Include="SQL\ParameterTest\SqlVariantParam.cs" />
Expand Down Expand Up @@ -326,22 +325,6 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>DateTimeVariant_ReleaseMode_Azure.bsl</Link>
</Content>
<Content Include="SQL\ParameterTest\OutputParameter_DebugMode.bsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>OutputParameter_DebugMode.bsl</Link>
</Content>
<Content Include="SQL\ParameterTest\OutputParameter_DebugMode_Azure.bsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>OutputParameter_DebugMode_Azure.bsl</Link>
</Content>
<Content Include="SQL\ParameterTest\OutputParameter_ReleaseMode.bsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>OutputParameter_ReleaseMode.bsl</Link>
</Content>
<Content Include="SQL\ParameterTest\OutputParameter_ReleaseMode_Azure.bsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>OutputParameter_ReleaseMode_Azure.bsl</Link>
</Content>
</ItemGroup>

<!-- Items to include in AE test set -->
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/// <summary>
/// Tests for output parameters.
/// These tests run independently with their own baseline comparison.
/// </summary>
[Collection("ParameterBaselineTests")]
public class OutputParameterTests
{
private readonly string _connStr;

public OutputParameterTests()
{
_connStr = DataTestUtility.TCPConnectionString;
}

[Trait("Category", "flaky")]
/// <summary>
/// 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.
/// </summary>
[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);
}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading