Ignore constructors when discovering actions

This commit is contained in:
Pranav K 2018-03-06 10:19:59 -08:00
parent f3ffdada95
commit 5af246b554
3 changed files with 24 additions and 0 deletions

View File

@ -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 &&

View File

@ -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 &&

View File

@ -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()
{