当前位置: 首页>>代码示例>>C#>>正文


C# Routing.HttpContextStub2类代码示例

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


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

示例1: 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

示例2: Ignore_String

		public void Ignore_String ()
		{
			var c = new RouteCollection ();

			AssertExtensions.Throws<ArgumentNullException> (() => {
				c.Ignore (null);
			}, "#A1");

			c.Ignore ("{resource}.axd/{*pathInfo}");
			var hc = new HttpContextStub2 ("~/something.axd/pathinfo", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (3));
			var rd = c.GetRouteData (hc);

			Assert.IsNotNull (rd, "#A1-1");
			Assert.IsNotNull (rd.RouteHandler, "#A1-2");
			Assert.AreEqual (typeof (StopRoutingHandler), rd.RouteHandler.GetType (), "#A1-3");
			Assert.IsTrue (rd.Route is Route, "#A1-4");
			Assert.IsNotNull (((Route) rd.Route).Constraints, "#A1-5");
			Assert.AreEqual (0, ((Route) rd.Route).Constraints.Count, "#A1-6");
		}
开发者ID:carrie901,项目名称:mono,代码行数:20,代码来源:RouteCollectionTest.cs

示例3: MapPageRoute_String_String_String

		public void MapPageRoute_String_String_String ()
		{
			var c = new RouteCollection ();

			c.MapPageRoute (null, "{foo}-{bar}", "~/some-url");
			var hc = new HttpContextStub2 ("~/some-url", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (3));
			var rd = c.GetRouteData (hc);

			Assert.IsNotNull (rd, "#A1-1");
			Assert.IsNotNull (rd.RouteHandler, "#A1-2");
			Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A1-3");

			c = new RouteCollection ();
			AssertExtensions.Throws<ArgumentNullException> (() => {
				c.MapPageRoute ("RouteName", null, "~/some-url");
			}, "#A2");

			c = new RouteCollection ();
			c.MapPageRoute ("RouteName", String.Empty, "~/some-url");
			rd = c.GetRouteData (hc);

			Assert.IsNull (rd, "#A2");

			c = new RouteCollection ();
			// thrown by PageRouteHandler's constructor
			AssertExtensions.Throws<ArgumentException> (() => {
				c.MapPageRoute ("RouteName", "~/some-url", null);
			}, "#A3");
		}
开发者ID:carrie901,项目名称:mono,代码行数:30,代码来源:RouteCollectionTest.cs

示例4: GetVirtualPath4

		public void GetVirtualPath4 ()
		{
			var c = new RouteCollection ();

			c.Add (new MyRoute ("blog/{user}/{action}", new MyRouteHandler ()) {
					Defaults = new RouteValueDictionary {
							{ "controller", "blog" },
							{ "user", "admin" }
						}
				}
			);

			c.Add (new MyRoute ("forum/{user}/{action}", new MyRouteHandler ()) {
					Defaults = new RouteValueDictionary {
							{ "controller", "forum" },
							{ "user", "admin" }
						}
				}
			);

			var hc = new HttpContextStub2 ("~/forum/admin/Index", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (3));
			var rd = c.GetRouteData (hc);
			Assert.IsNotNull (rd, "#1");

			var vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { action="Index", controller="forum"}));
			Assert.IsNotNull (vp, "#2");
			Assert.AreEqual ("/forum/admin/Index", vp.VirtualPath, "#2-1");
			
			vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { action="Index", controller="blah"}));
			Assert.IsNull (vp, "#3");
		}
开发者ID:carrie901,项目名称:mono,代码行数:32,代码来源:RouteCollectionTest.cs

示例5: GetVirtualPathToExistingFile

		public void GetVirtualPathToExistingFile ()
		{
			var c = new RouteCollection ();
			c.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
			var hc = new HttpContextStub2 ("~/Test/test.html", String.Empty, ".");
			// it tries to get HttpContextBase.Response, so set it.
			hc.SetResponse (new HttpResponseStub (3));
			var rd = c.GetRouteData (hc);
			var vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
			Assert.AreEqual ("./Test/test.html", vpd.VirtualPath, "#1");
			Assert.AreEqual (0, vpd.DataTokens.Count, "#2");
		}
开发者ID:carrie901,项目名称:mono,代码行数:12,代码来源:RouteCollectionTest.cs

示例6: GetVirtualPathCheckVirtualPathToModify

		public void GetVirtualPathCheckVirtualPathToModify ()
		{
			var c = new RouteCollection ();
			c.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
			var hc = new HttpContextStub2 ("~/x/y", String.Empty, "apppath");
			// it tries to get HttpContextBase.Response, so set it.
			hc.SetResponse (new HttpResponseStub (1));
			var rd = c.GetRouteData (hc);
			try {
				var vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
				Assert.Fail ("#1");
			} catch (ApplicationException ex) {
				Assert.AreEqual ("apppath/x/y", ex.Message, "#2");
			}
		}
开发者ID:carrie901,项目名称:mono,代码行数:15,代码来源:RouteCollectionTest.cs

