Permalink
Browse files

#65 - fixed bug introduced in v2.* that arises when using the RouteAt…

…tribute on actions without specifying a verb.
  • Loading branch information...
1 parent 990d7b1 commit 8a9539fff5fab5bcba3b2d9ff487ba7e29ae90e3 @mccalltd committed Apr 26, 2012
@@ -1,27 +1,25 @@
Feature: Standard Usage
-Background:
- Given I generate the routes defined in the subject controllers
-
Scenario Outline: Generating routes for an action method
+ Given I have registered the routes for the StandardUsageController
When I fetch the routes for the StandardUsage controller's <action> action
Then the route is constrained to <method> requests
And the route url is "<url>"
And the default for "controller" is "StandardUsage"
And the default for "action" is "<action>"
And the namespace is "AttributeRouting.Specs.Subjects"
-
Examples:
- | method | action | url |
- | GET | Index | Index |
- | HEAD | Index | Index |
- | POST | Create | Create |
- | PUT | Update | Update/{id} |
- | DELETE | Destroy | Destroy/{id} |
- | GET | Wildcards | Wildcards/{*pathInfo} |
+ | method | action | url |
+ | GET | Index | Index |
+ | HEAD | Index | Index |
+ | POST | Create | Create |
+ | PUT | Update | Update/{id} |
+ | DELETE | Destroy | Destroy/{id} |
+ | GET | Wildcards | Wildcards/{*pathInfo} |
| | AnyVerb | AnyVerb |
Scenario Outline: Generating routes for an API controller
+ Given I have registered the routes for the HttpStandardUsageController
When I fetch the routes for the HttpStandardUsage controller's <action> action
Then the route is constrained to <method> requests
And the route url is "<url>"

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -1,5 +1,7 @@
-using System.Linq;
+using System.Collections.Specialized;
+using System.Linq;
using System.Web.Routing;
+using AttributeRouting.Helpers;
using AttributeRouting.Specs.Subjects;
using AttributeRouting.Specs.Subjects.Http;
using AttributeRouting.Specs.Tests;
@@ -73,10 +75,25 @@ public void WhenIFetchTheRoutesFor(string controllerName)
ScenarioContext.Current.SetFetchedRoutes(routes);
}
- [When(@"a request for ""(.*)"" is made")]
- public void WhenARequestForUrlIsMade(string url)
+ [When(@"a (.*)? request for ""(.*)"" is made")]
+ public void WhenAMethodRequestForUrlIsMade(string method, string url)
{
- var httpContextMock = MockBuilder.BuildMockHttpContext(r => r.SetupGet(x => x.PathInfo).Returns(url));
+ var desiredMethod = (method.HasValue() ? method : "GET").ToUpperInvariant();
+ var requestMethod = (desiredMethod.ValueEquals("GET") ? "GET" : "POST").ToUpperInvariant();
+
+ var httpContextMock = MockBuilder.BuildMockHttpContext(r =>
+ {
+ r.SetupGet(x => x.PathInfo).Returns(url);
+ r.SetupGet(x => x.HttpMethod).Returns(requestMethod);
+
+ if (desiredMethod != requestMethod)
+ {
+ r.SetupGet(x => x.Headers).Returns(new NameValueCollection
+ {
+ { "X-HTTP-Method-Override", desiredMethod }
+ });
+ }
+ });
ScenarioContext.Current.SetCurrentHttpContext(httpContextMock.Object);
}
@@ -77,6 +77,9 @@ public bool AppendTrailingSlash
public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo)
{
+ if (!HttpMethods.Any())
+ return true;
+
var method = controllerContext.HttpContext.Request.GetHttpMethodOverride();
return HttpMethods.Any(m => m.ValueEquals(method));
}
@@ -9,4 +9,4 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
-[assembly: AssemblyVersion("2.2.0.0")]
+[assembly: AssemblyVersion("2.2.1.0")]

0 comments on commit 8a9539f

Please sign in to comment.