本文整理汇总了C#中MonoTests.System.Web.Routing.MyRoute.GetRouteData方法的典型用法代码示例。如果您正苦于以下问题:C# MyRoute.GetRouteData方法的具体用法?C# MyRoute.GetRouteData怎么用?C# MyRoute.GetRouteData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MonoTests.System.Web.Routing.MyRoute
的用法示例。
在下文中一共展示了MyRoute.GetRouteData方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetVirtualPath5
public void GetVirtualPath5 ()
{
var r = new MyRoute ("{foo}/{bar}", new MyRouteHandler ());
var hc = new HttpContextStub2 ("~/x/y", String.Empty);
var rd = r.GetRouteData (hc);
// override values completely.
var values = new RouteValueDictionary ();
values ["foo"] = "A";
values ["bar"] = "B";
var vp = r.GetVirtualPath (new RequestContext (hc, rd), values);
Assert.IsNotNull (vp, "#1");
Assert.AreEqual ("A/B", vp.VirtualPath, "#2");
Assert.AreEqual (r, vp.Route, "#3");
Assert.AreEqual (0, vp.DataTokens.Count, "#4");
}
示例2: GetVirtualPath3
public void GetVirtualPath3 ()
{
var r = new MyRoute ("{foo}/{bar}", new MyRouteHandler ());
var hc = new HttpContextStub2 ("~/x/y", String.Empty);
var rd = r.GetRouteData (hc);
var vp = r.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
Assert.IsNotNull (vp, "#1");
Assert.AreEqual ("x/y", vp.VirtualPath, "#2");
Assert.AreEqual (r, vp.Route, "#3");
Assert.AreEqual (0, vp.DataTokens.Count, "#4");
}
示例3: GetVirtualPath4
public void GetVirtualPath4 ()
{
var r = new MyRoute ("{foo}/{bar}", new MyRouteHandler ());
var hc = new HttpContextStub2 ("~/x/y", String.Empty);
var rd = r.GetRouteData (hc);
// override a value incompletely
var values = new RouteValueDictionary ();
values ["foo"] = "A";
var vp = r.GetVirtualPath (new RequestContext (hc, rd), values);
Assert.IsNull (vp);
}
示例4: GetVirtualPath12
public void GetVirtualPath12 ()
{
var r = new MyRoute ("{foo}/{bar}", new MyRouteHandler ()) {
Defaults = new RouteValueDictionary (new { bar = "baz" })
};
var hc = new HttpContextStub2 ("~/x/y", String.Empty);
var rd = r.GetRouteData (hc);
var values = new RouteValueDictionary ();
// Partial override is possible if defaults are specified
values ["foo"] = "A";
values ["baz"] = "B";
var vp = r.GetVirtualPath (new RequestContext (hc, rd), values);
Assert.IsNotNull (vp, "#1");
Assert.AreEqual ("A?baz=B", vp.VirtualPath, "#1-1");
}
示例5: GetVirtualPath14
public void GetVirtualPath14 ()
{
var r = new MyRoute ("{table}/{action}.aspx", new MyRouteHandler ());
var hc = new HttpContextStub2 ("~/x/y.aspx", String.Empty);
var rd = r.GetRouteData (hc);
// override a value incompletely
var values = new RouteValueDictionary (new {
emptyValue = String.Empty,
nullValue = (string)null,
nonEmptyValue = "SomeValue"
});
var vp = r.GetVirtualPath (new RequestContext (hc, rd), values);
Assert.IsNotNull (vp, "#A1");
Assert.AreEqual ("x/y.aspx?nonEmptyValue=SomeValue", vp.VirtualPath, "#A1-1");
values["nonEmptyValue"] = "Some Value + encoding &";
vp = r.GetVirtualPath (new RequestContext (hc, rd), values);
Assert.IsNotNull (vp, "#B1");
Assert.AreEqual ("x/y.aspx?nonEmptyValue=Some%20Value%20%2B%20encoding%20%26", vp.VirtualPath, "#B1-1");
}
示例6: GetVirtualPath10
public void GetVirtualPath10 ()
{
var r = new MyRoute ("{foo}/{bar}", new MyRouteHandler ());
var hc = new HttpContextStub ("~/foo/bar", String.Empty);
var rd = r.GetRouteData (hc);
Assert.IsNotNull (rd, "#1");
var vp = r.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { page = 3 }));
Assert.IsNotNull (vp, "#2");
Assert.AreEqual ("foo/bar?page=3", vp.VirtualPath, "#2-1");
vp = r.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { page = 3, another = "stuff" }));
Assert.IsNotNull (vp, "#3");
Assert.AreEqual ("foo/bar?page=3&another=stuff", vp.VirtualPath, "#3-1");
vp = r.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { page = 3, another = "stuff", value = "with ; spaces & other chars" }));
Assert.IsNotNull (vp, "#4");
Assert.AreEqual ("foo/bar?page=3&another=stuff&value=with%20%3B%20spaces%20%26%20other%20chars", vp.VirtualPath, "#4-1");
}
示例7: GetVirtualPath11
public void GetVirtualPath11 ()
{
var r = new MyRoute ("summary/{action}/{page}", new MyRouteHandler ()) {
Defaults = new RouteValueDictionary (new { action = "Index", page = 1 })
};
var hc = new HttpContextStub2 ("~/summary/test/1", String.Empty);
var rd = r.GetRouteData (hc);
var values = new RouteValueDictionary (new { page = 2 });
Assert.IsNotNull (rd, "#1");
var vp = r.GetVirtualPath (new RequestContext (hc, rd), values);
Assert.IsNotNull (vp, "#2");
Assert.AreEqual ("summary/test/2", vp.VirtualPath, "#2-1");
Assert.AreEqual (r, vp.Route, "#2-2");
Assert.AreEqual (0, vp.DataTokens.Count, "#2-3");
values = new RouteValueDictionary (new { page = 2, extra = "stuff" });
vp = r.GetVirtualPath (new RequestContext (hc, rd), values);
Assert.IsNotNull (vp, "#3");
Assert.AreEqual ("summary/test/2?extra=stuff", vp.VirtualPath, "#3-2");
Assert.AreEqual (0, vp.DataTokens.Count, "#3-3");
}
示例8: GetVirtualPath9
public void GetVirtualPath9 ()
{
var r = new MyRoute ("todo/{action}/{page}", new MyRouteHandler ()) {
Defaults = new RouteValueDictionary {
{"controller", "todo"},
{"action", null},
{"page", null}
}
};
var hc = new HttpContextStub2 ("~/todo/list/2", String.Empty);
var rd = r.GetRouteData (hc);
Assert.IsNotNull (rd, "#1");
var vp = r.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { page = 3 }));
Assert.IsNotNull (vp, "#2");
Assert.AreEqual ("todo/list/3", vp.VirtualPath, "#2-1");
}
示例9: GetVirtualPath24
public void GetVirtualPath24 ()
{
var r = new MyRoute ("{controller}/{country}-{locale}/{action}", new MyRouteHandler())
{
Defaults = new RouteValueDictionary (new { action = "Index", country = "us", locale = "en" })
};
var hc = new HttpContextStub2 ("~/login", String.Empty);
var rd = r.GetRouteData (hc);
Assert.IsNull (rd, "#0");
var values = new RouteValueDictionary ()
{
{ "controller", "SomeThing" },
{ "action", "Index" },
{ "country", "es" }
};
var vp = r.GetVirtualPath (new RequestContext (hc, new RouteData()), values);
Assert.IsNotNull (vp, "#1");
Assert.AreEqual ("SomeThing/es-en", vp.VirtualPath, "#1-1");
Assert.AreEqual (r, vp.Route, "#1-2");
Assert.AreEqual (0, vp.DataTokens.Count, "#1-3");
// Case #2: pass no country, but locale as user value.
values.Remove("country");
values.Add("locale", "xx");
vp = r.GetVirtualPath(new RequestContext(hc, new RouteData()), values);
Assert.IsNotNull(vp, "#2");
Assert.AreEqual("SomeThing/us-xx", vp.VirtualPath, "#2-1");
Assert.AreEqual(r, vp.Route, "#2-2");
Assert.AreEqual(0, vp.DataTokens.Count, "#2-3");
// Case #3: make contry required.
r = new MyRoute("{controller}/{country}-{locale}/{action}", new MyRouteHandler())
{
Defaults = new RouteValueDictionary(new { action = "Index", locale = "en" })
};
vp = r.GetVirtualPath(new RequestContext(hc, new RouteData()), values);
Assert.IsNull(vp, "#3");
}
示例10: GetVirtualPath23
public void GetVirtualPath23 ()
{
var r0 = new MyRoute ("summary/{id}", new MyRouteHandler());
var r1 = new MyRoute ("summary/{controller}/{id}/{action}", new MyRouteHandler())
{
Defaults = new RouteValueDictionary (new { action = "Index" })
};
var hc = new HttpContextStub2 ("~/summary/90941a4f-daf3-4c89-a6dc-83e8de4e3db5", String.Empty);
var rd = r0.GetRouteData (hc);
Assert.IsNotNull (rd, "#0");
Assert.AreEqual ("90941a4f-daf3-4c89-a6dc-83e8de4e3db5", rd.Values["id"]);
var values = new RouteValueDictionary ()
{
{ "controller", "SomeThing" },
{ "action", "Index" }
};
var vp = r1.GetVirtualPath (new RequestContext (hc, rd), values);
Assert.IsNotNull (vp, "#1");
Assert.AreEqual ("summary/SomeThing/90941a4f-daf3-4c89-a6dc-83e8de4e3db5", vp.VirtualPath, "#1-1");
Assert.AreEqual (r1, vp.Route, "#1-2");
Assert.AreEqual (0, vp.DataTokens.Count, "#1-3");
}
示例11: GetVirtualPath22
public void GetVirtualPath22 ()
{
var r = new MyRoute("summary/{controller}/{id}/{action}", new MyRouteHandler())
{
Defaults = new RouteValueDictionary(new { action = "Index" })
};
var hc = new HttpContextStub2("~/summary/kind/90941a4f-daf3-4c89-a6dc-83e8de4e3db5/test", String.Empty);
var rd = r.GetRouteData(hc);
Assert.IsNotNull(rd, "#0");
Assert.AreEqual("90941a4f-daf3-4c89-a6dc-83e8de4e3db5", rd.Values["id"]);
var values = new RouteValueDictionary(new { action = "Index" });
var vp = r.GetVirtualPath(new RequestContext(hc, rd), values);
Assert.IsNotNull(vp, "#1");
Assert.AreEqual("summary/kind/90941a4f-daf3-4c89-a6dc-83e8de4e3db5", vp.VirtualPath, "#1-1");
Assert.AreEqual(r, vp.Route, "#1-2");
Assert.AreEqual(0, vp.DataTokens.Count, "#1-3");
values = new RouteValueDictionary(new { action = "save" });
vp = r.GetVirtualPath(new RequestContext(hc, rd), values);
Assert.IsNotNull(vp, "#2");
Assert.AreEqual("summary/kind/90941a4f-daf3-4c89-a6dc-83e8de4e3db5/save", vp.VirtualPath, "#2-1");
Assert.AreEqual(r, vp.Route, "#2-2");
Assert.AreEqual(0, vp.DataTokens.Count, "#2-3");
values = new RouteValueDictionary(new { action = "save", extra = "stuff" });
vp = r.GetVirtualPath(new RequestContext(hc, rd), values);
Assert.IsNotNull(vp, "#3");
Assert.AreEqual("summary/kind/90941a4f-daf3-4c89-a6dc-83e8de4e3db5/save?extra=stuff", vp.VirtualPath, "#3-2");
Assert.AreEqual(0, vp.DataTokens.Count, "#3-3");
}
示例12: GetVirtualPath20
public void GetVirtualPath20 ()
{
var r = new MyRoute("summary/{controller}/{id}/{action}", new MyRouteHandler())
{
Defaults = new RouteValueDictionary(new { action = "Index" })
};
var hc = new HttpContextStub2("~/summary/kind/1/test", String.Empty);
var rd = r.GetRouteData(hc);
Assert.IsNotNull(rd, "#1");
var values = new RouteValueDictionary(new { id = "2", action = "save" });
var vp = r.GetVirtualPath(new RequestContext(hc, rd), values);
Assert.IsNotNull(vp, "#2");
Assert.AreEqual("summary/kind/2/save", vp.VirtualPath, "#2-1");
Assert.AreEqual(r, vp.Route, "#2-2");
Assert.AreEqual(0, vp.DataTokens.Count, "#2-3");
values = new RouteValueDictionary(new { id = "3", action = "save", extra = "stuff" });
vp = r.GetVirtualPath(new RequestContext(hc, rd), values);
Assert.IsNotNull(vp, "#3");
Assert.AreEqual("summary/kind/3/save?extra=stuff", vp.VirtualPath, "#3-2");
Assert.AreEqual(0, vp.DataTokens.Count, "#3-3");
}