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


C# RouteCollection.GetRouteData方法代码示例

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


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

示例1: RegisterRoutes

        public void RegisterRoutes(RouteCollection routes)
        {
            ViewEngines.Engines.Insert(0, new CustomViewEngine());

            routes.MapRoute("Plugin.Misc.LLT.ViewRegulations",
                "Regulations/",
                new { controller = "LLTHome", action = "Regulations" },
                new[] { CONTROLLERS_NAMESPACE });

            routes.MapRoute("Plugin.Misc.LLT.ViewRating",
                "Rating/",
                new { controller = "LLTHome", action = "Rating" },
                new[] { CONTROLLERS_NAMESPACE });

            routes.MapRoute("Plugin.Misc.LLT.ViewCourts",
                "Courts/",
                new { controller = "LLTHome", action = "Courts" },
                new[] { CONTROLLERS_NAMESPACE });

            routes.MapRoute("Plugin.Misc.LLT.ViewClubs",
                "Clubs/",
                new { controller = "Club", action = "List" },
                new[] { CONTROLLERS_NAMESPACE });

            routes.MapRoute("Plugin.Misc.LLT.ViewPlayers",
                "Players/",
                new { controller = "Player", action = "List"},
                new[] { CONTROLLERS_NAMESPACE });

            routes.MapRoute("Plugin.Misc.LLT.ViewHead2Head",
                "Head2Head/",
                new { controller = "Player", action = "Head2Head" },
                new[] { CONTROLLERS_NAMESPACE });

            routes.MapRoute("Plugin.Misc.LLT.ViewTournaments",
                "Tournaments/",
                new { controller = "Tournament", action = "List"},
                new[] { CONTROLLERS_NAMESPACE });

            routes.MapRoute("Plugin.Misc.LLT.ViewNews",
                "News/",
                new { controller = "LLTNews", action = "List" },
                new[] { CONTROLLERS_NAMESPACE });

            var routeDate = routes.GetRouteData(new FakeHttpContext("~/players"));
            routeDate = routes.GetRouteData(new FakeHttpContext("~/tournaments"));

            //LLT home page
            UpdateRoute(routes, "HomePage", "", "LLTHome", "Index", CONTROLLERS_NAMESPACE);
            //UpdateRoute(routes, "News", "", "LLTNews", "List", CONTROLLERS_NAMESPACE);
            //UpdateRoute(routes, "NewsItem", "", "LLTNews", "NewsItem", CONTROLLERS_NAMESPACE);
        }
开发者ID:AlexandrKiselev79,项目名称:LLT_Site,代码行数:52,代码来源:RouteProvider.cs

示例2: TestSearchListingsRouteDefaults

        public void TestSearchListingsRouteDefaults()
        {
            var routes = new RouteCollection();
            RouteConfig.RegisterRoutes(routes, false);
            //MvcApplication.RegisterRoutes(routes);

            var httpContextMock = new Mock<HttpContextBase>();
            httpContextMock.Setup(c => c.Request.AppRelativeCurrentExecutionFilePath)
                .Returns("~/Search/1111/1");

            var routeData = routes.GetRouteData(httpContextMock.Object);
            Assert.IsNotNull(routeData, "Should have found the route");
            Assert.AreEqual("Search", routeData.Values["Controller"]
                , "Expected a different controller");
            Assert.AreEqual("SearchJsonResult", routeData.Values["action"]
                , "Expected a different action");
            Assert.AreEqual("DateListed", routeData.Values["sortField"]
                , "Expected a different sortField");
            Assert.AreEqual(true, routeData.Values["sortDirectionDesc"]
                , "Expected a different sortDirectionDesc");
            Assert.AreEqual("1111", routeData.Values["location"]
                , "Expected a different location");
            Assert.AreEqual("1", routeData.Values["currentPageIndex"]
                , "Expected a different currentPageIndex");
        }
开发者ID:brontebantam,项目名称:MySiteMaster,代码行数:25,代码来源:Route_Tests.cs

示例3: TestRouteFail

 private void TestRouteFail(string url)
 {
     RouteCollection routes = new RouteCollection();
     RouteConfig.RegisterRoutes(routes);
     RouteData result = routes.GetRouteData(CreateHttpContext(url));
     Assert.IsTrue(result == null || result.Route == null);
 }
开发者ID:HowardHaoSun,项目名称:GITProject1,代码行数:7,代码来源:UnitTest1.cs

