[go: nahoru, domu]

Skip to content

Commit

Permalink
[rel/3.6] Fix MSTEST0030 to correctly handle all methods (#3974)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink authored Oct 30, 2024
1 parent b170f00 commit d0b9266
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private static void AnalyzeSymbol(SymbolAnalysisContext context, INamedTypeSymbo

bool hasTestMethod = false;
INamedTypeSymbol? currentType = namedTypeSymbol;
do
while (currentType is not null && !hasTestMethod)
{
foreach (ISymbol classMember in currentType.GetMembers())
{
Expand All @@ -94,16 +94,10 @@ private static void AnalyzeSymbol(SymbolAnalysisContext context, INamedTypeSymbo
break;
}
}

if (!hasTestMethod)
{
break;
}
}

currentType = currentType.BaseType;
}
while (currentType is not null && !hasTestMethod);

if (!hasTestMethod)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,28 @@ public void TestMethod1()

await VerifyCS.VerifyAnalyzerAsync(code);
}

public async Task WhenClassHasTestInitializeAndThenTestMethod_Diagnostic()
{
string code = """
using Microsoft.VisualStudio.TestTools.UnitTesting;

public class [|TestClass|]
{
[TestInitialize]
public void Initialize()
{

}

[TestMethod]
public void TestMethod1()
{

}
}
""";

await VerifyCS.VerifyAnalyzerAsync(code);
}
}

0 comments on commit d0b9266

Please sign in to comment.