本文整理匯總了C#中System.Web.Routing.Route.GetRouteData方法的典型用法代碼示例。如果您正苦於以下問題:C# Route.GetRouteData方法的具體用法?C# Route.GetRouteData怎麽用?C# Route.GetRouteData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Web.Routing.Route
的用法示例。
在下文中一共展示了Route.GetRouteData方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetRequestContext
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;
}
示例2: GenerateInboundRoute
/// <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;
}
示例3: GetRequestContext
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);
}
示例4: RouteGetRequiredStringWithDefaults
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");
}
示例5: GetRouteData22
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");
}
示例6: GetRouteData39
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");
}
示例7: GetVirtualPath2
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");
}
示例8: GetRouteData31
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");
}
示例9: GetRouteData35
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");
}
示例10: GetRouteData7
public void GetRouteData7 ()
{
var r = new Route ("{table}/{action}.aspx", null);
var rd = r.GetRouteData (new HttpContextStub ("~/FooTable/", String.Empty));
Assert.IsNull (rd, "#1");
}
示例11: GetRouteData27
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");
}
示例12: GetRouteData5
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");
}
示例13: GetRouteData6
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");
}
示例14: GetRouteData4
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
}
示例15: GetRouteData
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");
}