Permalink
Browse files

RouteConvention spec fix and RoutePrecedence specs

Also fixed an issue where the MVC-based config was accepting promoted
controllers of the Api controller types
  • Loading branch information...
1 parent 10c4194 commit 4c9e264ab814c68787dc9d0f5375aa6695e71da1 @kamranayub committed Apr 7, 2012
@@ -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" />
@@ -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
@@ -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"
@@ -167,22 +167,54 @@ public virtual void GeneratingRoutesUsingTheDefaultHttpRouteConvention(string ac
}
[NUnit.Framework.TestAttribute()]
+ [NUnit.Framework.DescriptionAttribute("Generating routes using the DefaultHttpRouteConventionPrefix on controllers with " +
+ "a RoutePrefix attribute")]
+ [NUnit.Framework.TestCaseAttribute("GetAll", "GET", "Prefix", new string[0])]
+ [NUnit.Framework.TestCaseAttribute("Get", "GET", "Prefix/{id}", new string[0])]
+ [NUnit.Framework.TestCaseAttribute("Post", "POST", "Prefix", new string[0])]
+ [NUnit.Framework.TestCaseAttribute("Put", "PUT", "Prefix/{id}", new string[0])]
+ [NUnit.Framework.TestCaseAttribute("Delete", "DELETE", "Prefix/{id}", new string[0])]
+ [NUnit.Framework.TestCaseAttribute("Custom", "GET", "Prefix/Custom", new string[0])]
+ public virtual void GeneratingRoutesUsingTheDefaultHttpRouteConventionPrefixOnControllersWithARoutePrefixAttribute(string action, string method, string url, string[] exampleTags)
+ {
+ TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Generating routes using the DefaultHttpRouteConventionPrefix on controllers with " +
+ "a RoutePrefix attribute", exampleTags);
+#line 59
+this.ScenarioSetup(scenarioInfo);
+#line 3
+this.FeatureBackground();
+#line 60
+ testRunner.When(string.Format("I fetch the routes for the DefaultHttpRouteConventionPrefix controller\'s {0} acti" +
+ "on", action));
+#line 61
+ testRunner.Then(string.Format("the route url is \"{0}\"", url));
+#line 62
+ testRunner.And("the default for \"controller\" is \"DefaultHttpRouteConventionPrefix\"");
+#line 63
+ testRunner.And(string.Format("the default for \"action\" is \"{0}\"", action));
+#line 64
+ testRunner.And(string.Format("the route for {0} is constrained to {1} requests", action, method));
+#line hidden
+ this.ScenarioCleanup();
+ }
+
+ [NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("Generating routes using the RestfulRouteConvention on actions with an explicit ro" +
"ute defined")]
public virtual void GeneratingRoutesUsingTheRestfulRouteConventionOnActionsWithAnExplicitRouteDefined()
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Generating routes using the RestfulRouteConvention on actions with an explicit ro" +
"ute defined", ((string[])(null)));
-#line 59
+#line 75
this.ScenarioSetup(scenarioInfo);
#line 3
this.FeatureBackground();
-#line 60
+#line 76
testRunner.When("I fetch the routes for the RestfulRouteConventionWithExplicitRoute controller\'s I" +
"ndex action");
-#line 61
+#line 77
testRunner.Then("the 1st route url is \"RestfulRouteConventionWithExplicitRoute\"");
-#line 62
+#line 78
testRunner.And("the 2nd route url is \"Legacy\"");
#line hidden
this.ScenarioCleanup();
@@ -195,16 +227,16 @@ public virtual void GeneratingRoutesUsingTheRestfulRouteConventionOnActionsWithA
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Generating routes using the RestfulRouteConvention on actions with an explicit or" +
"dered route defined", ((string[])(null)));
-#line 64
+#line 80
this.ScenarioSetup(scenarioInfo);
#line 3
this.FeatureBackground();
-#line 65
+#line 81
testRunner.When("I fetch the routes for the RestfulRouteConventionWithExplicitOrderedRoute control" +
"ler\'s Index action");
-#line 66
+#line 82
testRunner.Then("the 1st route url is \"RestfulRouteConventionWithExplicitOrderedRoute/Primary\"");
-#line 67
+#line 83
testRunner.And("the 2nd route url is \"RestfulRouteConventionWithExplicitOrderedRoute\"");
#line hidden
this.ScenarioCleanup();
@@ -217,16 +249,16 @@ public virtual void GeneratingRoutesUsingTheDefaultHttpRouteConventionOnActionsW
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Generating routes using the DefaultHttpRouteConvention on actions with an explici" +
"t route defined", ((string[])(null)));
-#line 69
+#line 85
this.ScenarioSetup(scenarioInfo);
#line 3
this.FeatureBackground();
-#line 70
+#line 86
testRunner.When("I fetch the routes for the DefaultHttpRouteConventionWithExplicitRoute controller" +
"\'s Get action");
-#line 71
+#line 87
testRunner.Then("the 1st route url is \"DefaultHttpRouteConventionWithExplicitRoute\"");
-#line 72
+#line 88
testRunner.And("the 2nd route url is \"Legacy\"");
#line hidden
this.ScenarioCleanup();
@@ -239,17 +271,17 @@ public virtual void GeneratingRoutesUsingTheDefaultHttpRouteConventionOnActionsW
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Generating routes using the DefaultHttpRouteConvention on actions with an explici" +
"t ordered route defined", ((string[])(null)));
-#line 74
+#line 90
this.ScenarioSetup(scenarioInfo);
#line 3
this.FeatureBackground();
-#line 75
+#line 91
testRunner.When("I fetch the routes for the DefaultHttpRouteConventionWithExplicitOrderedRoute con" +
- "troller\'s Index action");
-#line 76
+ "troller\'s Get action");
+#line 92
testRunner.Then("the 1st route url is \"DefaultHttpRouteConventionWithExplicitOrderedRoute/Primary\"" +
"");
-#line 77
+#line 93
testRunner.And("the 2nd route url is \"DefaultHttpRouteConventionWithExplicitOrderedRoute\"");
#line hidden
this.ScenarioCleanup();
@@ -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
@@ -176,6 +176,114 @@ public virtual void RoutePrecedenceAmongControllersAddedByBaseTypeUsingTheConfig
#line hidden
this.ScenarioCleanup();
}
+
+ [NUnit.Framework.TestAttribute()]
+ [NUnit.Framework.DescriptionAttribute("Web API route precedence among routes for an action using the Order property")]
+ public virtual void WebAPIRoutePrecedenceAmongRoutesForAnActionUsingTheOrderProperty()
+ {
+ TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Web API route precedence among routes for an action using the Order property", ((string[])(null)));
+#line 38
+this.ScenarioSetup(scenarioInfo);
+#line 3
+this.FeatureBackground();
+#line 39
+ testRunner.When("I fetch the routes for the HttpRoutePrecedenceAmongRoutes controller\'s Get action" +
+ "");
+#line 40
+ testRunner.Then("3 routes are found");
+#line 41
+ testRunner.And("the 1st route\'s url is \"Get/First\"");
+#line 42
+ testRunner.And("the 2nd route\'s url is \"Get/Second\"");
+#line 43
+ testRunner.And("the 3rd route\'s url is \"Get/Third\"");
+#line hidden
+ this.ScenarioCleanup();
+ }
+
+ [NUnit.Framework.TestAttribute()]
+ [NUnit.Framework.DescriptionAttribute("Web API route precedence among actions within a controller using the Precedence p" +
+ "roperty")]
+ public virtual void WebAPIRoutePrecedenceAmongActionsWithinAControllerUsingThePrecedenceProperty()
+ {
+ TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Web API route precedence among actions within a controller using the Precedence p" +
+ "roperty", ((string[])(null)));
+#line 45
+this.ScenarioSetup(scenarioInfo);
+#line 3
+this.FeatureBackground();
+#line 46
+ testRunner.When("I fetch the routes for the HttpRoutePrecedenceAmongActions controller");
+#line 47
+ testRunner.Then("the 1st route\'s url is \"ApiRoute1\"");
+#line 48
+ testRunner.And("the 2nd route\'s url is \"ApiRoute2\"");
+#line 49
+ testRunner.And("the 3rd route\'s url is \"ApiRoute3\"");
+#line hidden
+ this.ScenarioCleanup();
+ }
+
+ [NUnit.Framework.TestAttribute()]
+ [NUnit.Framework.DescriptionAttribute("Web API route precedence among controllers added individually using the configura" +
+ "tion api")]
+ public virtual void WebAPIRoutePrecedenceAmongControllersAddedIndividuallyUsingTheConfigurationApi()
+ {
+ TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Web API route precedence among controllers added individually using the configura" +
+ "tion api", ((string[])(null)));
+#line 51
+this.ScenarioSetup(scenarioInfo);
+#line 3
+this.FeatureBackground();
+#line 52
+ testRunner.Given("I have a new configuration object");
+#line 53
+ testRunner.And("I add the routes from the HttpRoutePrecedenceAmongControllers1 controller");
+#line 54
+ testRunner.And("I add the routes from the HttpRoutePrecedenceAmongControllers2 controller");
+#line 55
+ testRunner.And("I add the routes from the HttpRoutePrecedenceAmongControllers3 controller");
+#line 56
+ testRunner.When("I generate the routes with this configuration");
+#line 57
+ testRunner.Then("the routes from the HttpRoutePrecedenceAmongControllers1 controller precede those" +
+ " from the HttpRoutePrecedenceAmongControllers2 controller");
+#line 58
+ testRunner.And("the routes from the HttpRoutePrecedenceAmongControllers2 controller precede those" +
+ " from the HttpRoutePrecedenceAmongControllers3 controller");
+#line hidden
+ this.ScenarioCleanup();
+ }
+
+ [NUnit.Framework.TestAttribute()]
+ [NUnit.Framework.DescriptionAttribute("Web API route precedence among controllers added by base type using the configura" +
+ "tion api")]
+ public virtual void WebAPIRoutePrecedenceAmongControllersAddedByBaseTypeUsingTheConfigurationApi()
+ {
+ TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Web API route precedence among controllers added by base type using the configura" +
+ "tion api", ((string[])(null)));
+#line 60
+this.ScenarioSetup(scenarioInfo);
+#line 3
+this.FeatureBackground();
+#line 61
+ testRunner.Given("I have a new configuration object");
+#line 62
+ testRunner.And("I add the routes from controllers derived from the HttpRoutePrecedenceAmongDerive" +
+ "dControllersBase controller");
+#line 63
+ testRunner.And("I add the routes from the HttpRoutePrecedenceAmongControllers1 controller");
+#line 64
+ testRunner.When("I generate the routes with this configuration");
+#line 65
+ testRunner.Then("the routes from the HttpRoutePrecedenceAmongDerivedControllers1 controller preced" +
+ "e those from the HttpRoutePrecedenceAmongControllers1 controller");
+#line 66
+ testRunner.And("the routes from the HttpRoutePrecedenceAmongDerivedControllers2 controller preced" +
+ "e those from the HttpRoutePrecedenceAmongControllers1 controller");
+#line hidden
+ this.ScenarioCleanup();
+ }
}
}
#pragma warning restore
@@ -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;
@@ -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")]
@@ -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);
Oops, something went wrong.

0 comments on commit 4c9e264

Please sign in to comment.