Skip to content
Open
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 @@ -199,6 +199,12 @@
<Compile Include="SQL\ParameterTest\StePermutationSet.cs" />
<Compile Include="SQL\ParameterTest\SteTypeBoundaries.cs" />
<Compile Include="SQL\ParameterTest\StreamInputParam.cs" />
<Compile Include="SQL\ParameterTest\StreamInputParameterTests.cs" />
<Compile Include="SQL\ParameterTest\TvpColumnBoundariesTests.cs" />
<Compile Include="SQL\ParameterTest\TvpQueryHintsTests.cs" />
<Compile Include="SQL\ParameterTest\SqlVariantParameterTests.cs" />
<Compile Include="SQL\ParameterTest\DateTimeVariantTests.cs" />
<Compile Include="SQL\ParameterTest\OutputParameterTests.cs" />
<Compile Include="SQL\ParameterTest\TvpTest.cs" />
<Compile Include="SQL\SplitPacketTest\SplitPacketTest.cs" />
<Compile Include="SQL\SqlCommand\SqlCommandCancelTest.cs" />
Expand Down Expand Up @@ -237,14 +243,104 @@
<!-- @TODO: Move these into some folder or a resx or something -->
<Content Include="DDDataTypesTest_Data.xml"
CopyToOutputDirectory="PreserveNewest" />
<Content Include="SqlParameterTest_DebugMode.bsl"
CopyToOutputDirectory="PreserveNewest" />
<Content Include="SqlParameterTest_DebugMode_Azure.bsl"
CopyToOutputDirectory="PreserveNewest" />
<Content Include="SqlParameterTest_ReleaseMode.bsl"
CopyToOutputDirectory="PreserveNewest" />
<Content Include="SqlParameterTest_ReleaseMode_Azure.bsl"
CopyToOutputDirectory="PreserveNewest" />

<!-- Split baseline files for individual test groups -->
<Content Include="SQL\ParameterTest\StreamInputParameter_DebugMode.bsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>StreamInputParameter_DebugMode.bsl</Link>
</Content>
<Content Include="SQL\ParameterTest\StreamInputParameter_DebugMode_Azure.bsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>StreamInputParameter_DebugMode_Azure.bsl</Link>
</Content>
<Content Include="SQL\ParameterTest\StreamInputParameter_ReleaseMode.bsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>StreamInputParameter_ReleaseMode.bsl</Link>
</Content>
<Content Include="SQL\ParameterTest\StreamInputParameter_ReleaseMode_Azure.bsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>StreamInputParameter_ReleaseMode_Azure.bsl</Link>
</Content>
<Content Include="SQL\ParameterTest\TvpColumnBoundaries_DebugMode.bsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>TvpColumnBoundaries_DebugMode.bsl</Link>
</Content>
<Content Include="SQL\ParameterTest\TvpColumnBoundaries_DebugMode_Azure.bsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>TvpColumnBoundaries_DebugMode_Azure.bsl</Link>
</Content>
<Content Include="SQL\ParameterTest\TvpColumnBoundaries_ReleaseMode.bsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>TvpColumnBoundaries_ReleaseMode.bsl</Link>
</Content>
<Content Include="SQL\ParameterTest\TvpColumnBoundaries_ReleaseMode_Azure.bsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>TvpColumnBoundaries_ReleaseMode_Azure.bsl</Link>
</Content>
<Content Include="SQL\ParameterTest\TvpQueryHints_DebugMode.bsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>TvpQueryHints_DebugMode.bsl</Link>
</Content>
<Content Include="SQL\ParameterTest\TvpQueryHints_DebugMode_Azure.bsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>TvpQueryHints_DebugMode_Azure.bsl</Link>
</Content>
<Content Include="SQL\ParameterTest\TvpQueryHints_ReleaseMode.bsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>TvpQueryHints_ReleaseMode.bsl</Link>
</Content>
<Content Include="SQL\ParameterTest\TvpQueryHints_ReleaseMode_Azure.bsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>TvpQueryHints_ReleaseMode_Azure.bsl</Link>
</Content>
<Content Include="SQL\ParameterTest\SqlVariantParameter_DebugMode.bsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>SqlVariantParameter_DebugMode.bsl</Link>
</Content>
<Content Include="SQL\ParameterTest\SqlVariantParameter_DebugMode_Azure.bsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>SqlVariantParameter_DebugMode_Azure.bsl</Link>
</Content>
<Content Include="SQL\ParameterTest\SqlVariantParameter_ReleaseMode.bsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>SqlVariantParameter_ReleaseMode.bsl</Link>
</Content>
<Content Include="SQL\ParameterTest\SqlVariantParameter_ReleaseMode_Azure.bsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>SqlVariantParameter_ReleaseMode_Azure.bsl</Link>
</Content>
<Content Include="SQL\ParameterTest\DateTimeVariant_DebugMode.bsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>DateTimeVariant_DebugMode.bsl</Link>
</Content>
<Content Include="SQL\ParameterTest\DateTimeVariant_DebugMode_Azure.bsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>DateTimeVariant_DebugMode_Azure.bsl</Link>
</Content>
<Content Include="SQL\ParameterTest\DateTimeVariant_ReleaseMode.bsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>DateTimeVariant_ReleaseMode.bsl</Link>
</Content>
<Content Include="SQL\ParameterTest\DateTimeVariant_ReleaseMode_Azure.bsl">
<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
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// 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.Globalization;
using System.IO;
using System.Text;
using System.Threading;
using Xunit;

namespace Microsoft.Data.SqlClient.ManualTesting.Tests
{
/// <summary>
/// Tests for DateTime variant parameters with different date/time types.
/// These tests run independently with their own baseline comparison.
/// </summary>
[Collection("ParameterBaselineTests")]
public class DateTimeVariantTests
{
private readonly string _connStr;

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

[Trait("Category", "flaky")]
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
public void DateTimeVariantParameterTest()
{
Assert.True(RunTestAndCompareWithBaseline());
}
Comment on lines +28 to +33
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original monolithic TvpTest.TestMain forced Thread.CurrentThread.CurrentCulture to en-US to keep date/time string output stable for baseline comparisons. After splitting, this test no longer sets culture, so baselines can become machine-locale dependent. Set the culture (and ideally restore the previous culture in a try/finally) before running the test logic.

Copilot uses AI. Check for mistakes.

private bool RunTestAndCompareWithBaseline()
{
CultureInfo previousCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
try
{
string outputPath = "DateTimeVariant.out";
string baselinePath;
#if DEBUG
if (DataTestUtility.IsNotAzureServer() || DataTestUtility.IsManagedInstance)
{
baselinePath = "DateTimeVariant_DebugMode.bsl";
}
else
{
baselinePath = "DateTimeVariant_DebugMode_Azure.bsl";
}
#else
if (DataTestUtility.IsNotAzureServer() || DataTestUtility.IsManagedInstance)
{
baselinePath = "DateTimeVariant_ReleaseMode.bsl";
}
else
{
baselinePath = "DateTimeVariant_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
DateTimeVariantTest.TestAllDateTimeWithDataTypeAndVariant(_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("DateTimeVariantParameterTest 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);

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]);
}
}

return comparisonSb.ToString();
}
}
}
Loading
Loading