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


C# RouteCollection.GetVirtualPath方法代码示例

本文整理汇总了C#中RouteCollection.GetVirtualPath方法的典型用法代码示例。如果您正苦于以下问题:C# RouteCollection.GetVirtualPath方法的具体用法?C# RouteCollection.GetVirtualPath怎么用?C# RouteCollection.GetVirtualPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RouteCollection的用法示例。


在下文中一共展示了RouteCollection.GetVirtualPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateUrlViaMock

        private VirtualPathData GenerateUrlViaMock( object values )
        {
            //Arrange
            RouteCollection routeCollection = new RouteCollection();
            MvcApplication.RegisterRoutes( routeCollection );
            var mockHttpContext = new MockHttpContext().MakeMockHttpContext( null );
            RequestContext context = new RequestContext( mockHttpContext.Object, new RouteData() );

            //Act
            return routeCollection.GetVirtualPath( context, new RouteValueDictionary( values ) );
        }
开发者ID:j3itchtits,项目名称:jumblist,代码行数:11,代码来源:OutboundRouteTest.cs

示例2: GenerateUrlViaMocks

        public static VirtualPathData GenerateUrlViaMocks(RouteValueDictionary route)
        {
            // Arrange (get the routing config and test context)
            RouteCollection routeConfig = new RouteCollection();
            MvcApplication.RegisterRoutes(routeConfig);

            var mockContext = MakeMockHttpContext(null);
            RequestContext context = new RequestContext(mockContext.Object, new RouteData());

            // Act (generate a URL)
            return routeConfig.GetVirtualPath(context, route);
        }
开发者ID:triggerfish,项目名称:MvcTemplate,代码行数:12,代码来源:MockHttp.cs

示例3: GetOutboundUrl

        private string GetOutboundUrl(object routeValues)
        {
            RouteCollection routes = new RouteCollection();
            RouteConfig.RegisterRoutes(routes);
            var mockHttpContext = new Moq.Mock<HttpContextBase>();
            var mockRequest = new Moq.Mock<HttpRequestBase>();
            var fakeResponse = new FakeResponse();
            mockHttpContext.Setup(x => x.Request).Returns(mockRequest.Object);
            mockHttpContext.Setup(x => x.Response).Returns(fakeResponse);
            mockRequest.Setup(x => x.ApplicationPath).Returns("/");

            var ctx = new RequestContext(mockHttpContext.Object, new RouteData());
            return routes.GetVirtualPath(ctx, new RouteValueDictionary(routeValues)).VirtualPath;
        }
开发者ID:AbstractStudent,项目名称:SportStore,代码行数:14,代码来源:OutboundRoutingTests.cs

示例4: GetVirtualPathCanFillInSeparatedParametersWithDefaultValues

        public void GetVirtualPathCanFillInSeparatedParametersWithDefaultValues()
        {
            var routes = new RouteCollection();
            routes.MapRoute("some-route", "{controller}/{language}-{locale}", new {language="en", locale="US"});

            var request = new Mock<HttpRequestBase>();
            request.Expect(req => req.AppRelativeCurrentExecutionFilePath).Returns("~/");
            request.Expect(req => req.ApplicationPath).Returns("");

            var httpContext = new Mock<HttpContextBase>();
            httpContext.Expect(http => http.Request).Returns(request.Object);

            var context = new RequestContext(httpContext.Object, new RouteData());

            VirtualPathData vpd = routes.GetVirtualPath(context, new RouteValueDictionary(new { controller = "Orders" }));
            Assert.IsNotNull(vpd, "Expected this to match our one route");
            Assert.AreEqual("/Orders/en-US", vpd.VirtualPath, "Expected the route to fill in the parameters using the defaults");
        }
开发者ID:Eilon,项目名称:spark,代码行数:18,代码来源:RoutingTest.cs

示例5: GetVirtualPath6

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

			c.Add (new MyRoute ("reports/{year}/{month}/{day}", new MyRouteHandler ()) {
					Defaults = new RouteValueDictionary {
							{ "day", 1 }
						}
				}
			);

			var hc = new HttpContextStub2 ("~/reports/2009/05", String.Empty, "/myapp");
			hc.SetResponse (new HttpResponseStub (3));
			var rd = c.GetRouteData (hc);
			Assert.IsNotNull (rd, "#1");

			var vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
					{ "year", 2007 },
					{ "month", 1 },
					{ "day", 12 },
				}
			);
			Assert.IsNotNull (vp, "#2");
			Assert.AreEqual ("/myapp/reports/2007/1/12", vp.VirtualPath, "#2-1");
			
			vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
					{ "year", 2007 },
					{ "month", 1 }
				}
			);
			Assert.IsNotNull (vp, "#3");
			Assert.AreEqual ("/myapp/reports/2007/1", vp.VirtualPath, "#3-1");

			vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
					{ "year", 2007 },
					{ "month", 1 },
					{ "day", 12 },
					{ "category", 123 }
				}
			);
			Assert.IsNotNull (vp, "#4");
			Assert.AreEqual ("/myapp/reports/2007/1/12?category=123", vp.VirtualPath, "#4-1");
			
			vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
					{ "year", 2007 },
				}
			);
			Assert.IsNull (vp, "#5");
		}
开发者ID:carrie901,项目名称:mono,代码行数:49,代码来源:RouteCollectionTest.cs

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