示例4: TestRoute

        private void TestRoute(string url, object expectedValues)
        {
            // Arrange: Prepare the route collection and a mock request context
            RouteCollection routes = new RouteCollection();
            MvcApplication.RegisterRoutes(routes);
            var mockHttpContext = new Moq.Mock<HttpContextBase>();
            var mockRequest = new Moq.Mock<HttpRequestBase>();
            mockHttpContext.Setup(x => x.Request).Returns(mockRequest.Object);
            mockRequest.Setup(x => x.AppRelativeCurrentExecutionFilePath).Returns(url);

            // Act: Get the mapped route
            RouteData routeData = routes.GetRouteData(mockHttpContext.Object);

            // Assert: Test the route values against expectations
            Assert.IsNotNull(routeData);
            var expectedDict = new RouteValueDictionary(expectedValues);
            foreach (var expectedVal in expectedDict)
            {
                if (expectedVal.Value == null)
                    Assert.IsNull(routeData.Values[expectedVal.Key]);
                else
                    Assert.AreEqual(expectedVal.Value.ToString(),
                                    routeData.Values[expectedVal.Key].ToString());
            }
        }
开发者ID:benjito,项目名称:Projects,代码行数:25,代码来源:InboundRoutingTests.cs

示例5: Match

        public static void Match(this string url, string controller = "Home", string action = "Index", object routeValues = null)
        {
            var httpcontext = new StubHttpContext(requestUrl: url);
            var routes = new RouteCollection();
            MvcApplication.RegisterRoutes(routes);
            RouteData routeData = routes.GetRouteData(httpcontext);

            var _matchRouteValues = true;
            var _routeFailValue = "";
            if (routeValues != null)
            {
                PropertyInfo[] props = routeValues.GetType().GetProperties();

                foreach (var prop in props)
                {
                    if (!prop.GetValue(routeValues, null).Equals(routeData.Values[prop.Name]))
                    {
                        _matchRouteValues = false;
                        _routeFailValue = prop.Name;
                        break;
                    }
                }
            }

            Assert.IsNotNull(routeData, "routeData nulo, url não foi resolvida corretamente");
            Assert.AreEqual(controller, routeData.Values["controller"]);
            Assert.AreEqual(action, routeData.Values["action"]);
            Assert.IsTrue(_matchRouteValues, String.Format("route value '{0}' not match!", _routeFailValue));
        }
开发者ID:thiagozulato,项目名称:TestandoRotas,代码行数:29,代码来源:Helpers.cs

示例6: TestRoute

        private static void TestRoute(string url, object expectedControllerAction)
        {
            var routes = new RouteCollection();
            var routeMapper = new Configuration.RouteMapper(routes);
            routeMapper.RegisterRoutes();
            var mockHttpContext = new Mock<HttpContextBase>();
            var mockRequest = new Mock<HttpRequestBase>();
            mockHttpContext.Setup(x => x.Request).Returns(mockRequest.Object);
            mockRequest.Setup(x => x.AppRelativeCurrentExecutionFilePath).Returns(url);

            RouteData routeData = routes.GetRouteData(mockHttpContext.Object);

            Assert.IsNotNull(routeData);
            var expectedRoutes = new RouteValueDictionary(expectedControllerAction);
            foreach (var route in expectedRoutes)
            {
                if (route.Value == null)
                {
                    Assert.IsNull(routeData.Values[route.Key]);
                }
                else
                {
                    Assert.AreEqual(route.Value.ToString(), routeData.Values[route.Key].ToString());
                }
            }
        }
开发者ID:RezaMahmood,项目名称:ChopShop,代码行数:26,代码来源:InboundTests.cs

示例7: TestRoute

        private RouteData TestRoute( string url, object expectedValues )
        {
            //Arrange
            RouteCollection routeCollection = new RouteCollection();
            MvcApplication.RegisterRoutes( routeCollection );
            var mockHttpContext = new MockHttpContext().MakeMockHttpContext( url );

            //Act
            RouteData routeData = routeCollection.GetRouteData( mockHttpContext.Object );

            //Assert
            Assert.IsNotNull( routeData, "Null RouteData was returned" );
            Assert.IsNotNull( routeData.Route, "No route was matched" );

            var expectedDict = new RouteValueDictionary( expectedValues );

            foreach ( var item in expectedDict )
            {
                if ( item.Value == null )
                    Assert.IsNull( routeData.Values[item.Key] );
                else
                    Assert.AreEqual( item.Value.ToString(), routeData.Values[item.Key].ToString() );
            }

            return routeData;
        }
开发者ID:j3itchtits,项目名称:jumblist,代码行数:26,代码来源:InboundRouteTest.cs

示例8: ActionSelectionIsOrdinalCaseInsensitive

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

             routes.MapRoute(null, "{action}",
            new { controller = "ActionSelection" });

             foreach (string action in new[] { "Strasse", "Straße" }) {

            var httpContextMock = new Mock<HttpContextBase>();
            httpContextMock.Setup(c => c.Request.AppRelativeCurrentExecutionFilePath).Returns("~/" + action.ToUpperInvariant());

            var httpResponseMock = new Mock<HttpResponseBase>();
            httpContextMock.Setup(c => c.Response).Returns(httpResponseMock.Object);

            var routeData = routes.GetRouteData(httpContextMock.Object);

            var controllerInstance = (Controller)Activator.CreateInstance(typeof(ActionSelection.ActionSelectionController));
            controllerInstance.ValidateRequest = false;

            var requestContext = new RequestContext(httpContextMock.Object, routeData);
            var controllerContext = new ControllerContext(requestContext, controllerInstance);

            ((IController)controllerInstance).Execute(requestContext);

            httpResponseMock.Verify(c => c.Write(It.Is<string>(s => String.Equals(s, action, StringComparison.OrdinalIgnoreCase))), Times.AtLeastOnce());
             }
        }
