Skip to content

Commit

Permalink
RouteConvention spec fix and RoutePrecedence specs
Browse files Browse the repository at this point in the history
Also fixed an issue where the MVC-based config was accepting promoted
controllers of the Api controller types
  • Loading branch information
kamranayub committed Apr 7, 2012
1 parent 10c4194 commit 4c9e264
Show file tree
Hide file tree
Showing 9 changed files with 346 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/AttributeRouting.Specs/AttributeRouting.Specs.csproj
Expand Up @@ -138,6 +138,7 @@
<Compile Include="Subjects\Http\RouteConstraintsController.cs" />
<Compile Include="Subjects\Http\RouteConventionsController.cs" />
<Compile Include="Subjects\Http\RouteDefaultsController.cs" />
<Compile Include="Subjects\Http\RoutePrecedenceController.cs" />
<Compile Include="Subjects\Http\StandardUsageController.cs" />
<Compile Include="Subjects\LowercaseUrlController.cs" />
<Compile Include="Subjects\RouteAreasControllers.cs" />
Expand Down
20 changes: 18 additions & 2 deletions src/AttributeRouting.Specs/Features/RouteConventions.feature
Expand Up @@ -54,7 +54,23 @@ Scenario Outline: Generating routes using the DefaultHttpRouteConvention
| Post | POST | DefaultHttpRouteConvention |
| Put | PUT | DefaultHttpRouteConvention/{id} |
| Delete | DELETE | DefaultHttpRouteConvention/{id} |
| Custom | GET | DefaultHttpRouteConvention/Custom |
| Custom | GET | DefaultHttpRouteConvention/Custom |

Scenario Outline: Generating routes using the DefaultHttpRouteConventionPrefix on controllers with a RoutePrefix attribute
When I fetch the routes for the DefaultHttpRouteConventionPrefix controller's <action> action
Then the route url is "<url>"
And the default for "controller" is "DefaultHttpRouteConventionPrefix"
And the default for "action" is "<action>"
And the route for <action> is constrained to <method> requests

Examples:
| action | method | url |
| GetAll | GET | Prefix |
| Get | GET | Prefix/{id} |
| Post | POST | Prefix |
| Put | PUT | Prefix/{id} |
| Delete | DELETE | Prefix/{id} |
| Custom | GET | Prefix/Custom |

Scenario: Generating routes using the RestfulRouteConvention on actions with an explicit route defined
When I fetch the routes for the RestfulRouteConventionWithExplicitRoute controller's Index action
Expand All @@ -72,6 +88,6 @@ Scenario: Generating routes using the DefaultHttpRouteConvention on actions with
And the 2nd route url is "Legacy"

Scenario: Generating routes using the DefaultHttpRouteConvention on actions with an explicit ordered route defined
When I fetch the routes for the DefaultHttpRouteConventionWithExplicitOrderedRoute controller's Index action
When I fetch the routes for the DefaultHttpRouteConventionWithExplicitOrderedRoute controller's Get action
Then the 1st route url is "DefaultHttpRouteConventionWithExplicitOrderedRoute/Primary"
And the 2nd route url is "DefaultHttpRouteConventionWithExplicitOrderedRoute"
66 changes: 49 additions & 17 deletions src/AttributeRouting.Specs/Features/RouteConventions.feature.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 33 additions & 1 deletion src/AttributeRouting.Specs/Features/RoutePrecedence.feature
Expand Up @@ -31,4 +31,36 @@ Scenario: Route precedence among controllers added by base type using the config
And I add the routes from the RoutePrecedenceAmongControllers1 controller
When I generate the routes with this configuration
Then the routes from the RoutePrecedenceAmongDerivedControllers1 controller precede those from the RoutePrecedenceAmongControllers1 controller
And the routes from the RoutePrecedenceAmongDerivedControllers2 controller precede those from the RoutePrecedenceAmongControllers1 controller
And the routes from the RoutePrecedenceAmongDerivedControllers2 controller precede those from the RoutePrecedenceAmongControllers1 controller

# Web API

Scenario: Web API route precedence among routes for an action using the Order property
When I fetch the routes for the HttpRoutePrecedenceAmongRoutes controller's Get action
Then 3 routes are found
And the 1st route's url is "Get/First"
And the 2nd route's url is "Get/Second"
And the 3rd route's url is "Get/Third"

