Permalink
Browse files

RouteDefaults specs for Web API

  • Loading branch information...
kamranayub committed Apr 7, 2012
1 parent 907df42 commit 10c419483974f5f79c49a57e0adf18f9ffa6162d
@@ -134,8 +134,10 @@
<Compile Include="Steps\SharedSteps.cs" />
<Compile Include="Steps\StandardUsageSteps.cs" />
<Compile Include="Subjects\BugFixesController.cs" />
+ <Compile Include="Subjects\Http\RouteAreasControllers.cs" />
<Compile Include="Subjects\Http\RouteConstraintsController.cs" />
<Compile Include="Subjects\Http\RouteConventionsController.cs" />
+ <Compile Include="Subjects\Http\RouteDefaultsController.cs" />
<Compile Include="Subjects\Http\StandardUsageController.cs" />
<Compile Include="Subjects\LowercaseUrlController.cs" />
<Compile Include="Subjects\RouteAreasControllers.cs" />
@@ -7,25 +7,40 @@ Scenario: Generating area routes
When I fetch the routes for the Areas controller's Index action
Then the route url is "Area/Index"
And the data token for "area" is "Area"
+ When I fetch the routes for the HttpAreas controller's Get action
+ Then the route url is "ApiArea/Get"
+ And the data token for "area" is "ApiArea"
Scenario: Generating area routes when route urls specify a duplicate area prefix
When I fetch the routes for the Areas controller's DuplicatePrefix action
Then the route url is "Area/DuplicatePrefix"
+ When I fetch the routes for the HttpAreas controller's DuplicatePrefix action
+ Then the route url is "ApiArea/DuplicatePrefix"
Scenario: Generating absolute routes when a route area is defined
When I fetch the routes for the Areas controller's Absolute action
Then the route url is "AreaAbsolute"
+ When I fetch the routes for the HttpAreas controller's Absolute action
+ Then the route url is "ApiAreaAbsolute"
Scenario: Generating area routes when route url starts with the area prefix
When I fetch the routes for the Areas controller's RouteBeginsWithAreaName action
Then the route url is "Area/Areas"
+ When I fetch the routes for the HttpAreas controller's RouteBeginsWithAreaName action
+ Then the route url is "ApiArea/ApiAreas"
Scenario: Generating area routes with an explicit area url
When I fetch the routes for the ExplicitAreaUrl controller's Index action
Then the route url is "ExplicitArea/Index"
And the data token for "area" is "Area"
-
+ When I fetch the routes for the HttpExplicitAreaUrl controller's Get action
+ Then the route url is "ApiExplicitArea/Get"
+ And the data token for "area" is "ApiArea"
+
Scenario: Generating area routes with an explicit area url when route urls specify a duplicate area prefix
When I fetch the routes for the ExplicitAreaUrl controller's DuplicatePrefix action
Then the route url is "ExplicitArea/DuplicatePrefix"
- And the data token for "area" is "Area"
+ And the data token for "area" is "Area"
+ When I fetch the routes for the HttpExplicitAreaUrl controller's DuplicatePrefix action
+ Then the route url is "ApiExplicitArea/DuplicatePrefix"
+ And the data token for "area" is "ApiArea"

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

Oops, something went wrong.
@@ -5,22 +5,28 @@ Background:
Scenario: Route default specified with an attribute
When I fetch the routes for the RouteDefaults controller's Index action
+ And I fetch the routes for the HttpRouteDefaults controller's Get action
Then the default for "p1" is "variable"
Scenario: Route default specified inline
When I fetch the routes for the RouteDefaults controller's InlineDefaults action
+ And I fetch the routes for the HttpRouteDefaults controller's InlineDefaults action
Then the route url is "InlineDefaults/{hello}/{goodnight}"
Then the default for "hello" is "sun"
Then the default for "goodnight" is "moon"
Scenario: Optional parameters specified with a url parameter token
When I fetch the routes for the RouteDefaults controller's Optionals action
+ And I fetch the routes for the HttpRouteDefaults controller's Optionals action
Then the route url is "Optionals/{p1}/{p2}/{p3}"
And the parameter "p1" is optional
And the parameter "p2" is optional
And the parameter "p3" is optional
Scenario: Multiple routes with different defaults
When I fetch the routes for the RouteDefaults controller's MultipleRoutes action
+ And I fetch the routes for the HttpRouteDefaults controller's MultipleRoutes action
Then the route named "MultipleDefaults1" has a default for "p1" of "first"
And the route named "MultipleDefaults2" has a default for "p1" of "second"
+ And the route named "ApiMultipleDefaults1" has a default for "p1" of "first"
+ And the route named "ApiMultipleDefaults2" has a default for "p1" of "second"

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

Oops, something went wrong.
@@ -22,10 +22,10 @@ Scenario Outline: Generating routes for an action method
| | AnyVerb | AnyVerb |
Scenario Outline: Generating routes for an API controller
- When I fetch the routes for the ApiStandardUsage controller's <action> action
+ 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>"
- And the default for "controller" is "ApiStandardUsage"
+ And the default for "controller" is "HttpStandardUsage"
And the default for "action" is "<action>"
And the namespace is "AttributeRouting.Specs.Subjects.Http"

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

Oops, something went wrong.
@@ -1,4 +1,5 @@
using System.Linq;
+using System.Web.Http;
using System.Web.Mvc;
using AttributeRouting.Framework;
using AttributeRouting.Web.Mvc.Framework;
@@ -13,23 +14,27 @@ public class RouteDefaultsSteps
[Then(@"the parameter ""(.*?)"" is optional")]
public void ThenTheParameterIsOptional(string name)
{
- var route = ScenarioContext.Current.GetFetchedRoutes().First();
+ var routes = ScenarioContext.Current.GetFetchedRoutes();
- Assert.That(route, Is.Not.Null);
- Assert.That(route.Defaults[name], Is.EqualTo(UrlParameter.Optional));
+ foreach (var route in routes) {
+ Assert.That(route, Is.Not.Null);
+ Assert.That(route.Defaults[name], Is.EqualTo(UrlParameter.Optional).Or.EqualTo(RouteParameter.Optional));
+ }
}
[Then(@"the route named ""(.*)"" has a default for ""(.*)"" of ""?(.*?)""?")]
public void ThenTheRouteNamedHasADefaultForOf(string routeName, string key, string value)
{
- var route = ScenarioContext.Current.GetFetchedRoutes().Cast<AttributeRoute>().SingleOrDefault(r => r.Container.RouteName == routeName);
+ var routes = ScenarioContext.Current.GetFetchedRouteContainers().Where(c => c.RouteName == routeName);
- Assert.That(route, Is.Not.Null);
+ foreach (var route in routes) {
+ Assert.That(route, Is.Not.Null);
- var routeDefault = route.Defaults[key];
+ var routeDefault = route.Defaults[key];
- Assert.That(routeDefault, Is.Not.Null);
- Assert.That(routeDefault.ToString(), Is.EqualTo(value));
+ Assert.That(routeDefault, Is.Not.Null);
+ Assert.That(routeDefault.ToString(), Is.EqualTo(value));
+ }
}
}
}
Oops, something went wrong.

0 comments on commit 10c4194

Please sign in to comment.