Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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,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
{
/// <summary>
/// Tests for output parameters.
/// These tests run independently with their own baseline comparison.
/// </summary>
[Collection("ParameterBaselineTests")]
Comment thread
mdaigle marked this conversation as resolved.
public class OutputParameterTests
{
private readonly string _connStr;
Expand All @@ -25,122 +19,38 @@ public OutputParameterTests()
_connStr = DataTestUtility.TCPConnectionString;
}

[Trait("Category", "flaky")]
Comment thread
mdaigle marked this conversation as resolved.
/// <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()
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))
{
Comment thread
mdaigle marked this conversation as resolved.
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);
Comment thread
mdaigle marked this conversation as resolved.
}
}
}
Comment thread
mdaigle marked this conversation as resolved.
Outdated

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading