CR feedback again

This commit is contained in:
Ryan Nowak 2014-03-06 12:18:31 -08:00
parent f43985b58d
commit f604fb8d87
7 changed files with 33 additions and 32 deletions

View File

@ -21,10 +21,11 @@ namespace RoutingSample
context.IsHandled = true; context.IsHandled = true;
} }
public void BindPath(BindPathContext context) public string BindPath(BindPathContext context)
{ {
// We can generate a url for anything that the parent route deems OK. // We don't really care what the values look like.
context.IsBound = true; context.IsBound = true;
return null;
} }
} }
} }

View File

@ -50,9 +50,9 @@ namespace RoutingSample
} }
} }
public void BindPath(BindPathContext context) public string BindPath(BindPathContext context)
{ {
// Do nothing return null;
} }
} }
} }

View File

@ -20,8 +20,6 @@ namespace Microsoft.AspNet.Routing
public bool IsBound { get; set; } public bool IsBound { get; set; }
public string BoundPath { get; set; }
public IDictionary<string, object> Values { get; private set; } public IDictionary<string, object> Values { get; private set; }
} }
} }

View File

@ -8,6 +8,6 @@ namespace Microsoft.AspNet.Routing
{ {
Task RouteAsync(RouteContext context); Task RouteAsync(RouteContext context);
void BindPath(BindPathContext context); string BindPath(BindPathContext context);
} }
} }

View File

@ -2,7 +2,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Abstractions;
namespace Microsoft.AspNet.Routing namespace Microsoft.AspNet.Routing
{ {
@ -41,18 +40,20 @@ namespace Microsoft.AspNet.Routing
} }
} }
public virtual void BindPath(BindPathContext context) public virtual string BindPath(BindPathContext context)
{ {
for (var i = 0; i < Count; i++) for (var i = 0; i < Count; i++)
{ {
var route = this[i]; var route = this[i];
route.BindPath(context); var path = route.BindPath(context);
if (context.IsBound) if (path != null)
{ {
return; return path;
} }
} }
return null;
} }
} }
} }

View File

@ -75,28 +75,29 @@ namespace Microsoft.AspNet.Routing.Template
} }
} }
public void BindPath(BindPathContext context) public string BindPath(BindPathContext context)
{ {
// Validate that the target can accept these values. // Validate that the target can accept these values - if the target generates a value
_target.BindPath(context); // then that can short circuit.
if (!context.IsBound) var path = _target.BindPath(context);
if (path != null)
{ {
return; return path;
}
else if (!context.IsBound)
{
return null;
} }
// This could be optimized more heavily - right now we try to do the full url // 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. // generation after validating, but we could do it in two phases.
var path = _binder.Bind(_defaults, context.AmbientValues, context.Values); path = _binder.Bind(_defaults, context.AmbientValues, context.Values);
if (path == null) if (path == null)
{ {
context.IsBound = false; context.IsBound = false;
return;
}
else
{
Debug.Assert(context.IsBound);
context.BoundPath = path;
} }
return path;
} }
} }
} }

View File

@ -113,11 +113,11 @@ namespace Microsoft.AspNet.Routing.Template.Tests
var context = CreateRouteBindContext(new {controller = "Home"}); var context = CreateRouteBindContext(new {controller = "Home"});
// Act // Act
route.BindPath(context); var path = route.BindPath(context);
// Assert // Assert
Assert.True(context.IsBound); Assert.True(context.IsBound);
Assert.Equal("Home", context.BoundPath); Assert.Equal("Home", path);
} }
[Fact] [Fact]
@ -128,11 +128,11 @@ namespace Microsoft.AspNet.Routing.Template.Tests
var context = CreateRouteBindContext(new { controller = "Home" }); var context = CreateRouteBindContext(new { controller = "Home" });
// Act // Act
route.BindPath(context); var path = route.BindPath(context);
// Assert // Assert
Assert.False(context.IsBound); Assert.False(context.IsBound);
Assert.Null(context.BoundPath); Assert.Null(path);
} }
[Fact] [Fact]
@ -143,11 +143,11 @@ namespace Microsoft.AspNet.Routing.Template.Tests
var context = CreateRouteBindContext(new { controller = "Home" }); var context = CreateRouteBindContext(new { controller = "Home" });
// Act // Act
route.BindPath(context); var path = route.BindPath(context);
// Assert // Assert
Assert.False(context.IsBound); Assert.False(context.IsBound);
Assert.Null(context.BoundPath); Assert.Null(path);
} }
[Fact] [Fact]
@ -158,11 +158,11 @@ namespace Microsoft.AspNet.Routing.Template.Tests
var context = CreateRouteBindContext(new { action = "Index"}, new { controller = "Home" }); var context = CreateRouteBindContext(new { action = "Index"}, new { controller = "Home" });
// Act // Act
route.BindPath(context); var path = route.BindPath(context);
// Assert // Assert
Assert.True(context.IsBound); Assert.True(context.IsBound);
Assert.Equal("Home/Index", context.BoundPath); Assert.Equal("Home/Index", path);
} }
private static BindPathContext CreateRouteBindContext(object values) private static BindPathContext CreateRouteBindContext(object values)