Skip to content

Commit 030ba31

Browse files
committed
Use runtime-assets test files for Text and SQL Binary XML tests
1 parent 9d08eb9 commit 030ba31

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+78
-213
lines changed

eng/Versions.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
<!-- Runtime-Assets dependencies -->
150150
<SystemRuntimeNumericsTestDataVersion>8.0.0-beta.23107.1</SystemRuntimeNumericsTestDataVersion>
151151
<SystemComponentModelTypeConverterTestDataVersion>8.0.0-beta.23107.1</SystemComponentModelTypeConverterTestDataVersion>
152+
<SystemDataCommonTestDataVersion>8.0.0-dev</SystemDataCommonTestDataVersion>
152153
<SystemDrawingCommonTestDataVersion>8.0.0-beta.23107.1</SystemDrawingCommonTestDataVersion>
153154
<SystemFormatsTarTestDataVersion>8.0.0-beta.23107.1</SystemFormatsTarTestDataVersion>
154155
<SystemIOCompressionTestDataVersion>8.0.0-beta.23107.1</SystemIOCompressionTestDataVersion>

src/libraries/System.Data.Common/tests/System.Data.Common.Tests.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,9 @@
119119
<Compile Include="$(CommonTestPath)System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs"
120120
Link="Common\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs" />
121121
</ItemGroup>
122-
<ItemGroup>
123-
<Content Include="TestFiles\**\*" Link="TestFiles\%(RecursiveDir)%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
124-
</ItemGroup>
125122
<!-- S.D.SqlClient isn't live built anymore. -->
126123
<ItemGroup>
124+
<PackageReference Include="System.Data.Common.TestData" Version="$(SystemDataCommonTestDataVersion)" />
127125
<PackageReference Include="System.Data.SqlClient" Version="$(SystemDataSqlClientVersion)" />
128126
</ItemGroup>
129127
</Project>

src/libraries/System.Data.Common/tests/System/Data/SqlTypes/SqlXmlTest.cs

Lines changed: 76 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Collections;
5+
using System.Collections.Generic;
46
using System.Data.SqlTypes;
57
using System.IO;
8+
using System.Linq;
69
using System.Text;
710
using System.Xml;
811