开发者ID:brettveenstra,项目名称:MvcCodeRouting,代码行数:28,代码来源:ActionSelectionFacts.cs

示例9: TestRoute

        private void TestRoute(string url, object expectedValues)
        {
            // Подготовка
            RouteCollection routes = new RouteCollection();
            RouteConfig.RegisterRoutes(routes);
            var mockHttpContext = new Moq.Mock<HttpContextBase>();
            var mockRequest = new Moq.Mock<HttpRequestBase>();
            mockHttpContext.Setup(x => x.Request).Returns(mockRequest.Object);
            mockRequest.Setup(x => x.AppRelativeCurrentExecutionFilePath).Returns(url);

            // Действие
            RouteData routeData = routes.GetRouteData(mockHttpContext.Object);

            // Утверждение
            Assert.IsNotNull(routeData);
            var expectedDist = new RouteValueDictionary(expectedValues);
            foreach (var expectedVal in expectedDist)
            {
                if (expectedVal.Value == null)
                    Assert.IsNull(routeData.Values[expectedVal.Key]);
                else
                    Assert.AreEqual(expectedVal.Value.ToString(),
                                    routeData.Values[expectedVal.Key].ToString());
            }
        }
开发者ID:AbstractStudent,项目名称:SportStore,代码行数:25,代码来源:InboundRoutingTests.cs

示例10: TestCertainRoute

 public void TestCertainRoute()
 {
     var routes = new RouteCollection();
     RouteConfig.RegisterRoutes(routes);
     var mockHttpContext = MakeMockHttpContext("~/");
     var routeData = routes.GetRouteData(mockHttpContext.Object);
     Assert.IsNotNull(routeData, "NULL RouteData was returned");
 }
开发者ID:BernieCook,项目名称:FallenNova,代码行数:8,代码来源:IncomingRouteTests.cs

示例11: RetrieveRouteData

        private static RouteData RetrieveRouteData(RouteCollection routes, string httpVerb, string url)
        {
            var httpContext = new Mock<HttpContextBase>();
            httpContext.Setup(c => c.Request.AppRelativeCurrentExecutionFilePath).Returns(url);
            httpContext.Setup(c => c.Request.HttpMethod).Returns(httpVerb);

            return routes.GetRouteData(httpContext.Object);
        }
开发者ID:dlidstrom,项目名称:Snittlistan,代码行数:8,代码来源:RouteTestHelper.cs

示例12: GetRouteDataForUrl

        private static RouteData GetRouteDataForUrl(string relativeUrl)
        {
            var routes = new RouteCollection();
            MvcApplication.RegisterRoutes(routes);
            var context = new FakeHttpContext(relativeUrl);

            return routes.GetRouteData(context);
        }
开发者ID:mmozuras,项目名称:DotNetGroup,代码行数:8,代码来源:RoutingTests.cs

示例13: DefinirUrl

 private static RouteData DefinirUrl(string url)
 {
     Mock<HttpContextBase> mockContext = new Mock<HttpContextBase>();
     mockContext.Setup(c => c.Request.AppRelativeCurrentExecutionFilePath).Returns(url);
     RouteCollection routes = new RouteCollection();
     RouteConfig.RegisterRoutes(routes);
     RouteData routeData = routes.GetRouteData(mockContext.Object);
     return routeData;
 }
开发者ID:flagage,项目名称:Certification,代码行数:9,代码来源:UnitTest1.cs

示例14: GetRouteData

        public RouteData GetRouteData(string url)
        {
            var context = new StubHttpContextForRouting(requestUrl: url);
            var routes = new RouteCollection();
            RouteConfig.RegisterRoutes(routes);

            var routeData = routes.GetRouteData(context);
            return routeData;
        }
开发者ID:hackohackob,项目名称:OpenJudgeSystem,代码行数:9,代码来源:RoutesTestsBase.cs

示例15: TestRouteFail

        public static void TestRouteFail(string url)
        {
            var routes = new RouteCollection();
            MvcApplication.RegisterRoutes(routes);

            RouteData result = routes.GetRouteData(CreateHttpContext(url));

            Assert.IsTrue(result == null || result.Route == null);
        }
开发者ID:nategreenwood,项目名称:SnippetCache,代码行数:9,代码来源:RouteHelpers.cs


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