Skip to content

Commit cea4d6c

Browse files
committed
Split baseline files.
1 parent 7ecc5b3 commit cea4d6c

31 files changed

Lines changed: 8853 additions & 14 deletions
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.IO;
7+
using System.Text;
8+
using Xunit;
9+
10+
namespace Microsoft.Data.SqlClient.ManualTesting.Tests
11+
{
12+
/// <summary>
13+
/// Tests for DateTime variant parameters with different date/time types.
14+
/// These tests run independently with their own baseline comparison.
15+
/// </summary>
16+
public class DateTimeVariantTests
17+
{
18+
private readonly string _connStr;
19+
20+
public DateTimeVariantTests()
21+
{
22+
_connStr = DataTestUtility.TCPConnectionString;
23+
}
24+
25+
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
26+
public void DateTimeVariantParameterTest()
27+
{
28+
Assert.True(RunTestAndCompareWithBaseline());
29+
}
30+
31+
private bool RunTestAndCompareWithBaseline()
32+
{
33+
string outputPath = "DateTimeVariant.out";
34+
string baselinePath;
35+
#if DEBUG
36+
if (DataTestUtility.IsNotAzureServer() || DataTestUtility.IsManagedInstance)
37+
{
38+
baselinePath = "DateTimeVariant_DebugMode.bsl";
39+
}
40+
else
41+
{
42+
baselinePath = "DateTimeVariant_DebugMode_Azure.bsl";
43+
}
44+
#else
45+
if (DataTestUtility.IsNotAzureServer() || DataTestUtility.IsManagedInstance)
46+
{
47+
baselinePath = "DateTimeVariant_ReleaseMode.bsl";
48+
}
49+
else
50+
{
51+
baselinePath = "DateTimeVariant_ReleaseMode_Azure.bsl";
52+
}
53+
#endif
54+
55+
var fstream = new FileStream(outputPath, FileMode.Create, FileAccess.Write, FileShare.Read);
56+
var swriter = new StreamWriter(fstream, Encoding.UTF8);
57+
var twriter = new TvpTest.CarriageReturnLineFeedReplacer(swriter);
58+
Console.SetOut(twriter);
59+
60+
// Run Test
61+
DateTimeVariantTest.TestAllDateTimeWithDataTypeAndVariant(_connStr);
62+
63+
Console.Out.Flush();
64+
Console.Out.Dispose();
65+
66+
// Recover the standard output stream
67+
StreamWriter standardOutput = new(Console.OpenStandardOutput());
68+
standardOutput.AutoFlush = true;
69+
Console.SetOut(standardOutput);
70+
71+
// Compare output file
72+
var comparisonResult = FindDiffFromBaseline(baselinePath, outputPath);
73+
74+
if (string.IsNullOrEmpty(comparisonResult))
75+
{
76+
return true;
77+
}
78+
79+
Console.WriteLine("DateTimeVariantParameterTest Failed!");
80+
Console.WriteLine("Please compare baseline: {0} with output: {1}", Path.GetFullPath(baselinePath), Path.GetFullPath(outputPath));
81+
Console.WriteLine("Comparison Results:");
82+
Console.WriteLine(comparisonResult);
83+
return false;
84+
}
85+
86+
private static string FindDiffFromBaseline(string baselinePath, string outputPath)
87+
{
88+
var expectedLines = File.ReadAllLines(baselinePath);
89+
var outputLines = File.ReadAllLines(outputPath);
90+
91+
var comparisonSb = new StringBuilder();
92+
93+
var expectedLength = expectedLines.Length;
94+
var outputLength = outputLines.Length;
95+
var findDiffLength = Math.Min(expectedLength, outputLength);
96+
97+
for (var lineNo = 0; lineNo < findDiffLength; lineNo++)
98+
{
99+
if (!expectedLines[lineNo].Equals(outputLines[lineNo]))
100+
{
101+
comparisonSb.AppendFormat("** DIFF at line {0} \n", lineNo);
102+
comparisonSb.AppendFormat("A : {0} \n", outputLines[lineNo]);
103+
comparisonSb.AppendFormat("E : {0} \n", expectedLines[lineNo]);
104+
}
105+
}
106+
107+
var startIndex = findDiffLength - 1;
108+
if (startIndex < 0)
109+
{
110+
startIndex = 0;
111+
}
112+
113+
if (findDiffLength < expectedLength)
114+
{
115+
comparisonSb.AppendFormat("** MISSING \n");
116+
for (var lineNo = startIndex; lineNo < expectedLength; lineNo++)
117+
{
118+
comparisonSb.AppendFormat("{0} : {1}", lineNo, expectedLines[lineNo]);
119+
}
120+
}
121+
if (findDiffLength < outputLength)
122+
{
123+
comparisonSb.AppendFormat("** EXTRA \n");
124+
for (var lineNo = startIndex; lineNo < outputLength; lineNo++)
125+
{
126+
comparisonSb.AppendFormat("{0} : {1}", lineNo, outputLines[lineNo]);
127+
}
128+
}
129+
130+
return comparisonSb.ToString();
131+
}
132+
}
133+
}

0 commit comments

Comments
 (0)