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)); }
private static string GenerateUrlViaTestDouble(object values) { // Arrange (get the routing config and test context) RouteCollection routeConfig = new RouteCollection(); RegisterAllAreas(routeConfig); MvcApplication.RegisterRoutes(routeConfig); var testContext = new TestHttpContext(null); RequestContext context = new RequestContext(testContext, new RouteData()); // Act (generate a URL) return(UrlHelper.GenerateUrl(null, null, null, /* Explained below */ new RouteValueDictionary(values), routeConfig, context, true)); }
string GetOutboundUrl(object routeValues) { // Get route configuration and mock request context RouteCollection routes = new RouteCollection(); MvcApplication.RegisterRoutes(routes); var mockHttpContext = new Moq.Mock <HttpContextBase>(); var mockRequest = new Moq.Mock <HttpRequestBase>(); var fakeResponse = new FakeResponse(); mockHttpContext.Setup(x => x.Request).Returns(mockRequest.Object); mockHttpContext.Setup(x => x.Response).Returns(fakeResponse); mockRequest.Setup(x => x.ApplicationPath).Returns("/"); // Generate the outbound URL var ctx = new RequestContext(mockHttpContext.Object, new RouteData()); return(routes.GetVirtualPath(ctx, new RouteValueDictionary(routeValues)) .VirtualPath); }
public void Setup() { RouteTable.Routes.Clear(); MvcApplication.RegisterRoutes(RouteTable.Routes); }