Adding HttpPost, HttpDelete, HttpPut, HttpPatch attributes
This commit is contained in:
parent
faa8251b70
commit
01527cd4df
|
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
||||
public sealed class HttpDeleteAttribute : Attribute, IActionHttpMethodProvider
|
||||
{
|
||||
private static readonly IEnumerable<string> _supportedMethods = new string[] { "DELETE" };
|
||||
|
||||
public IEnumerable<string> HttpMethods
|
||||
{
|
||||
get { return _supportedMethods; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
||||
public sealed class HttpPatchAttribute : Attribute, IActionHttpMethodProvider
|
||||
{
|
||||
private static readonly IEnumerable<string> _supportedMethods = new string[] { "PATCH" };
|
||||
|
||||
public IEnumerable<string> HttpMethods
|
||||
{
|
||||
get { return _supportedMethods; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
||||
public sealed class HttpPostAttribute : Attribute, IActionHttpMethodProvider
|
||||
{
|
||||
private static readonly IEnumerable<string> _supportedMethods = new string[] { "POST" };
|
||||
|
||||
public IEnumerable<string> HttpMethods
|
||||
{
|
||||
get { return _supportedMethods; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
||||
public sealed class HttpPutAttribute : Attribute, IActionHttpMethodProvider
|
||||
{
|
||||
private static readonly IEnumerable<string> _supportedMethods = new string[] { "PUT" };
|
||||
|
||||
public IEnumerable<string> HttpMethods
|
||||
{
|
||||
get { return _supportedMethods; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -22,7 +22,33 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
[InlineData("GET")]
|
||||
[InlineData("PUT")]
|
||||
[InlineData("POST")]
|
||||
public async Task HttpMethodAttribute_ActionDecoratedWithMultipleHttpMethodAttribute_ORsMultipleHttpMethods(string verb)
|
||||
[InlineData("DELETE")]
|
||||
[InlineData("PATCH")]
|
||||
public async Task HttpMethodAttribute_ActionWithMultipleHttpMethodAttributeViaAcceptVerbs_ORsMultipleHttpMethods(string verb)
|
||||
{
|
||||
// Arrange
|
||||
var requestContext = new RequestContext(
|
||||
GetHttpContext(verb),
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "controller", "HttpMethodAttributeTests_RestOnly" },
|
||||
{ "action", "Patch" }
|
||||
});
|
||||
|
||||
// Act
|
||||
var result = await InvokeActionSelector(requestContext);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Patch", result.Name);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("GET")]
|
||||
[InlineData("PUT")]
|
||||
[InlineData("POST")]
|
||||
[InlineData("DELETE")]
|
||||
[InlineData("PATCH")]
|
||||
public async Task HttpMethodAttribute_ActionWithMultipleHttpMethodAttributes_ORsMultipleHttpMethods(string verb)
|
||||
{
|
||||
// Arrange
|
||||
var requestContext = new RequestContext(
|
||||
|
|
@ -155,15 +181,15 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
private class HttpMethodAttributeTests_RestOnlyController
|
||||
{
|
||||
[HttpGet]
|
||||
[AcceptVerbs("PUT", "POST")]
|
||||
[HttpPut]
|
||||
[HttpPost]
|
||||
[HttpDelete]
|
||||
[HttpPatch]
|
||||
public void Put()
|
||||
{
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
}
|
||||
|
||||
[AcceptVerbs("PUT", "post", "GET", "delete", "pATcH")]
|
||||
public void Patch()
|
||||
{
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue