diff options
author | Khalid Abuhakmeh <khalid@aquabirdconsulting.com> | 2012-03-28 05:18:56 +0400 |
---|---|---|
committer | marcind <marcind@microsoft.com> | 2012-04-03 07:45:00 +0400 |
commit | 78bc211245bdf4d537c72acc2b354cf8766031af (patch) | |
tree | 56cd5cf28320f2f29134339f6a429a1f25e3c945 | |
parent | 6e7594781f71bb3594a0d32f99dba025f156b400 (diff) |
added PATCH (issue #3) and OPTIONS (issue #6) as a valid HttpVerb and created corresponding filter attributes.
-rw-r--r-- | src/Microsoft.Web.Mvc/Resources/HttpRequestBaseExtensions.cs | 4 | ||||
-rw-r--r-- | src/System.Web.Mvc/AcceptVerbsAttribute.cs | 2 | ||||
-rw-r--r-- | src/System.Web.Mvc/HtmlHelper.cs | 6 | ||||
-rw-r--r-- | src/System.Web.Mvc/HttpOptionsAttribute.cs | 15 | ||||
-rw-r--r-- | src/System.Web.Mvc/HttpPatchAttribute.cs | 15 | ||||
-rw-r--r-- | src/System.Web.Mvc/HttpVerbs.cs | 4 | ||||
-rw-r--r-- | src/System.Web.Mvc/Properties/MvcResources.Designer.cs | 4 | ||||
-rw-r--r-- | src/System.Web.Mvc/Properties/MvcResources.resx | 2 | ||||
-rw-r--r-- | src/System.Web.Mvc/System.Web.Mvc.csproj | 2 | ||||
-rw-r--r-- | test/System.Web.Mvc.Test/System.Web.Mvc.Test.csproj | 1 | ||||
-rw-r--r-- | test/System.Web.Mvc.Test/Test/HtmlHelperTest.cs | 6 | ||||
-rw-r--r-- | test/System.Web.Mvc.Test/Test/HttpOptionsAttributeTest.cs | 25 | ||||
-rw-r--r-- | test/System.Web.Mvc.Test/Test/HttpPatchAttributeTest.cs | 24 |
13 files changed, 103 insertions, 7 deletions
diff --git a/src/Microsoft.Web.Mvc/Resources/HttpRequestBaseExtensions.cs b/src/Microsoft.Web.Mvc/Resources/HttpRequestBaseExtensions.cs index 8d0c331f..72207c9d 100644 --- a/src/Microsoft.Web.Mvc/Resources/HttpRequestBaseExtensions.cs +++ b/src/Microsoft.Web.Mvc/Resources/HttpRequestBaseExtensions.cs @@ -58,6 +58,10 @@ namespace Microsoft.Web.Mvc.Resources return request.IsHttpMethod("DELETE", allowOverride); case HttpVerbs.Head: return request.IsHttpMethod("HEAD", allowOverride); + case HttpVerbs.Patch: + return request.IsHttpMethod("PATCH", allowOverride); + case HttpVerbs.Options: + return request.IsHttpMethod("OPTIONS", allowOverride); default: // CODEREVIEW: does this look reasonable? return request.IsHttpMethod(httpMethod.ToString().ToUpperInvariant(), allowOverride); diff --git a/src/System.Web.Mvc/AcceptVerbsAttribute.cs b/src/System.Web.Mvc/AcceptVerbsAttribute.cs index 1783cdfe..7f53f9ed 100644 --- a/src/System.Web.Mvc/AcceptVerbsAttribute.cs +++ b/src/System.Web.Mvc/AcceptVerbsAttribute.cs @@ -45,6 +45,8 @@ namespace System.Web.Mvc AddEntryToList(verbs, HttpVerbs.Put, verbList, "PUT"); AddEntryToList(verbs, HttpVerbs.Delete, verbList, "DELETE"); AddEntryToList(verbs, HttpVerbs.Head, verbList, "HEAD"); + AddEntryToList(verbs, HttpVerbs.Patch, verbList, "PATCH"); + AddEntryToList(verbs, HttpVerbs.Options, verbList, "OPTIONS"); return verbList.ToArray(); } diff --git a/src/System.Web.Mvc/HtmlHelper.cs b/src/System.Web.Mvc/HtmlHelper.cs index c6ab7021..d9a5d2d0 100644 --- a/src/System.Web.Mvc/HtmlHelper.cs +++ b/src/System.Web.Mvc/HtmlHelper.cs @@ -359,6 +359,12 @@ namespace System.Web.Mvc case HttpVerbs.Put: httpMethod = "PUT"; break; + case HttpVerbs.Patch: + httpMethod = "PATCH"; + break; + case HttpVerbs.Options: + httpMethod = "OPTIONS"; + break; default: throw new ArgumentException(MvcResources.HtmlHelper_InvalidHttpVerb, "httpVerb"); } diff --git a/src/System.Web.Mvc/HttpOptionsAttribute.cs b/src/System.Web.Mvc/HttpOptionsAttribute.cs new file mode 100644 index 00000000..8ba16155 --- /dev/null +++ b/src/System.Web.Mvc/HttpOptionsAttribute.cs @@ -0,0 +1,15 @@ +using System.Reflection; + +namespace System.Web.Mvc +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] + public sealed class HttpOptionsAttribute : ActionMethodSelectorAttribute + { + private static readonly AcceptVerbsAttribute _innerAttribute = new AcceptVerbsAttribute(HttpVerbs.Options); + + public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo) + { + return _innerAttribute.IsValidForRequest(controllerContext, methodInfo); + } + } +}
\ No newline at end of file diff --git a/src/System.Web.Mvc/HttpPatchAttribute.cs b/src/System.Web.Mvc/HttpPatchAttribute.cs new file mode 100644 index 00000000..6f7d9252 --- /dev/null +++ b/src/System.Web.Mvc/HttpPatchAttribute.cs @@ -0,0 +1,15 @@ +using System.Reflection; + +namespace System.Web.Mvc +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] + public sealed class HttpPatchAttribute : ActionMethodSelectorAttribute + { + private static readonly AcceptVerbsAttribute _innerAttribute = new AcceptVerbsAttribute(HttpVerbs.Patch); + + public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo) + { + return _innerAttribute.IsValidForRequest(controllerContext, methodInfo); + } + } +}
\ No newline at end of file diff --git a/src/System.Web.Mvc/HttpVerbs.cs b/src/System.Web.Mvc/HttpVerbs.cs index 22049977..debd7824 100644 --- a/src/System.Web.Mvc/HttpVerbs.cs +++ b/src/System.Web.Mvc/HttpVerbs.cs @@ -7,6 +7,8 @@ Post = 1 << 1, Put = 1 << 2, Delete = 1 << 3, - Head = 1 << 4 + Head = 1 << 4, + Patch = 1 << 5, + Options = 1 << 6, } } diff --git a/src/System.Web.Mvc/Properties/MvcResources.Designer.cs b/src/System.Web.Mvc/Properties/MvcResources.Designer.cs index 0618068e..b1db5533 100644 --- a/src/System.Web.Mvc/Properties/MvcResources.Designer.cs +++ b/src/System.Web.Mvc/Properties/MvcResources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. -// Runtime Version:4.0.30319.17369 +// Runtime Version:4.0.30319.530 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -542,7 +542,7 @@ namespace System.Web.Mvc.Properties { } /// <summary> - /// Looks up a localized string similar to The specified HttpVerbs value is not supported. The supported values are Delete, Head, and Put.. + /// Looks up a localized string similar to The specified HttpVerbs value is not supported. The supported values are Delete, Head, Put, Options, and Patch.. /// </summary> internal static string HtmlHelper_InvalidHttpVerb { get { diff --git a/src/System.Web.Mvc/Properties/MvcResources.resx b/src/System.Web.Mvc/Properties/MvcResources.resx index 5bcc68f5..0189143a 100644 --- a/src/System.Web.Mvc/Properties/MvcResources.resx +++ b/src/System.Web.Mvc/Properties/MvcResources.resx @@ -277,7 +277,7 @@ <value>The requested resource can only be accessed via SSL.</value> </data> <data name="HtmlHelper_InvalidHttpVerb" xml:space="preserve"> - <value>The specified HttpVerbs value is not supported. The supported values are Delete, Head, and Put.</value> + <value>The specified HttpVerbs value is not supported. The supported values are Delete, Head, Put, Options, and Patch.</value> </data> <data name="HtmlHelper_InvalidHttpMethod" xml:space="preserve"> <value>The GET and POST HTTP methods are not supported.</value> diff --git a/src/System.Web.Mvc/System.Web.Mvc.csproj b/src/System.Web.Mvc/System.Web.Mvc.csproj index b1eb3c0c..632fd4d9 100644 --- a/src/System.Web.Mvc/System.Web.Mvc.csproj +++ b/src/System.Web.Mvc/System.Web.Mvc.csproj @@ -96,6 +96,8 @@ <Compile Include="ChildActionValueProvider.cs" /> <Compile Include="ChildActionValueProviderFactory.cs" /> <Compile Include="HttpHeadAttribute.cs" /> + <Compile Include="HttpOptionsAttribute.cs" /> + <Compile Include="HttpPatchAttribute.cs" /> <Compile Include="IEnumerableValueProvider.cs" /> <Compile Include="DataTypeUtil.cs" /> <Compile Include="Html\DisplayNameExtensions.cs" /> diff --git a/test/System.Web.Mvc.Test/System.Web.Mvc.Test.csproj b/test/System.Web.Mvc.Test/System.Web.Mvc.Test.csproj index 2c3aa7bb..52973b2b 100644 --- a/test/System.Web.Mvc.Test/System.Web.Mvc.Test.csproj +++ b/test/System.Web.Mvc.Test/System.Web.Mvc.Test.csproj @@ -102,6 +102,7 @@ <Compile Include="Test\AllowHtmlAttributeTest.cs" /> <Compile Include="Test\HtmlHelper`1Test.cs" /> <Compile Include="Test\HttpHeadAttributeTest.cs" /> + <Compile Include="Test\HttpPatchAttributeTest.cs" /> <Compile Include="Test\MockableUnvalidatedRequestValues.cs" /> <Compile Include="Test\DescriptorUtilTest.cs" /> <Compile Include="Razor\Test\MvcVBRazorCodeParserTest.cs" /> diff --git a/test/System.Web.Mvc.Test/Test/HtmlHelperTest.cs b/test/System.Web.Mvc.Test/Test/HtmlHelperTest.cs index 1e577dc8..9c0a0cab 100644 --- a/test/System.Web.Mvc.Test/Test/HtmlHelperTest.cs +++ b/test/System.Web.Mvc.Test/Test/HtmlHelperTest.cs @@ -544,17 +544,17 @@ location2"); ); Assert.Throws<ArgumentException>( () => htmlHelper.HttpMethodOverride((HttpVerbs)10000), - @"The specified HttpVerbs value is not supported. The supported values are Delete, Head, and Put. + @"The specified HttpVerbs value is not supported. The supported values are Delete, Head, Put, Options, and Patch. Parameter name: httpVerb" ); Assert.Throws<ArgumentException>( () => htmlHelper.HttpMethodOverride(HttpVerbs.Get), - @"The specified HttpVerbs value is not supported. The supported values are Delete, Head, and Put. + @"The specified HttpVerbs value is not supported. The supported values are Delete, Head, Put, Options, and Patch. Parameter name: httpVerb" ); Assert.Throws<ArgumentException>( () => htmlHelper.HttpMethodOverride(HttpVerbs.Post), - @"The specified HttpVerbs value is not supported. The supported values are Delete, Head, and Put. + @"The specified HttpVerbs value is not supported. The supported values are Delete, Head, Put, Options, and Patch. Parameter name: httpVerb" ); Assert.Throws<ArgumentException>( diff --git a/test/System.Web.Mvc.Test/Test/HttpOptionsAttributeTest.cs b/test/System.Web.Mvc.Test/Test/HttpOptionsAttributeTest.cs new file mode 100644 index 00000000..1f24deee --- /dev/null +++ b/test/System.Web.Mvc.Test/Test/HttpOptionsAttributeTest.cs @@ -0,0 +1,25 @@ +using Xunit; + +namespace System.Web.Mvc.Test +{ + public class HttpOptionsAttributeTest + { + [Fact] + public void IsValidForRequestReturnsFalseIfHttpVerbIsNotOptions() + { + HttpVerbAttributeHelper.TestHttpVerbAttributeWithInvalidVerb<HttpOptionsAttribute>("GET"); + } + + [Fact] + public void IsValidForRequestReturnsTrueIfHttpVerbIsOptions() + { + HttpVerbAttributeHelper.TestHttpVerbAttributeWithValidVerb<HttpOptionsAttribute>("OPTIONS"); + } + + [Fact] + public void IsValidForRequestThrowsIfControllerContextIsNull() + { + HttpVerbAttributeHelper.TestHttpVerbAttributeNullControllerContext<HttpOptionsAttribute>(); + } + } +}
\ No newline at end of file diff --git a/test/System.Web.Mvc.Test/Test/HttpPatchAttributeTest.cs b/test/System.Web.Mvc.Test/Test/HttpPatchAttributeTest.cs new file mode 100644 index 00000000..68bbae6d --- /dev/null +++ b/test/System.Web.Mvc.Test/Test/HttpPatchAttributeTest.cs @@ -0,0 +1,24 @@ +using Xunit; + +namespace System.Web.Mvc.Test { + public class HttpPatchAttributeTest + { + [Fact] + public void IsValidForRequestReturnsFalseIfHttpVerbIsNotPatch() + { + HttpVerbAttributeHelper.TestHttpVerbAttributeWithInvalidVerb<HttpPatchAttribute>("GET"); + } + + [Fact] + public void IsValidForRequestReturnsTrueIfHttpVerbIsPatch() + { + HttpVerbAttributeHelper.TestHttpVerbAttributeWithValidVerb<HttpPatchAttribute>("PATCH"); + } + + [Fact] + public void IsValidForRequestThrowsIfControllerContextIsNull() + { + HttpVerbAttributeHelper.TestHttpVerbAttributeNullControllerContext<HttpPatchAttribute>(); + } + } +}
\ No newline at end of file |