Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DataRowAttribute to be cls compliant #1878

Merged
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
8 changes: 8 additions & 0 deletions TestFx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,11 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSTest.Analyzers.Package", "src\Analyzers\MSTest.Analyzers.Package\MSTest.Analyzers.Package.csproj", "{DC068986-7549-4B75-8EFC-A9958FD5CF88}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSTest.Analyzers.Test", "test\UnitTests\MSTest.Analyzers.Test\MSTest.Analyzers.Test.csproj", "{1FF35C23-C128-4C95-B3F8-67B1B4C51E4D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSTest.Sdk", "src\Package\MSTest.Sdk\MSTest.Sdk.csproj", "{10930CFD-EDF9-4486-B0A3-49230B5A6798}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClsTestProject", "test\IntegrationTests\TestAssets\ClsTestProject\ClsTestProject.csproj", "{100CF515-8291-45FF-9FFD-2A9064FECC72}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -386,6 +389,10 @@ Global
{10930CFD-EDF9-4486-B0A3-49230B5A6798}.Debug|Any CPU.Build.0 = Debug|Any CPU
{10930CFD-EDF9-4486-B0A3-49230B5A6798}.Release|Any CPU.ActiveCfg = Release|Any CPU
{10930CFD-EDF9-4486-B0A3-49230B5A6798}.Release|Any CPU.Build.0 = Release|Any CPU
{100CF515-8291-45FF-9FFD-2A9064FECC72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{100CF515-8291-45FF-9FFD-2A9064FECC72}.Debug|Any CPU.Build.0 = Debug|Any CPU
{100CF515-8291-45FF-9FFD-2A9064FECC72}.Release|Any CPU.ActiveCfg = Release|Any CPU
{100CF515-8291-45FF-9FFD-2A9064FECC72}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -455,6 +462,7 @@ Global
{DC068986-7549-4B75-8EFC-A9958FD5CF88} = {E7F15C9C-3928-47AD-8462-64FD29FFCA54}
{1FF35C23-C128-4C95-B3F8-67B1B4C51E4D} = {BB874DF1-44FE-415A-B634-A6B829107890}
{10930CFD-EDF9-4486-B0A3-49230B5A6798} = {E374A3A6-C364-4890-B315-D60F5C682B6E}
{100CF515-8291-45FF-9FFD-2A9064FECC72} = {C9F82701-0E0F-4E61-B05B-AE387E7631F6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {31E0F4D5-975A-41CC-933E-545B2201FAF9}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@ public DataRowAttribute()
}

/// <summary>
/// Initializes a new instance of the <see cref="DataRowAttribute"/> class.
/// Initializes a new instance of the <see cref="DataRowAttribute"/> class with an array of object arguments.
/// </summary>
/// <param name="data"> The data. </param>
/// <remarks>This constructor is only kept for CLS compliant tests.</remarks>
public DataRowAttribute(object? data)
{
Data = data is not null ? [data] : [null];
}

/// <summary>
/// Initializes a new instance of the <see cref="DataRowAttribute"/> class with an array of string arguments.
/// </summary>
/// <param name="stringArrayData"> The string array data. </param>
public DataRowAttribute(string?[]? stringArrayData)
Expand All @@ -30,7 +40,7 @@ public DataRowAttribute(string?[]? stringArrayData)
}

/// <summary>
/// Initializes a new instance of the <see cref="DataRowAttribute"/> class which takes in an array of arguments.
/// Initializes a new instance of the <see cref="DataRowAttribute"/> class with an array of object arguments.
/// </summary>
/// <param name="data"> The data. </param>
public DataRowAttribute(params object?[]? data)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute.DataRowAttribute(object? data) -> void
28 changes: 28 additions & 0 deletions test/IntegrationTests/MSTest.IntegrationTests/ClsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.MSTestV2.CLIAutomation;

namespace MSTest.IntegrationTests;

public class ClsTests : CLITestBase
{
private const string TestAssetName = "ClsTestProject";

public void TestsAreRun()
{
// Arrange
var assemblyPath = GetAssetFullPath(TestAssetName);

// Act
var testCases = DiscoverTests(assemblyPath);
var testResults = RunTests(testCases);

// Assert
VerifyE2E.TestsPassed(
testResults,
"TestMethod",
"IntDataRow (10)",
"StringDataRow (some string)");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net462</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)src\Adapter\MSTest.TestAdapter\MSTest.TestAdapter.csproj" />
</ItemGroup>

</Project>
34 changes: 34 additions & 0 deletions test/IntegrationTests/TestAssets/ClsTestProject/MyTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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;

using Microsoft.VisualStudio.TestTools.UnitTesting;

[assembly: CLSCompliant(true)]

namespace DataRowTestProject;

[TestClass]
public class ClsTests
{
[TestMethod]
public void TestMethod()
{
Assert.IsTrue(true);
}

[TestMethod]
[DataRow(10)]
public void IntDataRow(int i)
{
Assert.IsTrue(i != 0);
}

[TestMethod]
[DataRow("some string")]
public void StringDataRow(string s)
{
Assert.IsNotNull(s);
}
}