GetRouteData() public method

Gets the route data from an incoming request; parses the incoming virtual path and returns the route data that was inside the url.
public GetRouteData ( System.Web.HttpContextBase httpContext ) : System.Web.Routing.RouteData
httpContext System.Web.HttpContextBase The HTTP context containing the url data.
return System.Web.Routing.RouteData
Example #1
0
		public void ShouldNotBeNullIfRouteIsMatched()
		{
			var route = new RegexRoute("asdf", handler);
			RouteData routeData = route.GetRouteData("asdf");
			Assert.AreSame(handler, routeData.RouteHandler);
			Assert.IsNotNull(routeData, "routeData should not be null if the path matched the regex");
		}
Example #2
0
		public void ShouldHaveMatchedPairIfValueFound()
		{
			var route = new RegexRoute(@"(?<Controller>[a-zA-Z]+)_((?<Action>[a-zA-Z]+)_)?(?<Id>\d+)?", handler);
			RouteData routeData = route.GetRouteData("Products_View_0");
			Assert.AreSame(handler, routeData.RouteHandler);
			Assert.AreEqual("Products", routeData.Values["Controller"]);
			Assert.AreEqual("View", routeData.Values["Action"]);
			Assert.AreEqual("0", routeData.Values["Id"]);
		}
Example #3
0
		public void ShouldHaveDefaultValuesIfPairFoundButDoesNotMatchAnything()
		{
			var defaults = new RouteValueDictionary(new {a = "A"});
			var route = new RegexRoute("asdf", defaults, handler);
			RouteData routeData = route.GetRouteData("asdf");
			Assert.AreSame(handler, routeData.RouteHandler);
			Assert.IsNotNull(routeData, "routeData should not be null if the path matched the regex");
			Assert.IsTrue(routeData.Values.ContainsKey("a"));
			Assert.AreEqual("A", routeData.Values["a"], "if the match failed, the value should be default");
		}
Example #4
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);
 }
Example #5
0
 public void ShouldReturnNullIfRouteIsNotMatched()
 {
     var route = new RegexRoute("asdf", handler);
     RouteData routeData = route.GetRouteData("fdsa");
     Assert.IsNull(routeData, "routedata should be null if the path didn't match");
 }
Example #6
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);
 }
Example #7
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);
 }