Example #1
0
        private string GenerateUrlFromMock(object values)
        {
            var routes = new RouteCollection();
            var adminArea = new AdminAreaRegistration();
            var businessArea = new BusinessAreaRegistration();

            adminArea.RegisterArea(new AreaRegistrationContext(adminArea.AreaName, routes));
            businessArea.RegisterArea(new AreaRegistrationContext(businessArea.AreaName, routes));

            MvcApplication.RegisterRoutes(routes);

            var context = GetMockHttpContext(null);
            var reqContext = new RequestContext(context.Object, new RouteData());
            return UrlHelper.GenerateUrl(null, null, null, new RouteValueDictionary(values), routes, reqContext, true);
        }
Example #2
0
        private void TestIncomingRoute(string url, Dictionary<string, string> route)
        {
            RouteCollection routes = new RouteCollection();
            var adminArea = new AdminAreaRegistration();
            var businessArea = new BusinessAreaRegistration();
            adminArea.RegisterArea(new AreaRegistrationContext(adminArea.AreaName, routes));
            businessArea.RegisterArea(new AreaRegistrationContext(businessArea.AreaName, routes));
            MvcApplication.RegisterRoutes(routes);

            var httpContext = GetMockHttpContext(url);

            var routeData = routes.GetRouteData(httpContext.Object);

            Assert.IsNotNull(routeData, "route data should not be null");
            Assert.IsNotNull(routeData.Route, "route should not be null");

            foreach (var key in route.Keys)
            {
                if (route[key] == null)
                {
                    Assert.IsNull(routeData.Values[key]);
                }
                else
                {
                    Assert.AreEqual(route[key], routeData.Values[key], "unexptected value for {0}", key);
                }
            }
        }