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
|
// 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).
|
// (such as property accessors and operator overloading methods).
|
||||||
!method.IsSpecialName;
|
!method.IsSpecialName &&
|
||||||
|
!method.IsDefined(typeof(NonActionAttribute));
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual IEnumerable<string> GetSupportedHttpMethods(MethodInfo methodInfo)
|
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 Moq;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
@ -108,6 +109,26 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
Assert.Equal("Index", result.Name);
|
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]
|
[Theory]
|
||||||
[InlineData("GET")]
|
[InlineData("GET")]
|
||||||
[InlineData("PUT")]
|
[InlineData("PUT")]
|
||||||
|
|
@ -220,6 +241,25 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
|
|
||||||
#region Controller Classes
|
#region Controller Classes
|
||||||
|
|
||||||
|
private class NonActionController
|
||||||
|
{
|
||||||
|
[NonAction]
|
||||||
|
public void Put()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[NonAction]
|
||||||
|
public void RPCMethod()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[NonAction]
|
||||||
|
[HttpGet]
|
||||||
|
public void RPCMethodWithHttpGet()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class HttpMethodAttributeTests_DefaultMethodValidationController
|
private class HttpMethodAttributeTests_DefaultMethodValidationController
|
||||||
{
|
{
|
||||||
public void Index()
|
public void Index()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue