Ignore constructors when discovering actions
This commit is contained in:
parent
f3ffdada95
commit
5af246b554
|
|
@ -54,6 +54,7 @@ namespace Microsoft.AspNetCore.Mvc.Analyzers
|
|||
return
|
||||
method.ContainingType.HasAttribute(ApiControllerAttribute, inherit: true) &&
|
||||
method.DeclaredAccessibility == Accessibility.Public &&
|
||||
method.MethodKind == MethodKind.Ordinary &&
|
||||
!method.IsGenericMethod &&
|
||||
!method.IsAbstract &&
|
||||
!method.IsStatic &&
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ namespace Microsoft.AspNetCore.Mvc.Analyzers
|
|||
return
|
||||
method.ContainingType.HasAttribute(ControllerAttribute, inherit: true) &&
|
||||
method.DeclaredAccessibility == Accessibility.Public &&
|
||||
method.MethodKind == MethodKind.Ordinary &&
|
||||
!method.IsGenericMethod &&
|
||||
!method.IsAbstract &&
|
||||
!method.IsStatic &&
|
||||
|
|
|
|||
|
|
@ -76,6 +76,28 @@ public class PetController : Controller
|
|||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task NoDiagnosticsAreReturned_ForConstructors()
|
||||
{
|
||||
// Arrange
|
||||
var test =
|
||||
@"
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
[ApiController]
|
||||
public class PetController : Controller
|
||||
{
|
||||
public PetController(){ }
|
||||
}";
|
||||
var project = CreateProject(test);
|
||||
|
||||
// Act
|
||||
var result = await GetDiagnosticAsync(project);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task NoDiagnosticsAreReturned_ForNonActions()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue