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);
        }
Esempio n. 2
0
 public void Setup()
 {
     RouteTable.Routes.Clear();
     MvcApplication.RegisterRoutes(RouteTable.Routes);
 }