• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Routing.MyRoute类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中MonoTests.System.Web.Routing.MyRoute的典型用法代码示例。如果您正苦于以下问题:C# MyRoute类的具体用法?C# MyRoute怎么用?C# MyRoute使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MyRoute类属于MonoTests.System.Web.Routing命名空间,在下文中一共展示了MyRoute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: 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);
		}
开发者ID:stabbylambda,项目名称:mono,代码行数:13,代码来源:RouteTest.cs


示例2: 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");
		}
开发者ID:stabbylambda,项目名称:mono,代码行数:18,代码来源:RouteTest.cs


示例3: ProcessConstraint

		public void ProcessConstraint ()
		{
			var route = new MyRoute ("hello/{name}", new MyRouteHandler ());

			Assert.IsFalse (route.DoProcessConstraint (null, "regex", "parameter", new RouteValueDictionary (), RouteDirection.IncomingRequest), "#1");

			// constraint is null
			AssertExtensions.Throws <InvalidOperationException> (
				() => route.DoProcessConstraint (null, null, "parameter", new RouteValueDictionary (), RouteDirection.IncomingRequest),
				"#2"
			);

			// constraint is neither a string or an IRouteConstraint instance
			AssertExtensions.Throws <InvalidOperationException> (
				() => route.DoProcessConstraint (null, 1, "parameter", new RouteValueDictionary (), RouteDirection.IncomingRequest),
				"#3"
			);

			AssertExtensions.Throws <ArgumentNullException> (
				() => route.DoProcessConstraint (null, "regex", null, new RouteValueDictionary (), RouteDirection.IncomingRequest),
				"#4"
			);

			Assert.IsFalse (route.DoProcessConstraint (null, "regex", String.Empty, new RouteValueDictionary (), RouteDirection.IncomingRequest), "#5");
			
			// This is a .NET programming error, so not sure if we should test for this...
			AssertExtensions.Throws <NullReferenceException> (
				() => route.DoProcessConstraint (null, "regex", "parameter", null, RouteDirection.IncomingRequest),
				"#6"
			);
		}
开发者ID:stabbylambda,项目名称:mono,代码行数:31,代码来源:RouteTest.cs


示例4: 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");
		}
开发者ID:stabbylambda,项目名称:mono,代码行数:12,代码来源:RouteTest.cs


示例5: 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");
		}
开发者ID:stabbylambda,项目名称:mono,代码行数:18,代码来源:RouteTest.cs


示例6: 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");

		}
开发者ID:stabbylambda,项目名称:mono,代码行数:23,代码来源:RouteTest.cs


示例7: 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");
		}
开发者ID:stabbylambda,项目名称:mono,代码行数:20,代码来源:RouteTest.cs


示例8: 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");
		}
开发者ID:stabbylambda,项目名称:mono,代码行数:24,代码来源:RouteTest.cs


示例9: GetVirtualPathWithCatchall2

		public void GetVirtualPathWithCatchall2()
		{
			var r = new MyRoute("HelloWorld/{*path}", new MyRouteHandler());
			var hc = new HttpContextStub2("~/", String.Empty);
			var values = new RouteValueDictionary()
			{
				{ "path", "foo/bar/baz" },
			};
			var vp = r.GetVirtualPath(new RequestContext(hc, new RouteData()), values);

			Assert.IsNotNull(vp, "#1");
			Assert.AreEqual("HelloWorld/foo/bar/baz", vp.VirtualPath, "#2");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:13,代码来源:RouteTest.cs


示例10: 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");
		}
开发者ID:stabbylambda,项目名称:mono,代码行数:19,代码来源:RouteTest.cs


示例11: GetVirtualPath25

		public void GetVirtualPath25()
		{
			var r = new MyRoute("{year}/{month}/{slug}", new MyRouteHandler())
			{
				Defaults = new RouteValueDictionary(new { controller = "Blog", action = "View" }),
				Constraints = new RouteValueDictionary(new { year = @"\d{4}", month = @"\d{2}" }),
			};
			var hc = new HttpContextStub2("~/", String.Empty);
			var values = new RouteValueDictionary()
			{
				{ "area", string.Empty },
				{ "controller", "Blog" },
				{ "action", "View" },
				{ "year", 2013 }, // Year as an int, not a string
				{ "month", "08" },
				{ "slug", "hello-world" },
			};
			var vp = r.GetVirtualPath(new RequestContext(hc, new RouteData()), values);

			Assert.IsNotNull(vp, "#1");
			Assert.AreEqual("2013/08/hello-world", vp.VirtualPath, "#2");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:22,代码来源:RouteTest.cs


示例12: 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");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:42,代码来源:RouteTest.cs


示例13: 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");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:24,代码来源:RouteTest.cs


示例14: 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");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:34,代码来源:RouteTest.cs


示例15: 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");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:25,代码来源:RouteTest.cs



注:本文中的MonoTests.System.Web.Routing.MyRoute类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# WebControls.DataGridPoker类代码示例发布时间:2022-05-26
下一篇:
C# Routing.HttpContextStub2类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap