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