GetVirtualPath() public method

Used to get a virtual path for a given set of route settings. If the combination of defaults/values doesn't satisfy the url generator tokens: null is returned, signaling that this route isn't correct for the given values.
This function is not used for figuring out the routes. It is only used for generating links for new routes.
public GetVirtualPath ( System.Web.Routing.RequestContext requestContext, RouteValueDictionary values ) : System.Web.Routing.VirtualPathData
requestContext System.Web.Routing.RequestContext The request context.
values RouteValueDictionary The settings to use to generate this virtual path.
return System.Web.Routing.VirtualPathData
Exemplo n.º 1
0
 public void RouteGeneratorReturnsNullWhenNotAllParametersFilledIn()
 {
     var route = new RegexRoute(@"(?<Controller>[a-zA-Z]+)(_(?<Action>[a-zA-Z]+))?(_?<Id>\d+)?",
                                "{Controller}_{Action}_{Id}", handler);
     RouteData routeData = route.GetRouteData("Products_View_0");
     VirtualPathData pathData = route.GetVirtualPath(new RequestContext(mr.PartialMock<HttpContextBase>(), routeData),
                                                     new RouteValueDictionary(
                                                         new {Controller = "Accounts", Action = "Delete"}));
     Assert.IsNull(pathData);
 }
Exemplo n.º 2
0
 public void RouteGeneratorCallsCustomFunctionIfProvided()
 {
     bool called = false;
     RequestContext innerContext = null;
     RouteValueDictionary innerRouteValues = null;
     RegexRoute innerRoute = null;
     VirtualPathData innerPathData = null;
     var route = new RegexRoute(
         @"(?<Controller>[a-zA-Z]+)(_(?<Action>[a-zA-Z]+))?(_?<Id>\d+)?",
         delegate(RequestContext context, RouteValueDictionary routeValues, RegexRoute thisRoute)
             {
                 called = true;
                 innerContext = context;
                 innerRouteValues = routeValues;
                 innerRoute = thisRoute;
                 innerPathData = new VirtualPathData(thisRoute, "");
                 return innerPathData;
             },
         handler);
     RouteData routeData = route.GetRouteData("Products_View_0");
     var values = new RouteValueDictionary(new {Controller = "Accounts", Action = "Delete", Id = 0});
     var requestContext = new RequestContext(mr.PartialMock<HttpContextBase>(), routeData);
     VirtualPathData pathData = route.GetVirtualPath(
         requestContext,
         values);
     Assert.IsTrue(called);
     Assert.IsNotNull(innerContext);
     Assert.AreSame(requestContext, innerContext);
     Assert.IsNotNull(innerRouteValues);
     Assert.AreSame(values, innerRouteValues);
     Assert.IsNotNull(innerRoute);
     Assert.AreSame(route, innerRoute);
     Assert.IsNotNull(pathData);
     Assert.AreSame(pathData, innerPathData);
 }
Exemplo n.º 3
0
 public void RouteGeneratorGeneratesValidRouteWithoutDefaults()
 {
     var route = new RegexRoute(@"(?<Controller>[a-zA-Z]+)(_(?<Action>[a-zA-Z]+))?(_?<Id>\d+)?",
                                "{Controller}_{Action}_{Id}", handler);
     RouteData routeData = route.GetRouteData("Products_View_0");
     VirtualPathData pathData = route.GetVirtualPath(new RequestContext(mr.PartialMock<HttpContextBase>(), routeData),
                                                     new RouteValueDictionary(
                                                         new {Controller = "Accounts", Action = "Delete", Id = 0}));
     Assert.AreEqual("Accounts_Delete_0", pathData.VirtualPath);
 }