From f43985b58d849fae0eaae9ff7391dfbb01c86564 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Thu, 6 Mar 2014 11:27:37 -0800 Subject: [PATCH] CR feedback --- .../RouteCollectionExtensions.cs | 2 +- samples/RoutingSample/Startup.cs | 2 +- .../RouteCollectionExtensions.cs | 5 ++-- .../Template/TemplateRoute.cs | 24 ++++++++++++------- .../Template/TemplateRouteTests.cs | 2 +- 5 files changed, 21 insertions(+), 14 deletions(-) rename src/Microsoft.AspNet.Routing/{Template => }/RouteCollectionExtensions.cs (87%) diff --git a/samples/RoutingSample/RouteCollectionExtensions.cs b/samples/RoutingSample/RouteCollectionExtensions.cs index ac557efd86..d1581153ab 100644 --- a/samples/RoutingSample/RouteCollectionExtensions.cs +++ b/samples/RoutingSample/RouteCollectionExtensions.cs @@ -11,7 +11,7 @@ namespace RoutingSample { if (routes.DefaultHandler == null) { - throw new InvalidOperationException("DefaultHandler must be set."); + throw new ArgumentException("DefaultHandler must be set."); } return AddPrefixRoute(routes, prefix, routes.DefaultHandler); diff --git a/samples/RoutingSample/Startup.cs b/samples/RoutingSample/Startup.cs index f4d39a1a2e..9f187829a4 100644 --- a/samples/RoutingSample/Startup.cs +++ b/samples/RoutingSample/Startup.cs @@ -3,7 +3,7 @@ #if NET45 using Microsoft.AspNet.Abstractions; -using Microsoft.AspNet.Routing.Template; +using Microsoft.AspNet.Routing; using Owin; namespace RoutingSample diff --git a/src/Microsoft.AspNet.Routing/Template/RouteCollectionExtensions.cs b/src/Microsoft.AspNet.Routing/RouteCollectionExtensions.cs similarity index 87% rename from src/Microsoft.AspNet.Routing/Template/RouteCollectionExtensions.cs rename to src/Microsoft.AspNet.Routing/RouteCollectionExtensions.cs index 80b04c97ec..9627b618cf 100644 --- a/src/Microsoft.AspNet.Routing/Template/RouteCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Routing/RouteCollectionExtensions.cs @@ -2,8 +2,9 @@ using System; using System.Collections.Generic; +using Microsoft.AspNet.Routing.Template; -namespace Microsoft.AspNet.Routing.Template +namespace Microsoft.AspNet.Routing { public static class RouteCollectionExtensions { @@ -23,7 +24,7 @@ namespace Microsoft.AspNet.Routing.Template { if (routes.DefaultHandler == null) { - throw new InvalidOperationException("DefaultHandler must be set."); + throw new ArgumentException("DefaultHandler must be set."); } routes.Add(new TemplateRoute(routes.DefaultHandler, template, defaults)); diff --git a/src/Microsoft.AspNet.Routing/Template/TemplateRoute.cs b/src/Microsoft.AspNet.Routing/Template/TemplateRoute.cs index e980f58ccd..8d1f0a1839 100644 --- a/src/Microsoft.AspNet.Routing/Template/TemplateRoute.cs +++ b/src/Microsoft.AspNet.Routing/Template/TemplateRoute.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Threading.Tasks; using Microsoft.AspNet.Abstractions; @@ -76,20 +77,25 @@ namespace Microsoft.AspNet.Routing.Template public void BindPath(BindPathContext context) { - // This could be optimized more heavily - right now we try to do the full url - // generation before validating, but we could do it in two phases. - var path = _binder.Bind(_defaults, context.AmbientValues, context.Values); - if (path == null) + // Validate that the target can accept these values. + _target.BindPath(context); + if (!context.IsBound) { return; } - context.BoundPath = path; - _target.BindPath(context); - - if (!context.IsBound) + // This could be optimized more heavily - right now we try to do the full url + // generation after validating, but we could do it in two phases. + var path = _binder.Bind(_defaults, context.AmbientValues, context.Values); + if (path == null) { - context.BoundPath = null; + context.IsBound = false; + return; + } + else + { + Debug.Assert(context.IsBound); + context.BoundPath = path; } } } diff --git a/test/Microsoft.AspNet.Routing.Tests/Template/TemplateRouteTests.cs b/test/Microsoft.AspNet.Routing.Tests/Template/TemplateRouteTests.cs index 2baaaf3a69..4a6d40a39d 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Template/TemplateRouteTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Template/TemplateRouteTests.cs @@ -76,7 +76,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests } [Fact] - public async void Match_RejectedByHanlder() + public async void Match_RejectedByHandler() { // Arrange var route = CreateRoute("{controller}", accept: false);