@@ -13,7 +16,7 @@ namespace System.Data.Tests.SqlTypes
1316
public class SqlXmlTest
1417
{
1518
[Fact]
16-
public void Constructor2_Stream_Unicode()
19+
public void Constructor_Stream_Unicode()
1720
{
1821
string xmlStr = "<Employee><FirstName>Varadhan</FirstName><LastName>Veerapuram</LastName></Employee>";
1922
MemoryStream stream = new MemoryStream(Encoding.Unicode.GetBytes(xmlStr));
@@ -23,7 +26,7 @@ public void Constructor2_Stream_Unicode()
2326
}
2427

2528
[Fact]
26-
public void Constructor2_Stream_Empty()
29+
public void Constructor_Stream_Empty()
2730
{
2831
MemoryStream ms = new MemoryStream();
2932
SqlXml xmlSql = new SqlXml(ms);
@@ -32,7 +35,7 @@ public void Constructor2_Stream_Empty()
3235
}
3336

3437
[Fact]
35-
public void Constructor2_Stream_Null()
38+
public void Constructor_Stream_Null()
3639
{
3740
SqlXml xmlSql = new SqlXml((Stream)null);
3841
Assert.True(xmlSql.IsNull);
@@ -41,7 +44,7 @@ public void Constructor2_Stream_Null()
4144
}
4245

4346
[Fact]
44-
public void Constructor3()
47+
public void Constructor_StringReader()
4548
{
4649
string xmlStr = "<Employee><FirstName>Varadhan</FirstName><LastName>Veerapuram</LastName></Employee>";
4750
XmlReader xrdr = new XmlTextReader(new StringReader(xmlStr));
@@ -51,7 +54,7 @@ public void Constructor3()
5154
}
5255

5356
[Fact]
54-
public void Constructor3_XmlReader_Empty()
57+
public void Constructor_XmlReader_Empty()
5558
{
5659
XmlReaderSettings xs = new XmlReaderSettings();
5760
xs.ConformanceLevel = ConformanceLevel.Fragment;
@@ -62,7 +65,7 @@ public void Constructor3_XmlReader_Empty()
6265
}
6366

6467
[Fact]
65-
public void Constructor3_XmlReader_Null()
68+
public void Constructor_XmlReader_Null()
6669
{
6770
SqlXml xmlSql = new SqlXml((XmlReader)null);
6871
Assert.True(xmlSql.IsNull);
@@ -84,7 +87,7 @@ public void CreateReader_Stream_Unicode()
8487
}
8588

8689
[Fact]
87-
public void SqlXml_fromXmlReader_CreateReaderTest()
90+
public void CreateReader_XmlTextReader_CanReadContent()
8891
{
8992
string xmlStr = "<Employee><FirstName>Varadhan</FirstName><LastName>Veerapuram</LastName></Employee>";
9093
XmlReader rdr = new XmlTextReader(new StringReader(xmlStr));
@@ -96,84 +99,82 @@ public void SqlXml_fromXmlReader_CreateReaderTest()
9699
Assert.Equal(xmlStr, xrdr.ReadOuterXml());
97100
}
98101

99-
[Theory]
100-
[InlineData("element_whitespace-text.xml")]
101-
[InlineData("root_qname.xml")]
102-
[InlineData("sample_ecommerce.xml")]
103-
[InlineData("sql_batch_request.xml")]
104-
[InlineData("sql_batch_response.xml")]
105-
[InlineData("sql_datatypes-1.xml")]
106-
[InlineData("sql_datatypes-2.xml")]
107-
[InlineData("sql_datatypes-3.xml")]
108-
[InlineData("xmlns-1.xml")]
109-
[InlineData("xmlns-2.xml")]
110-
[InlineData("xmlns-3.xml")]
111-
[InlineData("xmlns-4.xml")]
112-
[InlineData("comments_pis.xml")]
113-
[InlineData("element_content_growth.xml")]
114-
[InlineData("element_nested-1.xml")]
115-
[InlineData("element_nested-2.xml")]
116-
[InlineData("element_nested-3.xml")]
117-
[InlineData("element_single.xml")]
118-
[InlineData("element_stack_growth.xml")]
119-
[InlineData("element_tagname_growth.xml")]
120-
[InlineData("element_types.xml")]
121-
[InlineData("element_whitespace-modes.xml")]
122-
public void SqlXml_fromXmlReader_TextXml(string filename)
102+
public static class CreateReader_TestFiles
123103
{
124-
string filepath = Path.Combine("TestFiles/SqlXml/TextXml", filename);
125-
126-
using FileStream xmlStream = new FileStream(filepath, FileMode.Open);
127-
SqlXml sqlXml = new SqlXml(xmlStream);
128-
129-
// Reading XML stored as SQL Binary XML will result in using
130-
// the XmlTextReader implementation
131-
using XmlReader sqlXmlReader = sqlXml.CreateReader();
132-
133-
// Read to the end to verify no exceptions are thrown
134-
while(sqlXmlReader.Read());
104+
private static TheoryData<string, string> _filesAndBaselines;
105+
106+
// The test files are made available through the System.Data.Common.TestData package included in dotnet/runtime-assets
107+
private static void EnsureFileList()
108+
{
109+
if (_filesAndBaselines is null)
110+
{
111+
IEnumerable<string> text = Directory.EnumerateFiles(Path.Combine("SqlXml.CreateReader", "Baseline-Text"), "*.xml");
112+
IEnumerable<string> binary = Directory.EnumerateFiles(Path.Combine("SqlXml.CreateReader", "SqlBinaryXml"), "*.bmx");
113+
114+
// Make sure that we found our test files; otherwise the theories would succeed without validating anything
115+
Assert.NotEmpty(text);
116+
Assert.NotEmpty(binary);
117+
118+
TheoryData<string, string> filesAndBaselines = new TheoryData<string, string>();
119+
120+
// Use the Text XML files as their own baselines
121+
filesAndBaselines.Append(text.Select(f => new string[] { TextXmlFileName(f), TextXmlFileName(f) }).ToArray());
122+
123+
// Use the matching Text XML files as the baselines for the SQL Binary XML files
124+
filesAndBaselines.Append(binary
125+
.Select(Path.GetFileNameWithoutExtension)
126+
.Intersect(text.Select(Path.GetFileNameWithoutExtension))
127+
.Select(f => new string[] { SqlBinaryXmlFileName(f), TextXmlFileName(f) }).ToArray());
128+
129+
_filesAndBaselines = filesAndBaselines;
130+
131+
string TextXmlFileName(string name) => Path.Combine("SqlXml.CreateReader", "Baseline-Text", $"{name}.xml");
132+
string SqlBinaryXmlFileName(string name) => Path.Combine("SqlXml.CreateReader", "SqlBinaryXml", $"{name}.bmx");
133+
}
134+
}
135+
136+
public static TheoryData<string, string> FilesAndBaselines
137+
{
138+
get
139+
{
140+
EnsureFileList();
141+
return _filesAndBaselines;
142+
}
143+
}
144+
145+
public static string ReadAllXml(XmlReader reader)
146+
{
147+
using StringWriter writer = new StringWriter();
148+
using XmlWriter xmlWriter = new XmlTextWriter(writer);
149+
150+
while (reader.Read()) xmlWriter.WriteNode(reader, false);
151+
152+
return writer.ToString();
153+
}
135154
}
136155

137156
[Theory]
138-
[InlineData("element_whitespace-text.bmx")]
139-
[InlineData("root_qname.bmx")]
140-
[InlineData("sample_ecommerce.bmx")]
141-
[InlineData("sql_batch_request.bmx")]
142-
[InlineData("sql_batch_response.bmx")]
143-
[InlineData("sql_datatypes-1.bmx")]
144-
[InlineData("sql_datatypes-2.bmx")]
145-
[InlineData("sql_datatypes-3.bmx")]
146-
[InlineData("xmlns-1.bmx")]
147-
[InlineData("xmlns-2.bmx")]
148-
[InlineData("xmlns-3.bmx")]
149-
[InlineData("xmlns-4.bmx")]
150-
[InlineData("comments_pis.bmx")]
151-
[InlineData("element_content_growth.bmx")]
152-
[InlineData("element_nested-1.bmx")]
153-
[InlineData("element_nested-2.bmx")]
154-
[InlineData("element_nested-3.bmx")]
155-
[InlineData("element_single.bmx")]
156-
[InlineData("element_stack_growth.bmx")]
157-
[InlineData("element_tagname_growth.bmx")]
158-
[InlineData("element_types.bmx")]
159-
[InlineData("element_whitespace-modes.bmx")]
160-
public void SqlXml_fromXmlReader_SqlBinaryXml(string filename)
157+
[MemberData(nameof(CreateReader_TestFiles.FilesAndBaselines), MemberType = typeof(CreateReader_TestFiles))]
158+
public void CreateReader_TestAgainstBaseline(string testFile, string baselineFile)
161159
{
162-
string filepath = Path.Combine("TestFiles/SqlXml/SqlBinaryXml", filename);
160+
// Get our expected output by using XmlReader directly
161+
using XmlReader baselineReader = XmlReader.Create(baselineFile);
162+
string expected = CreateReader_TestFiles.ReadAllXml(baselineReader);
163163

164-
using FileStream xmlStream = new FileStream(filepath, FileMode.Open);
164+
// Now produce the actual output through SqlXml.CreateReader
165+
using FileStream xmlStream = new FileStream(testFile, FileMode.Open);
165166
SqlXml sqlXml = new SqlXml(xmlStream);
166167

167-
// Reading XML stored as SQL Binary XML will result in using
168-
// the XmlSqlBinaryReader implementation
169-
using XmlReader sqlXmlReader = sqlXml.CreateReader();
168+
// When the input is text, an XmlTextReader will be returned
169+
// When the input is SQL Binary XML, an XmlSqlBinaryReader will be returned
170+
using XmlReader actualReader = sqlXml.CreateReader();
171+
string actual = CreateReader_TestFiles.ReadAllXml(actualReader);
170172

171-
// Read to the end to verify no exceptions are thrown
172-
while(sqlXmlReader.Read());
173+
Assert.Equal(expected, actual);
173174
}
174175

175176
[Fact]
176-
public void SqlXml_fromZeroLengthStream_CreateReaderTest()
177+
public void SqlXml_FromZeroLengthStream_CreateReaderTest()
177178
{
178179
MemoryStream stream = new MemoryStream();
179180
SqlXml xmlSql = new SqlXml(stream);
@@ -184,7 +185,7 @@ public void SqlXml_fromZeroLengthStream_CreateReaderTest()
184185
}
185186

186187
[Fact]
187-
public void SqlXml_fromZeroLengthXmlReader_CreateReaderTest_withFragment()
188+
public void SqlXml_FromZeroLengthXmlReader_CreateReaderTest_withFragment()
188189
{
189190
XmlReaderSettings xs = new XmlReaderSettings();
190191
xs.ConformanceLevel = ConformanceLevel.Fragment;
@@ -198,7 +199,7 @@ public void SqlXml_fromZeroLengthXmlReader_CreateReaderTest_withFragment()
198199
}
199200

200201
[Fact]
201-
public void SqlXml_fromZeroLengthXmlReader_CreateReaderTest()
202+
public void SqlXml_FromZeroLengthXmlReader_CreateReaderTest()
202203
{
203204
XmlReader rdr = new XmlTextReader(new StringReader(string.Empty));
204205

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

src/libraries/System.Data.Common/tests/TestFiles/SqlXml/TextXml/comments_pis.xml

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/libraries/System.Data.Common/tests/TestFiles/SqlXml/TextXml/element_content_growth.xml

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/libraries/System.Data.Common/tests/TestFiles/SqlXml/TextXml/element_nested-1.xml

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/libraries/System.Data.Common/tests/TestFiles/SqlXml/TextXml/element_nested-2.xml

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/libraries/System.Data.Common/tests/TestFiles/SqlXml/TextXml/element_nested-3.xml

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/libraries/System.Data.Common/tests/TestFiles/SqlXml/TextXml/element_single.xml

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/libraries/System.Data.Common/tests/TestFiles/SqlXml/TextXml/element_stack_growth.xml

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)