示例7: GetVirtualPath2

		public void GetVirtualPath2 ()
		{
			var c = new RouteCollection ();
			
			c.Add ("Summary",
			       new MyRoute ("summary/{action}-{type}/{page}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Summary", action = "Index", page = 1}) }
			);
			       
			c.Add ("Apis",
			       new MyRoute ("apis/{apiname}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Apis", action = "Index" }) }
			);
							    
			c.Add ("Single Report",
			       new MyRoute ("report/{guid}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Reports", action = "SingleReport" }) }
			);
			
			c.Add ("Reports",
			       new MyRoute ("reports/{page}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Reports", action = "Index", page = 1 }) }
			);

			c.Add ("Default",
			       new MyRoute ("{controller}/{action}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Home", action = "Index"}) }
			);

			var hc = new HttpContextStub2 ("~/Home/About", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (2));
			var rd = c.GetRouteData (hc);
			var vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
			Assert.IsNotNull (vpd, "#A1");
			Assert.AreEqual ("/Home/About_modified", vpd.VirtualPath, "#A2");
			Assert.AreEqual (0, vpd.DataTokens.Count, "#A3");

			hc = new HttpContextStub2 ("~/Home/Index", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (2));
			rd = c.GetRouteData (hc);
			vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
			Assert.IsNotNull (vpd, "#B1");
			Assert.AreEqual ("/_modified", vpd.VirtualPath, "#B2");
			Assert.AreEqual (0, vpd.DataTokens.Count, "#B3");

			hc = new HttpContextStub2 ("~/Account/LogOn", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (2));
			rd = c.GetRouteData (hc);
			vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
			Assert.IsNotNull (vpd, "#C1");
			Assert.AreEqual ("/Account/LogOn_modified", vpd.VirtualPath, "#C2");
			Assert.AreEqual (0, vpd.DataTokens.Count, "#C3");

			hc = new HttpContextStub2 ("~/", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (3));
			rd = c.GetRouteData (hc);
			vpd = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { controller = "home" }) );
			Assert.IsNotNull (vpd, "#D1");
			Assert.AreEqual ("/", vpd.VirtualPath, "#D2");
			Assert.AreEqual (0, vpd.DataTokens.Count, "#D3");

			hc = new HttpContextStub2 ("~/", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (3));
			rd = c.GetRouteData (hc);
			vpd = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { controller = "Home" }) );
			Assert.IsNotNull (vpd, "#E1");
			Assert.AreEqual ("/", vpd.VirtualPath, "#E2");
			Assert.AreEqual (0, vpd.DataTokens.Count, "#E3");
		}
开发者ID:carrie901,项目名称:mono,代码行数:64,代码来源:RouteCollectionTest.cs

示例8: GetVirtualPath8

		public void GetVirtualPath8 ()
		{
			var routes = new RouteCollection();

			routes.Add (new MyRoute ("login", new MyRouteHandler ()) {
				Defaults = new RouteValueDictionary (new { controller = "Home", action = "LogOn" })
			});

			routes.Add (new MyRoute ("{site}/{controller}/{action}", new MyRouteHandler ())	{
				Defaults = new RouteValueDictionary (new { site = "_", controller = "Home", action = "Index" }),
				Constraints = new RouteValueDictionary ( new { site = "_?[0-9A-Za-z-]*" })
			});

			routes.Add (new MyRoute ("{*path}", new MyRouteHandler ()) {
				Defaults = new RouteValueDictionary (new { controller = "Error", action = "NotFound" }),
			});

			var hc = new HttpContextStub2 ("~/login", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (3));
			var rd = routes.GetRouteData (hc);
			var rvs = new RouteValueDictionary () {
				{ "controller", "Home" },
				{ "action" , "Index" }
			};
			var vpd = routes.GetVirtualPath (new RequestContext (hc, rd), rvs);
			Assert.IsNotNull (vpd, "#A1");
			Assert.AreEqual ("/", vpd.VirtualPath, "#A2");
			Assert.AreEqual (0, vpd.DataTokens.Count, "#A3");

			hc = new HttpContextStub2 ("~/login", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (3));
			rd = routes.GetRouteData (hc);
			rvs = new RouteValueDictionary () {
				{ "controller", "Home" }
			};
			vpd = routes.GetVirtualPath (new RequestContext (hc, rd), rvs);
			Assert.IsNotNull (vpd, "#B1");
			Assert.AreEqual ("/login", vpd.VirtualPath, "#B2");
			Assert.AreEqual (0, vpd.DataTokens.Count, "#B3");

			hc = new HttpContextStub2 ("~/login", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (3));
			rd = routes.GetRouteData (hc);
			rvs = new RouteValueDictionary () {
				{ "action" , "Index" }
			};
			vpd = routes.GetVirtualPath (new RequestContext (hc, rd), rvs);
			Assert.IsNotNull (vpd, "#C1");
			Assert.AreEqual ("/", vpd.VirtualPath, "#C2");
			Assert.AreEqual (0, vpd.DataTokens.Count, "#C3");

			hc = new HttpContextStub2 ("~/", String.Empty, String.Empty);
			rd = routes.GetRouteData (hc);
			Assert.IsNotNull (rd, "#D1");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:55,代码来源:RouteCollectionTest.cs

示例9: 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

示例10: 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

示例11: 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

示例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: GetVirtualPathNoApplicationPath

		public void GetVirtualPathNoApplicationPath ()
		{
			var c = new RouteCollection ();
			c.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
			var hc = new HttpContextStub2 ("~/x/y", String.Empty);
			var rd = c.GetRouteData (hc);
			// it tries to get HttpContextBase.Request.ApplicationPath and then throws NIE.
			var vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
		}
开发者ID:carrie901,项目名称:mono,代码行数:9,代码来源:RouteCollectionTest.cs


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