String URL to RouteValueDictionary

前端 未结 4 718
盖世英雄少女心
盖世英雄少女心 2020-11-27 18:02

Is there as easy way to convert string URL to RouteValueDictionary collection? Some method like UrlToRouteValueDictionary(string url).

I need such metho

4条回答
  •  旧时难觅i
    2020-11-27 18:31

    You would need to create a mocked HttpContext as routes constrains requires it.

    Here is an example that I use to unit test my routes (it was copied from Pro ASP.Net MVC framework):

            RouteCollection routeConfig = new RouteCollection();
            MvcApplication.RegisterRoutes(routeConfig);
            var mockHttpContext = new MockedHttpContext(url);
            RouteData routeData = routeConfig.GetRouteData(mockHttpContext.Object);
            // routeData.Values is an instance of RouteValueDictionary
            //...
    

提交回复
热议问题