public GetRouteData ( System.Web.HttpContextBase httpContext ) : System.Web.Routing.RouteData | ||
httpContext | System.Web.HttpContextBase | |
return | System.Web.Routing.RouteData |
static Mock<RequestContext> GetRequestContext(string requestUrl, string routeUrl, IRouteHandler handler) { var route = new Route(routeUrl, handler); var sv = new Mock<NameValueCollection>(MockBehavior.Strict); sv.Setup(m => m.Get("IIS_UrlRewriteModule")).Returns((string)null); var req = new Mock<HttpRequestBase>(MockBehavior.Strict); req.Setup(m => m.AppRelativeCurrentExecutionFilePath).Returns("~/"); req.Setup(m => m.PathInfo).Returns(requestUrl); req.Setup(m => m.ApplicationPath).Returns("/"); req.Setup(m => m.ServerVariables).Returns(sv.Object); var resp = new Mock<HttpResponseBase>(MockBehavior.Strict); resp.Setup(m => m.ApplyAppPathModifier(It.IsAny<string>())).Returns<string>(url => url); var ctx = new Mock<HttpContextBase>(MockBehavior.Strict); ctx.Setup(m => m.Request).Returns(req.Object); ctx.Setup(m => m.Response).Returns(resp.Object); var reqCtx = new Mock<RequestContext>(MockBehavior.Strict); reqCtx.Setup(m => m.HttpContext).Returns(ctx.Object); reqCtx.Setup(m => m.RouteData).Returns(route.GetRouteData(ctx.Object)); return reqCtx; }
/// <summary> /// Create inbound route values from a string url. /// </summary> /// <param name="url">The url from which to generate the route</param> /// <param name="route">The route from which to generate the route</param> /// <returns>The route values</returns> public static RouteValueDictionary GenerateInboundRoute(string url, Route route) { HttpContextBase mockHttp = MockHelpers.HttpContext(url).Object; RouteData data = route.GetRouteData(mockHttp); if (null != data) { return data.Values; } return null; }
private static RequestContext GetRequestContext(StubContainerProvider containerProvider) { var handler = new MvcRouteHandler(); var route = new Route("yadda", handler) { DataTokens = new RouteValueDictionary {{"IContainerProvider", containerProvider}} }; var httpContext = new StubHttpContext(); var routeData = route.GetRouteData(httpContext); return new RequestContext(httpContext, routeData); }
public void RouteGetRequiredStringWithDefaults () { var routes = new RouteValueDictionary (); var route = new Route ("Hello/{name}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new {controller = "Home", action = "Hello"}) }; routes.Add ("Name", route); var hc = new HttpContextStub2 ("~/Hello/World", String.Empty); var rd = route.GetRouteData (hc); Assert.IsNotNull (rd, "#A1"); Assert.AreEqual ("Home", rd.GetRequiredString ("controller"), "#A2"); Assert.AreEqual ("Hello", rd.GetRequiredString ("action"), "#A3"); Assert.AreEqual ("World", rd.Values ["name"], "#A4"); }
public void GetRouteData22 () { var r = new Route ("foo/{ \t\n}", null); var hc = new HttpContextStub ("~/FOO/stuff", String.Empty); var rd = r.GetRouteData (hc); Assert.IsNotNull (rd, "#1"); Assert.AreEqual (r, rd.Route, "#2"); Assert.AreEqual (0, rd.DataTokens.Count, "#3"); Assert.AreEqual (1, rd.Values.Count, "#4"); Assert.AreEqual ("stuff", rd.Values[" \t\n"], "#4-1"); }
public void GetRouteData39 () { // {} matches and substitutes even at partial state ... var r = new Route ("{foo}/bar{baz}", null); var hc = new HttpContextStub ("~/x/barte", String.Empty); var rd = r.GetRouteData (hc); Assert.IsNotNull (rd, "#1"); Assert.AreEqual (r, rd.Route, "#2"); Assert.AreEqual (0, rd.DataTokens.Count, "#3"); Assert.AreEqual (2, rd.Values.Count, "#4"); Assert.AreEqual ("x", rd.Values ["foo"], "#4-1"); Assert.AreEqual ("te", rd.Values ["baz"], "#4-2"); }
public void GetVirtualPath2 () { var r = new Route ("{foo}/{bar}", null); var hc = new HttpContextStub ("~/x/y", String.Empty); var rd = r.GetRouteData (hc); var vp = r.GetVirtualPath (new RequestContext (hc, rd), null); Assert.IsNotNull (vp, "#1"); Assert.AreEqual ("x/y", vp.VirtualPath, "#2"); Assert.AreEqual (r, vp.Route, "#3"); Assert.AreEqual (0, vp.DataTokens.Count, "#4"); }
public void GetRouteData31() { var r = new Route("{controller}/{action}", null) { Defaults = new RouteValueDictionary(new { controller = "Home", action = "Index" }), DataTokens = new RouteValueDictionary(new { foobar = "bar" }) }; var hc = new HttpContextStub("~/", String.Empty); var rd = r.GetRouteData(hc); Assert.IsNotNull(rd, "#1"); Assert.AreEqual(r, rd.Route, "#2"); Assert.AreEqual(1, rd.DataTokens.Count, "#3"); Assert.AreEqual(2, rd.Values.Count, "#4"); Assert.AreEqual("Home", rd.Values["controller"], "#4-1"); Assert.AreEqual("Index", rd.Values["action"], "#4-2"); Assert.IsNull(rd.Values["foobar"], "#4-3"); Assert.IsNotNull(rd.DataTokens, "#5"); Assert.AreEqual(1, rd.DataTokens.Count, "#6"); Assert.AreEqual("bar", rd.DataTokens["foobar"], "#6-1"); }
public void GetRouteData35 () { var r = new Route ("{foo}xyz{bar}xyz{baz}", null); var hc = new HttpContextStub ("~/xyzxyzxyzdabxyzblah", String.Empty); var rd = r.GetRouteData (hc); Assert.IsNotNull (rd, "#1"); Assert.AreEqual (r, rd.Route, "#2"); Assert.AreEqual (0, rd.DataTokens.Count, "#3"); Assert.AreEqual (3, rd.Values.Count, "#4"); Assert.AreEqual ("xyzxyz", rd.Values ["foo"], "#4-1"); Assert.AreEqual ("dab", rd.Values ["bar"], "#4-2"); Assert.AreEqual ("blah", rd.Values ["baz"], "#4-3"); }
public void GetRouteData7 () { var r = new Route ("{table}/{action}.aspx", null); var rd = r.GetRouteData (new HttpContextStub ("~/FooTable/", String.Empty)); Assert.IsNull (rd, "#1"); }
public void GetRouteData27 () { var r = new Route ("foo/{bar}/{baz}/{dancefloor}", null) { Defaults = new RouteValueDictionary (new { bar = "BlueOyster", dancefloor = 1 }) }; var hc = new HttpContextStub ("~/foo/nyc", String.Empty); var rd = r.GetRouteData (hc); Assert.IsNull (rd, "#1"); }
public void GetRouteData5 () { var r = new Route ("{foo}/{bar}", new StopRoutingHandler ()); var rd = r.GetRouteData (new HttpContextStub ("x/y", String.Empty)); Assert.IsNull (rd, "#1"); rd = r.GetRouteData (new HttpContextStub ("~/x/y", String.Empty)); Assert.IsNotNull (rd, "#2"); rd = r.GetRouteData (new HttpContextStub ("~/x/y/z", String.Empty)); Assert.IsNull (rd, "#3"); rd = r.GetRouteData (new HttpContextStub ("~x/y", String.Empty)); Assert.IsNull (rd, "#4"); rd = r.GetRouteData (new HttpContextStub ("/x/y", String.Empty)); Assert.IsNull (rd, "#5"); rd = r.GetRouteData (new HttpContextStub ("{foo}/{bar}/baz", String.Empty)); Assert.IsNull (rd, "#6"); rd = r.GetRouteData (new HttpContextStub ("{foo}/{bar}", String.Empty)); Assert.IsNotNull (rd, "#7"); Assert.AreEqual (0, rd.DataTokens.Count, "#7-2"); Assert.AreEqual (2, rd.Values.Count, "#7-3"); }
public void GetRouteData6 () { var r = new Route ("{table}/{action}.aspx", null); var rd = r.GetRouteData (new HttpContextStub ("~/FooTable/List.aspx", String.Empty)); Assert.IsNotNull (rd, "#1"); Assert.AreEqual ("FooTable", rd.Values ["table"], "#2"); Assert.AreEqual ("List", rd.Values ["action"], "#3"); }
public void GetRouteData4 () { var r = new Route ("{foo}/{bar}", null); var hc = new HttpContextStub ("~/x", String.Empty); var rd = r.GetRouteData (hc); Assert.IsNull (rd); // mismatch }
public void GetRouteData () { var r = new Route ("{foo}/{bar}", null); var hc = new HttpContextStub ("~/x/y", String.Empty); var rd = r.GetRouteData (hc); Assert.IsNotNull (rd, "#1"); Assert.AreEqual (r, rd.Route, "#2"); Assert.AreEqual (0, rd.DataTokens.Count, "#3"); Assert.AreEqual (2, rd.Values.Count, "#4"); Assert.AreEqual ("x", rd.Values ["foo"], "#4-1"); Assert.AreEqual ("y", rd.Values ["bar"], "#4-2"); }
public void InvalidConstraint () { var r = new Route ("{foo}/{bar}", new StopRoutingHandler ()); var c = new RouteValueDictionary (); c ["foo"] = Guid.NewGuid (); r.Constraints = c; var hc = new HttpContextStub ("~/x/y", String.Empty); var rd = r.GetRouteData (hc); }
public void GetRouteData23 () { var r = new Route ("foo/{bar}-{baz}/{dancefloor}", null) { Defaults = new RouteValueDictionary (new { bar = "BlueOyster", dancefloor = 1 }) }; var hc = new HttpContextStub ("~/foo/-nyc/1", String.Empty); var rd = r.GetRouteData (hc); Assert.IsNull (rd, "#1"); hc = new HttpContextStub ("~/foo/blueoyster-nyc", String.Empty); rd = r.GetRouteData (hc); Assert.IsNotNull (rd, "#2"); Assert.AreEqual (r, rd.Route, "#2-1"); Assert.AreEqual (0, rd.DataTokens.Count, "#2-2"); Assert.AreEqual (3, rd.Values.Count, "#2-3"); Assert.AreEqual ("blueoyster", rd.Values["bar"], "#2-4"); Assert.AreEqual ("nyc", rd.Values["baz"], "#2-5"); Assert.AreEqual (1, rd.Values["dancefloor"], "#2-6"); Assert.IsTrue (typeof (int) == rd.Values["dancefloor"].GetType (), "#2-7"); }
public void GetRouteData8 () { var r = new Route ("{first}/{*rest}", null); var hc = new HttpContextStub ("~/a/b/c/d", String.Empty); var rd = r.GetRouteData (hc); Assert.IsNotNull (rd, "#1"); Assert.AreEqual (r, rd.Route, "#2"); Assert.AreEqual (0, rd.DataTokens.Count, "#3"); Assert.AreEqual (2, rd.Values.Count, "#4"); Assert.AreEqual ("a", rd.Values ["first"], "#4-1"); Assert.AreEqual ("b/c/d", rd.Values ["rest"], "#4-2"); }
public void GetRouteData26 () { var r = new Route ("foo/{bar}/{baz}-{dancefloor}", null) { Defaults = new RouteValueDictionary (new { baz = "nyc", dancefloor = 1 }) }; var hc = new HttpContextStub ("~/foo/BlueOyster", String.Empty); var rd = r.GetRouteData (hc); Assert.IsNull (rd, "#1"); hc = new HttpContextStub ("~/foo/blueoyster/bigapple", String.Empty); rd = r.GetRouteData (hc); Assert.IsNull (rd, "#2"); hc = new HttpContextStub ("~/foo/blueoyster/bigapple-3", String.Empty); rd = r.GetRouteData (hc); Assert.IsNotNull (rd, "#3"); Assert.AreEqual (r, rd.Route, "#3-1"); Assert.AreEqual (0, rd.DataTokens.Count, "#3-2"); Assert.AreEqual (3, rd.Values.Count, "#3-3"); Assert.AreEqual ("blueoyster", rd.Values["bar"], "#3-4"); Assert.AreEqual ("bigapple", rd.Values["baz"], "#3-5"); Assert.AreEqual ("3", rd.Values["dancefloor"], "#3-6"); Assert.IsTrue (typeof (string) == rd.Values["dancefloor"].GetType (), "#3-7"); hc = new HttpContextStub ("~/foo/blueoyster/-", String.Empty); rd = r.GetRouteData (hc); Assert.IsNull (rd, "#4"); }
public void GetRouteData12 () { var r = new Route ("summary/{action}-{type}/{page}", null); var hc = new HttpContextStub ("~/summary/test-xml", String.Empty); var rd = r.GetRouteData (hc); Assert.IsNull (rd, "#1"); // mismatch, missing page }
public void GetRouteData30 () { var r = new Route ("{foo}/bar/{baz}/boo/{blah}", null) { Defaults = new RouteValueDictionary (new { baz = "meep", blah = "blurb" }) }; var hc = new HttpContextStub ("~/foo/bar", String.Empty); var rd = r.GetRouteData (hc); Assert.IsNull (rd, "#1"); hc = new HttpContextStub ("~/foo/bar/baz/boo", String.Empty); rd = r.GetRouteData (hc); Assert.IsNotNull (rd, "#2"); Assert.AreEqual (r, rd.Route, "#3"); Assert.AreEqual (0, rd.DataTokens.Count, "#4"); Assert.AreEqual (3, rd.Values.Count, "#4"); Assert.AreEqual ("foo", rd.Values["foo"], "#4-1"); Assert.AreEqual ("baz", rd.Values["baz"], "#4-2"); Assert.AreEqual ("blurb", rd.Values["blah"], "#4-3"); }
public void GetRouteData13 () { var r = new Route ("summary/{action}-{type}/{page}", null) { Defaults = new RouteValueDictionary (new { action = "Index", page = 1 } ) }; var hc = new HttpContextStub ("~/summary/test-xml/1", String.Empty); var rd = r.GetRouteData (hc); Assert.IsNotNull (rd, "#1"); Assert.AreEqual (r, rd.Route, "#2"); Assert.AreEqual (0, rd.DataTokens.Count, "#3"); Assert.AreEqual (3, rd.Values.Count, "#4"); Assert.AreEqual ("test", rd.Values["action"], "#4-1"); Assert.AreEqual ("xml", rd.Values["type"], "#4-2"); Assert.AreEqual ("1", rd.Values["page"], "#4-3"); }
public void GetRouteData33 () { var r = new Route (null, null); var hc = new HttpContextStub ("~/", String.Empty); var rd = r.GetRouteData (hc); Assert.IsNotNull (rd, "#1"); Assert.AreEqual (r, rd.Route, "#2"); Assert.AreEqual (0, rd.DataTokens.Count, "#3"); Assert.AreEqual (0, rd.Values.Count, "#4"); }
public void GetRouteData14 () { var r = new Route ("{filename}.{ext}", null); var hc = new HttpContextStub ("~/Foo.xml.aspx", String.Empty); var rd = r.GetRouteData (hc); Assert.IsNotNull (rd, "#1"); Assert.AreEqual (r, rd.Route, "#2"); Assert.AreEqual (0, rd.DataTokens.Count, "#3"); Assert.AreEqual (2, rd.Values.Count, "#4"); Assert.AreEqual ("Foo.xml", rd.Values["filename"], "#4-1"); Assert.AreEqual ("aspx", rd.Values["ext"], "#4-2"); }
public void GetRouteData37 () { var r = new Route ("{foo}xyz{bar}xyz{baz}", null); var hc = new HttpContextStub ("~/xyzxyzxyzxyzxyz", String.Empty); var rd = r.GetRouteData (hc); #if NET_4_0 || !DOTNET // When running on Mono this test succeeds - it was a bug in .NET routing for 3.5 which // we don't reproduce anymore. Assert.IsNotNull (rd, "#1"); Assert.AreEqual (r, rd.Route, "#2"); Assert.AreEqual (0, rd.DataTokens.Count, "#3"); Assert.AreEqual (3, rd.Values.Count, "#4"); Assert.AreEqual ("xyz", rd.Values ["foo"], "#4-1"); Assert.AreEqual ("xyz", rd.Values ["bar"], "#4-2"); Assert.AreEqual ("xyz", rd.Values ["baz"], "#4-3"); #else Assert.IsNull (rd, "#1"); #endif }
public void GetRouteData47 () { var r = new Route ("Foo/{id}", new StopRoutingHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Foo", action = "Retrieve" }), Constraints = new RouteValueDictionary (new { id = @"\d{1,10}" }) }; var hc = new HttpContextStub ("~/Foo/x123", String.Empty); var rd = r.GetRouteData (hc); Assert.IsNull (rd, "#1"); }
public void GetRouteData43 () { // {} matches and substitutes even at partial state ... var r = new Route ("{foo}-{bar}-{baz}", null); var hc = new HttpContextStub ("~/--", String.Empty); var rd = r.GetRouteData (hc); Assert.IsNull (rd, "#1"); hc = new HttpContextStub ("~/1-2-3", String.Empty); rd = r.GetRouteData (hc); Assert.IsNotNull (rd, "#2"); Assert.AreEqual (r, rd.Route, "#2"); Assert.AreEqual (0, rd.DataTokens.Count, "#3"); Assert.AreEqual (3, rd.Values.Count, "#4"); Assert.AreEqual ("1", rd.Values ["foo"], "#4-1"); Assert.AreEqual ("2", rd.Values ["bar"], "#4-2"); Assert.AreEqual ("3", rd.Values ["baz"], "#4-2"); }
public void GetRouteData16 () { var r = new Route ("My{location}---{sublocation}", null); var hc = new HttpContextStub ("~/MyHouse-LivingRoom", String.Empty); var rd = r.GetRouteData (hc); Assert.IsNull (rd, "#1"); }
public void GetRouteData15 () { var r = new Route ("My{location}-{sublocation}", null); var hc = new HttpContextStub ("~/MyHouse-LivingRoom", String.Empty); var rd = r.GetRouteData (hc); Assert.IsNotNull (rd, "#1"); Assert.AreEqual (r, rd.Route, "#2"); Assert.AreEqual (0, rd.DataTokens.Count, "#3"); Assert.AreEqual (2, rd.Values.Count, "#4"); Assert.AreEqual ("House", rd.Values["location"], "#4-1"); Assert.AreEqual ("LivingRoom", rd.Values["sublocation"], "#4-2"); }
public void GetRouteDataWithCatchAll () { var r = new Route ("{*path}", new StopRoutingHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Error", action = "NotFound" }) }; var hc = new HttpContextStub ("~/", String.Empty); var rd = r.GetRouteData (hc); Assert.IsNotNull (rd, "#1"); hc = new HttpContextStub ("~/Foo/x123", String.Empty); rd = r.GetRouteData (hc); Assert.IsNotNull (rd, "#2"); }