0
我在MVC中爲測試路由創建一個測試項目。mvc路由單元測試中的測試方法出錯
我在這一行收到此錯誤
Test Name: RouteWithControllerNoActionNoId
Test FullName: test.Web.Tests.Routing.TestRoute.RouteWithControllerNoActionNoId
Test Source: d:\newtest\test.Web.Tests\Routing\TestRoute.cs : line 17
Test Outcome: Failed
Test Duration: 0:00:06.6382043
Result Message:
Test method test.Web.Tests.Routing.TestRoute.RouteWithControllerNoActionNoId threw exception:
System.MissingMethodException: Method not found: 'System.Web.Routing.RouteValueDictionary System.Web.WebPages.TypeHelper.ObjectToDictionaryUncached(System.Object)'.
Result StackTrace:
at System.Web.Mvc.RouteCollectionExtensions.CreateRouteValueDictionaryUncached(Object values)
at System.Web.Mvc.RouteCollectionExtensions.IgnoreRoute(RouteCollection routes, String url, Object constraints)
at System.Web.Mvc.RouteCollectionExtensions.IgnoreRoute(RouteCollection routes, String url)
at test.Web.RouteConfig.RegisterRoutes(RouteCollection routes) in d:\newtest\test.Web\App_Start\RouteConfig.cs:line 15
at test.Wesb.Tests.Routing.TestRoute.RouteWithControllerNoActionNoId() in d:\newtest\test.Web.Tests\Routing\TestRoute.cs:line 21
這是我的示例代碼
[TestMethod]
public void RouteWithControllerNoActionNoId()
{
// Arrange
var context = new StubHttpContextForRouting(requestUrl: "~/Home");
var routes = new RouteCollection();
RouteConfig.RegisterRoutes(routes);
// Act
RouteData routeData = routes.GetRouteData(context);
// Assert
Assert.IsNotNull(routeData);
Assert.AreEqual("Home", routeData.Values["controller"]);
Assert.AreEqual("Index", routeData.Values["action"]);
Assert.AreEqual(UrlParameter.Optional, routeData.Values["id"]);
}
我收到錯誤
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
在我RouteConfig
文件
鈣任何人都幫助我?
感謝您的幫助....我爲此奮鬥了幾天:) – Twix 2014-09-04 06:08:12