示例7: GetVirtualPath3

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

			c.Add ("todo-route",
			       new MyRoute ("todo/{action}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new {controller = "todo", action="list", page=0}) }
			);

			c.Add ("another-route",
			       new MyRoute ("{controller}/{action}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new {controller = "home", action="list", page=0}) }
			);

			var hc = new HttpContextStub2 ("~/home/list", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (3));
			var rd = c.GetRouteData (hc);
			Assert.IsNotNull (rd, "#1");
			Assert.AreEqual (3, rd.Values.Count, "#1-1");
			Assert.AreEqual ("home", rd.Values["controller"], "#1-2");
			Assert.AreEqual ("list", rd.Values["action"], "#1-3");
			Assert.AreEqual (0, rd.Values["page"], "#1-4");
			
			var vp = c.GetVirtualPath (new RequestContext (hc, rd), "todo-route", new RouteValueDictionary ());
			Assert.IsNotNull (vp, "#2");
			Assert.AreEqual ("/todo", vp.VirtualPath, "#2-1");

			vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary ());
			Assert.IsNotNull (vp, "#3");
			Assert.AreEqual ("/todo", vp.VirtualPath, "#3-1");

			vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { controller = "home" }));
			Assert.IsNotNull (vp, "#4");
			Assert.AreEqual ("/", vp.VirtualPath, "#4-1");

			vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { controller = "home", extra="stuff" }));
			Assert.IsNotNull (vp, "#5");
			Assert.AreEqual ("/?extra=stuff", vp.VirtualPath, "#5-1");
		}
开发者ID:carrie901,项目名称:mono,代码行数:37,代码来源:RouteCollectionTest.cs

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

示例9: GetVirtualPath

		public void GetVirtualPath ()
		{
			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 (2));
			var rd = c.GetRouteData (hc);
			Assert.IsNotNull (rd, "#1");
			
			var vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
			Assert.IsNotNull (vpd, "#2");
			Assert.AreEqual ("apppath/x/y_modified", vpd.VirtualPath, "#3");
			Assert.AreEqual (0, vpd.DataTokens.Count, "#4");
		}
开发者ID:carrie901,项目名称:mono,代码行数:15,代码来源:RouteCollectionTest.cs

示例10: GenerateOutboundVirtualPath

        /// <summary>
        /// Generates an outbound url from the specified values.  Requires a delegate
        /// to populate a route collection with all possible routes.
        /// </summary>
        /// <param name="routeValues">The route values from which to generate the url</param>
        /// <param name="registerRoutes">Delegate to register all possible routes</param>
        /// <returns>The virtual path data object</returns>
        public static VirtualPathData GenerateOutboundVirtualPath(RouteValueDictionary routeValues, Action<RouteCollection> registerRoutes)
        {
            // Arrange (get the routing config and test context)
            RouteCollection routeConfig = new RouteCollection();
            registerRoutes(routeConfig);

            HttpContextBase mockHttp = MockHelpers.HttpContext(null).Object;
            RequestContext context = new RequestContext(mockHttp, new RouteData());

            // Act (generate a URL)
            return routeConfig.GetVirtualPath(context, routeValues);
        }
开发者ID:triggerfish,项目名称:Common,代码行数:19,代码来源:OutboundRoutingHelpers.cs

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

示例12: GenerateUrl

        internal static string GenerateUrl(string routeName, string actionName, string controllerName, RouteValueDictionary routeValues, RouteCollection routeCollection, RequestContext requestContext, bool includeImplicitMvcValues) {
            RouteValueDictionary mergedRouteValues = RouteValuesHelpers.MergeRouteValues(actionName, controllerName, requestContext.RouteData.Values, routeValues, includeImplicitMvcValues);

            VirtualPathData vpd = routeCollection.GetVirtualPath(requestContext, routeName, mergedRouteValues);
            if (vpd == null) {
                return null;
            }

            string modifiedUrl = PathHelpers.GenerateClientUrl(requestContext.HttpContext, vpd.VirtualPath);
            return modifiedUrl;
        }
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:11,代码来源:UrlHelper.cs

示例13: GenerateUrl

 private string GenerateUrl(RouteCollection routeCollection, RouteValueDictionary routeValueDictionary)
 {
     var requestContext = _urlHelper.RequestContext;
     var virtualPathForArea = routeCollection.GetVirtualPath(requestContext, null,
         routeValueDictionary ?? new RouteValueDictionary());
     return virtualPathForArea == null ? null : GenerateClientUrl(requestContext.HttpContext, virtualPathForArea.VirtualPath);
 }
开发者ID:l1183479157,项目名称:RabbitHub,代码行数:7,代码来源:DefaultNavigationManager.cs

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

示例15: GetVirtualPath7

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

			c.Add (new MyRoute ("{table}/{action}.aspx", new MyRouteHandler ()) {
				Constraints = new RouteValueDictionary (new { action = "List|Details|Edit|Insert" }),
			});

			var req = new FakeHttpWorkerRequest ();
			var ctx = new HttpContext (req);
			HttpContext.Current = ctx;
			var rd = new RouteData ();
			var hc = new HttpContextWrapper (ctx);

			var vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
				{"Table", "FooTable"},
				{"Action", "Details"}
			});

			Assert.IsNotNull (vp, "#A1");
			Assert.AreEqual ("/FooTable/Details.aspx", vp.VirtualPath, "#A1-1");

			vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
				{"Table", "FooTable"},
				{"Action", String.Empty}
			});

			Assert.IsNull (vp, "#B1");

			vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
				{"Table", "FooTable"},
				{"Action", null}
			});

			Assert.IsNull (vp, "#C1");
		}
开发者ID:carrie901,项目名称:mono,代码行数:36,代码来源:RouteCollectionTest.cs


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