-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8260bd6
commit 8f73a4a
Showing
6 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# MSTest.TestFramework | ||
|
||
MSTest is Microsoft supported Test Framework. | ||
|
||
This package includes the functionality needed for writing Csv-based data source unit tests. | ||
|
||
Supported platforms: | ||
|
||
- .NET Standard 2.0 |
1 change: 1 addition & 0 deletions
1
src/TestFramework/TestFramework.Extensions.Xml/PublicAPI/PublicAPI.Shipped.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#nullable enable |
3 changes: 3 additions & 0 deletions
3
src/TestFramework/TestFramework.Extensions.Xml/PublicAPI/PublicAPI.Unshipped.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#nullable enable | ||
Microsoft.VisualStudio.TestTools.UnitTesting.XmlDataSourceAttribute | ||
Microsoft.VisualStudio.TestTools.UnitTesting.XmlDataSourceAttribute.XmlDataSourceAttribute(string! fileName, string! tableName) -> void |
39 changes: 39 additions & 0 deletions
39
src/TestFramework/TestFramework.Extensions.Xml/TestFramework.Extensions.Xml.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<!-- TODO: (before merge) Is this hack relevant for a new project? --> | ||
<UseAssemblyVersion14>true</UseAssemblyVersion14> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<IsPackable>true</IsPackable> | ||
<PackageId>MSTest.TestFramework.Xml</PackageId> | ||
<PackageTags>MSTest TestFramework Unittest MSTestV2 Microsoft Test Testing TDD Framework</PackageTags> | ||
<PackageDescription> | ||
MSTest is Microsoft supported Test Framework. | ||
|
||
This package includes the functionality needed for writing Xml-based data source unit tests. | ||
|
||
Supported platforms: | ||
- .NET Standard 2.0 | ||
</PackageDescription> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<RootNamespace>Microsoft.VisualStudio.TestTools.UnitTesting</RootNamespace> | ||
<!-- TODO: Discuss the assembly name before shipping/merging --> | ||
<AssemblyName>Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.Xml</AssemblyName> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="$(RepoRoot)src\TestFramework\TestFramework.Extensions\TestFramework.Extensions.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<!-- API that is common to all frameworks that we build for. --> | ||
<AdditionalFiles Include="PublicAPI\PublicAPI.Shipped.txt" /> | ||
<AdditionalFiles Include="PublicAPI\PublicAPI.Unshipped.txt" /> | ||
</ItemGroup> | ||
|
||
</Project> |
58 changes: 58 additions & 0 deletions
58
src/TestFramework/TestFramework.Extensions.Xml/XmlDataSourceAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Data; | ||
using System.Globalization; | ||
using System.Reflection; | ||
using System.Xml; | ||
|
||
namespace Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
/// <summary> | ||
/// Attribute to define dynamic data from an XML file for a test method. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false/*TODO: Do we want to allow multiple*/)] | ||
public sealed class XmlDataSourceAttribute : Attribute, ITestDataSource | ||
{ | ||
public XmlDataSourceAttribute(string fileName, string tableName) | ||
{ | ||
FileName = fileName; | ||
TableName = tableName; | ||
} | ||
|
||
internal string FileName { get; } | ||
|
||
internal string TableName { get; } | ||
|
||
IEnumerable<object?[]> ITestDataSource.GetData(MethodInfo methodInfo) | ||
{ | ||
string fullPath = Path.GetFullPath(FileName); | ||
if (!File.Exists(fullPath)) | ||
{ | ||
// TODO: Localize. | ||
throw new FileNotFoundException($"Xml file '{fullPath}' cannot be found.", fullPath); | ||
} | ||
|
||
DataSet dataSet = new() | ||
{ | ||
Locale = CultureInfo.CurrentCulture, | ||
}; | ||
|
||
// ReadXml should use the overload with XmlReader to avoid DTD processing | ||
dataSet.ReadXml(new XmlTextReader(fullPath)); | ||
|
||
DataTable table = dataSet.Tables[TableName]; | ||
|
||
object?[][] dataRows = new object?[table.Rows.Count][]; | ||
for (int i = 0; i < dataRows.Length; i++) | ||
{ | ||
dataRows[i] = [table.Rows[i]]; | ||
} | ||
|
||
return dataRows; | ||
} | ||
|
||
string? ITestDataSource.GetDisplayName(MethodInfo methodInfo, object?[]? data) | ||
// TODO | ||
=> null; | ||
} |