Scenario: Web API route precedence among actions within a controller using the Precedence property
When I fetch the routes for the HttpRoutePrecedenceAmongActions controller
Then the 1st route's url is "ApiRoute1"
And the 2nd route's url is "ApiRoute2"
And the 3rd route's url is "ApiRoute3"

Scenario: Web API route precedence among controllers added individually using the configuration api
Given I have a new configuration object
And I add the routes from the HttpRoutePrecedenceAmongControllers1 controller
And I add the routes from the HttpRoutePrecedenceAmongControllers2 controller
And I add the routes from the HttpRoutePrecedenceAmongControllers3 controller
When I generate the routes with this configuration
Then the routes from the HttpRoutePrecedenceAmongControllers1 controller precede those from the HttpRoutePrecedenceAmongControllers2 controller
And the routes from the HttpRoutePrecedenceAmongControllers2 controller precede those from the HttpRoutePrecedenceAmongControllers3 controller

Scenario: Web API route precedence among controllers added by base type using the configuration api
Given I have a new configuration object
And I add the routes from controllers derived from the HttpRoutePrecedenceAmongDerivedControllersBase controller
And I add the routes from the HttpRoutePrecedenceAmongControllers1 controller
When I generate the routes with this configuration
Then the routes from the HttpRoutePrecedenceAmongDerivedControllers1 controller precede those from the HttpRoutePrecedenceAmongControllers1 controller
And the routes from the HttpRoutePrecedenceAmongDerivedControllers2 controller precede those from the HttpRoutePrecedenceAmongControllers1 controller
108 changes: 108 additions & 0 deletions src/AttributeRouting.Specs/Features/RoutePrecedence.feature.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions src/AttributeRouting.Specs/Steps/RoutePrecedenceSteps.cs
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using System.Web.Routing;
using AttributeRouting.Web.Http.WebHost;
using AttributeRouting.Web.Mvc;
using NUnit.Framework;
using TechTalk.SpecFlow;
Expand All @@ -13,32 +14,41 @@ namespace AttributeRouting.Specs.Steps
public class RoutePrecedenceSteps
{
private AttributeRoutingConfiguration _configuration;
private HttpAttributeRoutingConfiguration _httpConfiguration;

[Given(@"I have a new configuration object")]
public void GivenIHaveANewConfigurationObject()
{
_configuration = new AttributeRoutingConfiguration();
_httpConfiguration = new HttpAttributeRoutingConfiguration();
}

[Given(@"I add the routes from the (.*) controller")]
public void GivenIAddTheRoutesFromTheController(string controllerName)
{
var controllerType = GetControllerType(controllerName);
_configuration.AddRoutesFromController(controllerType);

if (controllerName.StartsWith("Http"))
_httpConfiguration.AddRoutesFromController(controllerType);
}

[Given(@"I add the routes from controllers derived from the (.*) controller")]
public void GivenIAddTheRoutesFromControllersOfTypeBaseController(string baseControllerName)
{
var baseControllerType = GetControllerType(baseControllerName);
_configuration.AddRoutesFromControllersOfType(baseControllerType);

if (baseControllerName.StartsWith("Http"))
_httpConfiguration.AddRoutesFromControllersOfType(baseControllerType);
}

[When(@"I generate the routes with this configuration")]
public void WhenIGenerateTheRoutesWithThisConfiguration()
{
RouteTable.Routes.Clear();
RouteTable.Routes.MapAttributeRoutes(_configuration);
RouteTable.Routes.MapHttpAttributeRoutes(_httpConfiguration);
}

[Then(@"the routes from the (.*) controller precede those from the (.*) controller")]
Expand All @@ -58,6 +68,9 @@ public void ThenTheRoutesFromTheFirstControllerPrecedeThoseFromTheNextController

private Type GetControllerType(string controllerName)
{
if (controllerName.StartsWith("Http"))
controllerName = "Http." + controllerName;

var typeName = String.Format("AttributeRouting.Specs.Subjects.{0}Controller, AttributeRouting.Specs",
controllerName);

Expand Down

0 comments on commit 4c9e264

Please sign in to comment.