2014-09-03 90 views
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文件

鈣任何人都幫助我?

回答

0

參見: Mvc 5.1 MissingMethodException System.Web.WebPages.TypeHelper.ObjectToDictionaryUncached

「在我發現引用System.Web.WebPages.dll版本3.0.11001.0顯示了這種類型的錯誤,但是當我用System.Web.WebPages.dll版本來替換它3.0.20129.0它的工作原理簡單地說,你應該從引用中刪除舊的,並下載另一個版本,而不是乾淨的解決方案,重建,它將工作。「

+0

感謝您的幫助....我爲此奮鬥了幾天:) – Twix 2014-09-04 06:08:12