Skip to content
Draft
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 @@ -462,4 +462,72 @@ public void TestMethod1()

await VerifyCS.VerifyCodeFixAsync(code, fixedCode);
}

[TestMethod]
public async Task WhenNonTestClassHasDataTestMethod_Diagnostic()
{
string code = """
using Microsoft.VisualStudio.TestTools.UnitTesting;

public class [|MyTestClass|]
{
[DataTestMethod]
[DataRow(1)]
public void TestMethod1(int value) {}
}
""";

string fixedCode = """
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class MyTestClass
{
[DataTestMethod]
[DataRow(1)]
public void TestMethod1(int value) {}
}
""";

await VerifyCS.VerifyCodeFixAsync(code, fixedCode);
}

[TestMethod]
public async Task WhenNonTestClassInheritsDataTestMethodFromAbstractBase_Diagnostic()
{
// Abstract base is exempt from the diagnostic; derived non-test class
// that inherits [DataTestMethod] via the inheritance walk should fire.
string code = """
using Microsoft.VisualStudio.TestTools.UnitTesting;

public abstract class AbstractBase
{
[DataTestMethod]
[DataRow(1)]
public void TestMethod1(int value) {}
}

public class [|MyTestClass|] : AbstractBase
{
}
""";

string fixedCode = """
using Microsoft.VisualStudio.TestTools.UnitTesting;

public abstract class AbstractBase
{
[DataTestMethod]
[DataRow(1)]
public void TestMethod1(int value) {}
}

[TestClass]
public class MyTestClass : AbstractBase
{
}
""";

await VerifyCS.VerifyCodeFixAsync(code, fixedCode);
}
}