Ejemplo n.º 1
0
        private static RouteData TestRouteViaMocks(string url, object expectedValues)
        {
            // Arrange (obtain routing config + set up test context)
            RouteCollection routeConfig = new RouteCollection();

            MvcApplication.RegisterRoutes(routeConfig);
            var mockHttpContext = RoutingMockHelpers.MakeMockHttpContext(url);
            // Act (run the routing engine against this HttpContextBase)
            RouteData routeData = routeConfig.GetRouteData(mockHttpContext.Object);

            // Assert
            Assert.IsNotNull(routeData.Route, "No route was matched");
            var expectedDict = new RouteValueDictionary(expectedValues);

            foreach (var expectedVal in expectedDict)
            {
                if (expectedVal.Value == null)
                {
                    Assert.IsNull(routeData.Values[expectedVal.Key]);
                }
                else
                {
                    Assert.AreEqual(expectedVal.Value.ToString(),
                                    routeData.Values[expectedVal.Key].ToString());
                }
            }
            return(routeData); // ... in case the caller wants to add any other assertions
        }
Ejemplo n.º 2
0
        private string GenerateUrlViaMocks(object values)
        {
            // Arrange (get the routing config and test context)
            RouteCollection routeConfig = new RouteCollection();

            RegisterAllAreas(routeConfig);
            MvcApplication.RegisterRoutes(routeConfig);
            var            mockContext = RoutingMockHelpers.MakeMockHttpContext(null);
            RequestContext context     = new RequestContext(mockContext.Object, new RouteData());

            // Act (generate a URL)
            return(UrlHelper.GenerateUrl(null, null, null,
                                         new RouteValueDictionary(values), routeConfig, context, true));
        }