Adding NonAction Attribute
This commit is contained in:
parent
246bb2e3dd
commit
1536daa107
|
|
@ -86,7 +86,8 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
// The SpecialName bit is set to flag members that are treated in a special way by some compilers
|
||||
// (such as property accessors and operator overloading methods).
|
||||
!method.IsSpecialName;
|
||||
!method.IsSpecialName &&
|
||||
!method.IsDefined(typeof(NonActionAttribute));
|
||||
}
|
||||
|
||||
public virtual IEnumerable<string> GetSupportedHttpMethods(MethodInfo methodInfo)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
using System;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
||||
public sealed class NonActionAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ using Microsoft.AspNet.DependencyInjection.NestedProviders;
|
|||
using Moq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
|
@ -108,6 +109,26 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
Assert.Equal("Index", result.Name);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("Put")]
|
||||
[InlineData("RPCMethod")]
|
||||
[InlineData("RPCMethodWithHttpGet")]
|
||||
public async Task NonActionAttribute_ActionNotReachable(string actionName)
|
||||
{
|
||||
// Arrange
|
||||
var actionDescriptorProvider = GetActionDescriptorProvider(_actionDiscoveryConventions);
|
||||
|
||||
// Act
|
||||
var result = actionDescriptorProvider.GetDescriptors()
|
||||
.Select(x => x as ReflectedActionDescriptor)
|
||||
.FirstOrDefault(
|
||||
x=> x.ControllerName == "NonAction" &&
|
||||
x.Name == actionName);
|
||||
|
||||
// Assert
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("GET")]
|
||||
[InlineData("PUT")]
|
||||
|
|
@ -220,6 +241,25 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
|
||||
#region Controller Classes
|
||||
|
||||
private class NonActionController
|
||||
{
|
||||
[NonAction]
|
||||
public void Put()
|
||||
{
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
public void RPCMethod()
|
||||
{
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
[HttpGet]
|
||||
public void RPCMethodWithHttpGet()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private class HttpMethodAttributeTests_DefaultMethodValidationController
|
||||
{
|
||||
public void Index()
|
||||
|
|
|
|||
Loading…
Reference in New Issue