帮手:
public static MvcHtmlString RouteLink(this HtmlHelper helper, String linkText, String routeName, Object routeValues, String status)
{
if (status.ToLower() == "post-game" || status.ToLower() == "mid-game")
{
return helper.RouteLink(linkText, routeName, routeValues);
}
return MvcHtmlString.Create(" ");
}
单元测试:
[TestMethod]
public void RouteLinkTest()
{
var httpContext = new Mock<HttpContextBase>();
var routeData = new Mock<RouteData>();
var viewContext = new ViewContext { HttpContext = httpContext.Object, RouteData = routeData.Object };
var helper = new HtmlHelper(viewContext, new Mock<IViewDataContainer>().Object);
var target01 = helper.RouteLink("Linking Text", "route-name", new { id = "id" }, "status");
Assert.IsNotNull(target01);
}
错误:
Test method Web.Tests.Extensions.HtmlHelpersTest.RouteLinkTest threw exception:
System.ArgumentException: A route named 'route-name' could not be found in the route collection.
Parameter name: name
问题:如何模拟路线以获得正确的路线名称?