Rename BindPath (CR Feedback)
This commit is contained in:
parent
f5a43708ee
commit
da057820e5
|
|
@ -21,7 +21,7 @@ namespace RoutingSample
|
|||
context.IsHandled = true;
|
||||
}
|
||||
|
||||
public string BindPath(BindPathContext context)
|
||||
public string GetVirtualPath(VirtualPathContext context)
|
||||
{
|
||||
// We don't really care what the values look like.
|
||||
context.IsBound = true;
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ namespace RoutingSample
|
|||
}
|
||||
}
|
||||
|
||||
public string BindPath(BindPathContext context)
|
||||
public string GetVirtualPath(VirtualPathContext context)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,6 @@ namespace Microsoft.AspNet.Routing
|
|||
{
|
||||
Task RouteAsync(RouteContext context);
|
||||
|
||||
string BindPath(BindPathContext context);
|
||||
string GetVirtualPath(VirtualPathContext context);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,13 +40,13 @@ namespace Microsoft.AspNet.Routing
|
|||
}
|
||||
}
|
||||
|
||||
public virtual string BindPath(BindPathContext context)
|
||||
public virtual string GetVirtualPath(VirtualPathContext context)
|
||||
{
|
||||
for (var i = 0; i < Count; i++)
|
||||
{
|
||||
var route = this[i];
|
||||
|
||||
var path = route.BindPath(context);
|
||||
var path = route.GetVirtualPath(context);
|
||||
if (path != null)
|
||||
{
|
||||
return path;
|
||||
|
|
|
|||
|
|
@ -78,10 +78,10 @@ namespace Microsoft.AspNet.Routing.Template
|
|||
}
|
||||
}
|
||||
|
||||
public string BindPath(BindPathContext context)
|
||||
public string GetVirtualPath(VirtualPathContext context)
|
||||
{
|
||||
// Validate that the target can accept these values.
|
||||
var path = _target.BindPath(context);
|
||||
var path = _target.GetVirtualPath(context);
|
||||
if (path != null)
|
||||
{
|
||||
// If the target generates a value then that can short circuit.
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ using Microsoft.AspNet.Abstractions;
|
|||
|
||||
namespace Microsoft.AspNet.Routing
|
||||
{
|
||||
public class BindPathContext
|
||||
public class VirtualPathContext
|
||||
{
|
||||
public BindPathContext(HttpContext context, IDictionary<string, object> ambientValues, IDictionary<string, object> values)
|
||||
public VirtualPathContext(HttpContext context, IDictionary<string, object> ambientValues, IDictionary<string, object> values)
|
||||
{
|
||||
Context = context;
|
||||
AmbientValues = ambientValues;
|
||||
|
|
@ -92,9 +92,9 @@ namespace Microsoft.AspNet.Routing.Tests
|
|||
{
|
||||
var target = new Mock<IRouter>(MockBehavior.Strict);
|
||||
target
|
||||
.Setup(e => e.BindPath(It.IsAny<BindPathContext>()))
|
||||
.Callback<BindPathContext>(c => c.IsBound = accept)
|
||||
.Returns<BindPathContext>(null)
|
||||
.Setup(e => e.GetVirtualPath(It.IsAny<VirtualPathContext>()))
|
||||
.Callback<VirtualPathContext>(c => c.IsBound = accept)
|
||||
.Returns<VirtualPathContext>(null)
|
||||
.Verifiable();
|
||||
|
||||
target
|
||||
|
|
|
|||
|
|
@ -106,14 +106,14 @@ namespace Microsoft.AspNet.Routing.Template.Tests
|
|||
#region Route Binding
|
||||
|
||||
[Fact]
|
||||
public void Bind_Success()
|
||||
public void GetVirtualPath_Success()
|
||||
{
|
||||
// Arrange
|
||||
var route = CreateRoute("{controller}");
|
||||
var context = CreateRouteBindContext(new {controller = "Home"});
|
||||
var context = CreateVirtualPathContext(new {controller = "Home"});
|
||||
|
||||
// Act
|
||||
var path = route.BindPath(context);
|
||||
var path = route.GetVirtualPath(context);
|
||||
|
||||
// Assert
|
||||
Assert.True(context.IsBound);
|
||||
|
|
@ -121,14 +121,14 @@ namespace Microsoft.AspNet.Routing.Template.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void Bind_Fail()
|
||||
public void GetVirtualPath_Fail()
|
||||
{
|
||||
// Arrange
|
||||
var route = CreateRoute("{controller}/{action}");
|
||||
var context = CreateRouteBindContext(new { controller = "Home" });
|
||||
var context = CreateVirtualPathContext(new { controller = "Home" });
|
||||
|
||||
// Act
|
||||
var path = route.BindPath(context);
|
||||
var path = route.GetVirtualPath(context);
|
||||
|
||||
// Assert
|
||||
Assert.False(context.IsBound);
|
||||
|
|
@ -136,14 +136,14 @@ namespace Microsoft.AspNet.Routing.Template.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void Bind_RejectedByHandler()
|
||||
public void GetVirtualPath_RejectedByHandler()
|
||||
{
|
||||
// Arrange
|
||||
var route = CreateRoute("{controller}", accept: false);
|
||||
var context = CreateRouteBindContext(new { controller = "Home" });
|
||||
var context = CreateVirtualPathContext(new { controller = "Home" });
|
||||
|
||||
// Act
|
||||
var path = route.BindPath(context);
|
||||
var path = route.GetVirtualPath(context);
|
||||
|
||||
// Assert
|
||||
Assert.False(context.IsBound);
|
||||
|
|
@ -151,35 +151,35 @@ namespace Microsoft.AspNet.Routing.Template.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void Bind_Success_AmbientValues()
|
||||
public void GetVirtualPath_Success_AmbientValues()
|
||||
{
|
||||
// Arrange
|
||||
var route = CreateRoute("{controller}/{action}");
|
||||
var context = CreateRouteBindContext(new { action = "Index"}, new { controller = "Home" });
|
||||
var context = CreateVirtualPathContext(new { action = "Index"}, new { controller = "Home" });
|
||||
|
||||
// Act
|
||||
var path = route.BindPath(context);
|
||||
var path = route.GetVirtualPath(context);
|
||||
|
||||
// Assert
|
||||
Assert.True(context.IsBound);
|
||||
Assert.Equal("Home/Index", path);
|
||||
}
|
||||
|
||||
private static BindPathContext CreateRouteBindContext(object values)
|
||||
private static VirtualPathContext CreateVirtualPathContext(object values)
|
||||
{
|
||||
return CreateRouteBindContext(new RouteValueDictionary(values), null);
|
||||
return CreateVirtualPathContext(new RouteValueDictionary(values), null);
|
||||
}
|
||||
|
||||
private static BindPathContext CreateRouteBindContext(object values, object ambientValues)
|
||||
private static VirtualPathContext CreateVirtualPathContext(object values, object ambientValues)
|
||||
{
|
||||
return CreateRouteBindContext(new RouteValueDictionary(values), new RouteValueDictionary(ambientValues));
|
||||
return CreateVirtualPathContext(new RouteValueDictionary(values), new RouteValueDictionary(ambientValues));
|
||||
}
|
||||
|
||||
private static BindPathContext CreateRouteBindContext(IDictionary<string, object> values, IDictionary<string, object> ambientValues)
|
||||
private static VirtualPathContext CreateVirtualPathContext(IDictionary<string, object> values, IDictionary<string, object> ambientValues)
|
||||
{
|
||||
var context = new Mock<HttpContext>(MockBehavior.Strict);
|
||||
|
||||
return new BindPathContext(context.Object, ambientValues, values);
|
||||
return new VirtualPathContext(context.Object, ambientValues, values);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -198,8 +198,9 @@ namespace Microsoft.AspNet.Routing.Template.Tests
|
|||
{
|
||||
var target = new Mock<IRouter>(MockBehavior.Strict);
|
||||
target
|
||||
.Setup(e => e.BindPath(It.IsAny<BindPathContext>()))
|
||||
.Callback<BindPathContext>(c => c.IsBound = accept);
|
||||
.Setup(e => e.GetVirtualPath(It.IsAny<VirtualPathContext>()))
|
||||
.Callback<VirtualPathContext>(c => c.IsBound = accept)
|
||||
.Returns<VirtualPathContext>(rc => null);
|
||||
|
||||
target
|
||||
.Setup(e => e.RouteAsync(It.IsAny<RouteContext>()))
|
||||
|
|
|
|||
Loading…
Reference in New Issue