Skip to content

Commit

Permalink
Allow public override methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
manfred-brands committed Nov 28, 2023
1 parent a2b2f82 commit 1812172
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,21 @@ public override void Dispose() { }

RoslynAssert.Valid(analyzer, testCode);
}

[Test]
public void AnalyzeWhenMethodIsBaseClassOverride()
{
var testCode = TestUtility.WrapClassInNamespaceAndAddUsing(@"
public sealed class MyTestClass
{
[Test]
public void TestMethod() { }
public override string ToString() => ""My Test Class"";
}
");

RoslynAssert.Valid(analyzer, testCode);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private static void AnalyzeType(SymbolAnalysisContext context)
{
if (method.IsTestRelatedMethod(context.Compilation))
hasTestMethods = true;
else if (IsPublicOrInternalMethod(method) && !IsDisposeMethod(method))
else if (IsPublicOrInternalMethod(method) && !IsOverride(method) && !IsDisposeMethod(method))
publicNonTestMethods.Add(method);
}

Expand Down Expand Up @@ -74,13 +74,13 @@ private static bool IsPublicOrInternalMethod(IMethodSymbol method)
}
}

private static bool IsDisposeMethod(IMethodSymbol method)
private static bool IsOverride(IMethodSymbol method)
{
if (method.OverriddenMethod is not null)
{
return IsDisposeMethod(method.OverriddenMethod);
}
return method.IsOverride;
}

private static bool IsDisposeMethod(IMethodSymbol method)
{
return method.IsInterfaceImplementation("System.IDisposable");
}
}
Expand Down

0 comments on commit 1812172

Please sign in to comment.