Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #225 - add PATCH attribute. #262

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -29,6 +29,12 @@ public string Delete()
return "";
}

[PATCH("api/{id}")]
public string Patch()
{
return "";
}

[GET("api/Wildcards/{*pathInfo}")]
public string Wildcards()
{
Expand Down
12 changes: 12 additions & 0 deletions src/AttributeRouting.Specs/Subjects/StandardUsageController.cs
Expand Up @@ -30,6 +30,12 @@ public ActionResult Destroy()
return Content("");
}

[PATCH("PartialUpdate/{id}")]
public ActionResult PartialUpdate()
{
return Content("");
}

[GET("Wildcards/{*pathInfo}")]
public ActionResult Wildcards()
{
Expand Down Expand Up @@ -66,6 +72,12 @@ public ActionResult DeleteDefault()
return Content("");
}

[PATCH]
public ActionResult PatchDefault()
{
return Content("");
}

[Route]
public ActionResult RouteDefault()
{
Expand Down
4 changes: 2 additions & 2 deletions src/AttributeRouting.Specs/Tests/BugFixTests.cs
Expand Up @@ -169,7 +169,7 @@ public void Issue191_in_memory_config_initializes_routes_with_general_http_const
x.AddRoutesFromController<HttpStandardUsageController>();
});

Assert.AreEqual(6, inMemoryConfig.Routes.Count);
Assert.AreEqual(7, inMemoryConfig.Routes.Count);
Assert.True(inMemoryConfig.Routes.All(x => x.Constraints.All(c => c.Value.GetType() == typeof(InboundHttpMethodConstraint))));
}

Expand All @@ -181,7 +181,7 @@ public void Issue191_default_web_config_initializes_routes_with_web_http_constra

inMemoryConfig.Routes.MapHttpAttributeRoutes(x => x.AddRoutesFromController<HttpStandardUsageController>());

Assert.AreEqual(6, inMemoryConfig.Routes.Count);
Assert.AreEqual(7, inMemoryConfig.Routes.Count);
Assert.True(inMemoryConfig.Routes.All(x => x.Constraints.All(c => c.Value.GetType() == typeof(Web.Http.WebHost.Constraints.InboundHttpMethodConstraint))));
}

Expand Down
Expand Up @@ -37,5 +37,11 @@ public void Put(int id)
public void Delete(int id)
{
}

// PATCH /api/plain/5
[PATCH("{id}")]
public void Patch()
{
}
}
}
Expand Up @@ -94,6 +94,7 @@
<Compile Include="GETAttribute.cs" />
<Compile Include="HttpConfiguration.cs" />
<Compile Include="HttpConfigurationBase.cs" />
<Compile Include="PATCHAttribute.cs" />
<Compile Include="POSTAttribute.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PUTAttribute.cs" />
Expand Down
16 changes: 16 additions & 0 deletions src/AttributeRouting.Web.Http/PATCHAttribute.cs
@@ -0,0 +1,16 @@
using System.Net.Http;

namespace AttributeRouting.Web.Http
{
/// <summary>
/// Defines a route for an action constrained to requests providing an httpMethod value of PATCH.
/// </summary>
public class PATCHAttribute : HttpRouteAttribute
{
/// <summary>
/// Specify a route for a PATCH request.
/// </summary>
/// <param name="routeUrl">The url that is associated with this action</param>
public PATCHAttribute(string routeUrl) : base(routeUrl, new HttpMethod("PATCH")) { }
}
}
Expand Up @@ -93,6 +93,7 @@
<Compile Include="Framework\RouteParameterFactory.cs" />
<Compile Include="Framework\RouteConstraintFactory.cs" />
<Compile Include="GETAttribute.cs" />
<Compile Include="PATCHAttribute.cs" />
<Compile Include="POSTAttribute.cs" />
<Compile Include="PUTAttribute.cs" />
<Compile Include="RouteAttribute.cs" />
Expand Down
20 changes: 20 additions & 0 deletions src/AttributeRouting.Web.Mvc/PATCHAttribute.cs
@@ -0,0 +1,20 @@
namespace AttributeRouting.Web.Mvc
{
/// <summary>
/// Defines a PATCH route for an action in Mvc Controllers.
/// </summary>
public class PATCHAttribute : RouteAttribute
{
/// <summary>
/// Specify a route for PATCH request.
/// The route URL will be the name of the action.
/// </summary>
public PATCHAttribute() : base("PATCH") { }

/// <summary>
/// Specify a route for PATCH request.
/// </summary>
/// <param name="routeUrl">The url that is associated with this action</param>
public PATCHAttribute(string routeUrl) : base(routeUrl, "PATCH") { }
}
}
24 changes: 22 additions & 2 deletions src/AttributeRouting.Web.Mvc/RouteAttribute.cs
Expand Up @@ -42,9 +42,19 @@ public RouteAttribute(string routeUrl)
/// </summary>
/// <param name="allowedMethods">The httpMethods against which to constrain the route</param>
public RouteAttribute(params HttpVerbs[] allowedMethods)
: this(allowedMethods.Select(m => m.ToString()).ToArray())
{
}

/// <summary>
/// Specify the route information for an action.
/// The route URL will be the name of the action.
/// </summary>
/// <param name="allowedMethods">The httpMethods against which to constrain the route</param>
public RouteAttribute(params string[] allowedMethods)
: this()
{
HttpMethods = allowedMethods.Select(m => m.ToString().ToUpperInvariant()).ToArray();
HttpMethods = allowedMethods.Select(m => m.ToUpperInvariant()).ToArray();
}

/// <summary>
Expand All @@ -53,9 +63,19 @@ public RouteAttribute(params HttpVerbs[] allowedMethods)
/// <param name="routeUrl">The url that is associated with this action</param>
/// <param name="allowedMethods">The httpMethods against which to constrain the route</param>
public RouteAttribute(string routeUrl, params HttpVerbs[] allowedMethods)
: this(routeUrl, allowedMethods.Select(m => m.ToString()).ToArray())
{
}

/// <summary>
/// Specify the route information for an action.
/// </summary>
/// <param name="routeUrl">The url that is associated with this action</param>
/// <param name="allowedMethods">The httpMethods against which to constrain the route</param>
public RouteAttribute(string routeUrl, params string[] allowedMethods)
: this(routeUrl)
{
HttpMethods = allowedMethods.Select(m => m.ToString().ToUpperInvariant()).ToArray();
HttpMethods = allowedMethods.Select(m => m.ToUpperInvariant()).ToArray();
}

public string RouteUrl { get; private set; }
Expand Down