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


C# RouteCollection.Cast方法代码示例

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


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

示例1: RegisterUploadLogoRoute

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

            AppRoutes.RegisterRoutes(routes);

            var route = routes.Cast<Route>().SingleOrDefault(r =>
                    string.Equals(r.Url, "{tenant}/MyAccount/UploadLogo", StringComparison.OrdinalIgnoreCase) &&
                    string.Equals(r.Defaults["controller"] as string, "Account", StringComparison.OrdinalIgnoreCase) &&
                    string.Equals(r.Defaults["action"] as string, "UploadLogo", StringComparison.OrdinalIgnoreCase));
            Assert.IsNotNull(route);
        }
开发者ID:hanzzhang,项目名称:developguide,代码行数:12,代码来源:AppRoutesFixture.cs

示例2: RegisterOnBoardingRoute

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

            AppRoutes.RegisterRoutes(routes);

            var route = routes.Cast<Route>().SingleOrDefault(r =>
                    string.Equals(r.Url, string.Empty, StringComparison.OrdinalIgnoreCase) &&
                    string.Equals(r.Defaults["controller"] as string, "OnBoarding", StringComparison.OrdinalIgnoreCase) &&
                    string.Equals(r.Defaults["action"] as string, "Index", StringComparison.OrdinalIgnoreCase));
            Assert.IsNotNull(route);
        }
开发者ID:hanzzhang,项目名称:developguide,代码行数:12,代码来源:AppRoutesFixture.cs

示例3: RegisterFederationResultRoute

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

            AppRoutes.RegisterRoutes(routes);

            var route = routes.Cast<Route>().SingleOrDefault(r =>
                    string.Equals(r.Url, "FederationResult", StringComparison.OrdinalIgnoreCase) &&
                    string.Equals(r.Defaults["controller"] as string, "ClaimsAuthentication", StringComparison.OrdinalIgnoreCase) &&
                    string.Equals(r.Defaults["action"] as string, "FederationResult", StringComparison.OrdinalIgnoreCase));
            Assert.IsNotNull(route);
        }
开发者ID:hanzzhang,项目名称:developguide,代码行数:12,代码来源:AppRoutesFixture.cs

示例4: RegisteThankYouForFillingSurveyRoute

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

            AppRoutes.RegisterRoutes(routes);

            var route = routes.Cast<Route>().SingleOrDefault(r =>
                    string.Equals(r.Url, "survey/{tenant}/{surveySlug}/thankyou", System.StringComparison.OrdinalIgnoreCase) &&
                    string.Equals(r.Defaults["controller"] as string, "Surveys", System.StringComparison.OrdinalIgnoreCase) &&
                    string.Equals(r.Defaults["action"] as string, "ThankYou", System.StringComparison.OrdinalIgnoreCase));
            Assert.IsNotNull(route);
        }
开发者ID:hanzzhang,项目名称:developguide,代码行数:12,代码来源:AppRoutesFixture.cs

示例5: RegisteNewQuestionRoute

        public void RegisteNewQuestionRoute()
        {
            var routes = new RouteCollection();
            var registrationArea = new SurveyAreaRegistration();
            var areaRegistrationContext = new AreaRegistrationContext(registrationArea.AreaName, routes);

            registrationArea.RegisterArea(areaRegistrationContext);

            var route = routes.Cast<Route>().SingleOrDefault(r =>
                    string.Equals(r.Url, "survey/{tenant}/newquestion", System.StringComparison.OrdinalIgnoreCase) &&
                    string.Equals(r.Defaults["controller"] as string, "Surveys", System.StringComparison.OrdinalIgnoreCase) &&
                    string.Equals(r.Defaults["action"] as string, "NewQuestion", System.StringComparison.OrdinalIgnoreCase));
            Assert.IsNotNull(route);
        }
开发者ID:hanzzhang,项目名称:developguide,代码行数:14,代码来源:SurveyAreaRegistrationFixture.cs

示例6: RouteOrder

        public void RouteOrder()
        {
            RouteCollection collection = new RouteCollection();
            Routing.RegisterRoutes(collection);

            Route[] routes = collection.Cast<Route>().ToArray();
            Assert.Equal("a/b/c", routes[0].Url);
            Assert.Equal("a/b", routes[1].Url);
            Assert.Equal("a/{b}/{c}", routes[2].Url);
            Assert.Equal("a/{b}", routes[3].Url);
            Assert.Equal("a/{*b}", routes[4].Url);
            Assert.Equal("a", routes[5].Url);
            Assert.Equal(6, routes.Length);
        }
开发者ID:robmen,项目名称:tinybugs,代码行数:14,代码来源:RoutingFixture.cs

示例7: MapMvcAttributeRoutes_MapRouteAttributes

        public void MapMvcAttributeRoutes_MapRouteAttributes()
        {
            // Arrange
            var controllerTypes = new[] { typeof(SimpleRoutingController) };
            var routes = new RouteCollection();

            // Act
            routes.MapMvcAttributeRoutes(controllerTypes);

            // Assert
            var expectedResults = new List<Tuple<string, string, string[]>>
             {
                 new Tuple<string, string, string[]>("getme", "GetMe", new[] { "GET" }),
                 new Tuple<string, string, string[]>("postme", "PostMe", new[] { "POST" }),
                 new Tuple<string, string, string[]>("getorpostme", "GetOrPostMe", new[] { "GET", "POST" }),
                 new Tuple<string, string, string[]>("routeme", "RouteMe", null),
                 new Tuple<string, string, string[]>("once", "FoolMe", new[] { "GET" }),
                 new Tuple<string, string, string[]>("twice", "FoolMe", new[] { "GET" }),
                 new Tuple<string, string, string[]>("twice", "FoolMe", new[] { "GET" }),
             };

            foreach (var expected in expectedResults)
            {
                var url = expected.Item1;
                var methodName = expected.Item2;
                var expectedHttpMethods = expected.Item3;
                Route route = routes.Cast<Route>().Single(r => r.Url == url);
                Assert.Equal(methodName, route.GetTargetActionMethod().Name);
                var httpMethodConstraint = (HttpMethodConstraint)route.Constraints["httpMethod"];
                if (expectedHttpMethods == null)
                {
                    Assert.Null(httpMethodConstraint);
                }
                else
                {
                    Assert.NotNull(httpMethodConstraint);

                    var actualHttpMethods = httpMethodConstraint.AllowedMethods.ToArray();
                    Array.Sort(expectedHttpMethods);
                    Array.Sort(actualHttpMethods);
                    Assert.Equal(expectedHttpMethods, actualHttpMethods);
                }
            }
        }
开发者ID:karensyc,项目名称:aspnetwebstack,代码行数:44,代码来源:RouteCollectionAttributeRoutingExtensionsTests.cs

示例8: MapMvcAttributeRoutes_WithInlineConstraints_ParseConstraintsDefaultsAndOptionals

        public void MapMvcAttributeRoutes_WithInlineConstraints_ParseConstraintsDefaultsAndOptionals()
        {
            // Arrange
            var controllerTypes = new[] { typeof(SimpleRoutingController) };
            var routes = new RouteCollection();

            // Act
            routes.MapMvcAttributeRoutes(controllerTypes);

            // Assert
            Route route = routes.Cast<Route>().Single(r => r.GetTargetActionMethod().Name == "Parameterized");
            Assert.NotNull(route);

            Assert.Equal("i/{have}/{id}/{defaultsto}/{name}", route.Url);
            Assert.IsAssignableFrom<IntRouteConstraint>(route.Constraints["id"]);
            Assert.Equal("VAL", route.Defaults["defaultsto"]);
            Assert.Equal("", route.Defaults["name"].ToString());
        }
开发者ID:karensyc,项目名称:aspnetwebstack,代码行数:18,代码来源:RouteCollectionAttributeRoutingExtensionsTests.cs

示例9: IgnoreRoute4

        public void IgnoreRoute4()
        {
            // Arrange
            RouteCollection routes = new RouteCollection();
            var constraints = new { Foo = "DefaultFoo" };

            // Act
            routes.IgnoreRoute("SomeUrl", constraints);

            // Assert
            Route route = Assert.Single(routes.Cast<Route>());
            Assert.NotNull(route);
            Assert.Equal("SomeUrl", route.Url);
            Assert.IsType<StopRoutingHandler>(route.RouteHandler);
            Assert.Null(route.Defaults);
            Assert.Single(route.Constraints);
            Assert.Equal("DefaultFoo", route.Constraints["Foo"]);
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:18,代码来源:RouteCollectionExtensionsTest.cs

示例10: MapRoute5

        public void MapRoute5()
        {
            // Arrange
            RouteCollection routes = new RouteCollection();
            var defaults = new { Foo = "DefaultFoo" };
            var constraints = new { Foo = "ConstraintFoo" };

            // Act
            routes.MapRoute("RouteName", "SomeUrl", defaults, constraints);

            // Assert
            Route route = Assert.Single(routes.Cast<Route>());
            Assert.NotNull(route);
            Assert.Same(route, routes["RouteName"]);
            Assert.Equal("SomeUrl", route.Url);
            Assert.IsType<MvcRouteHandler>(route.RouteHandler);
            Assert.Equal("DefaultFoo", route.Defaults["Foo"]);
            Assert.Equal("ConstraintFoo", route.Constraints["Foo"]);
            Assert.Empty(route.DataTokens);
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:20,代码来源:RouteCollectionExtensionsTest.cs

示例11: MapRoute4WithNameSpaces

        public void MapRoute4WithNameSpaces()
        {
            // Arrange
            RouteCollection routes = new RouteCollection();
            var defaults = new { Foo = "DefaultFoo" };

            // Act
            routes.MapRoute("RouteName", "SomeUrl", defaults, _nameSpaces);

            // Assert
            Route route = Assert.Single(routes.Cast<Route>());
            Assert.NotNull(route);
            Assert.NotNull(route.DataTokens);
            Assert.NotNull(route.DataTokens["Namespaces"]);
            string[] routeNameSpaces = route.DataTokens["Namespaces"] as string[];
            Assert.Equal(routeNameSpaces.Length, 2);
            Assert.Same(route, routes["RouteName"]);
            Assert.Same(routeNameSpaces, _nameSpaces);
            Assert.Equal("SomeUrl", route.Url);
            Assert.IsType<MvcRouteHandler>(route.RouteHandler);
            Assert.Equal("DefaultFoo", route.Defaults["Foo"]);
            Assert.Empty(route.Constraints);
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:23,代码来源:RouteCollectionExtensionsTest.cs

示例12: MapRoute3WithEmptyNameSpaces

        public void MapRoute3WithEmptyNameSpaces()
        {
            // Arrange
            RouteCollection routes = new RouteCollection();

            // Act
            routes.MapRoute("RouteName", "SomeUrl", new string[] { });

            // Assert
            Route route = Assert.Single(routes.Cast<Route>());
            Assert.NotNull(route);
            Assert.Same(route, routes["RouteName"]);
            Assert.Equal("SomeUrl", route.Url);
            Assert.IsType<MvcRouteHandler>(route.RouteHandler);
            Assert.Empty(route.Defaults);
            Assert.Empty(route.Constraints);
            Assert.Empty(route.DataTokens);
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:18,代码来源:RouteCollectionExtensionsTest.cs

示例13: RegisterBrowseSurveyResponsesRoute

        public void RegisterBrowseSurveyResponsesRoute()
        {
            var routes = new RouteCollection();
            var registrationArea = new SurveyAreaRegistration();
            var areaRegistrationContext = new AreaRegistrationContext(registrationArea.AreaName, routes);

            registrationArea.RegisterArea(areaRegistrationContext);

            var route = routes.Cast<Route>().SingleOrDefault(r =>
                    string.Equals(r.Url, "survey/{tenant}/{surveySlug}/analyze/browse/{answerId}", System.StringComparison.OrdinalIgnoreCase) &&
                    string.Equals(r.Defaults["controller"] as string, "Surveys", System.StringComparison.OrdinalIgnoreCase) &&
                    string.Equals(r.Defaults["action"] as string, "BrowseResponses", System.StringComparison.OrdinalIgnoreCase) &&
                    string.Equals(r.Defaults["answerId"] as string, string.Empty, System.StringComparison.OrdinalIgnoreCase));
            Assert.IsNotNull(route);
        }
开发者ID:hanzzhang,项目名称:developguide,代码行数:15,代码来源:SurveyAreaRegistrationFixture.cs

示例14: MapRoute4WithDefaultsAsDictionary

        public void MapRoute4WithDefaultsAsDictionary()
        {
            // Arrange
            RouteCollection routes = new RouteCollection();
            var defaults = new Dictionary<string, object> { { "Foo", "DefaultFoo" } };

            // Act
            routes.MapRoute("RouteName", "SomeUrl", defaults);

            // Assert
            Route route = Assert.Single(routes.Cast<Route>());
            Assert.NotNull(route);
            Assert.Same(route, routes["RouteName"]);
            Assert.Equal("SomeUrl", route.Url);
            Assert.IsType<MvcRouteHandler>(route.RouteHandler);
            Assert.Equal("DefaultFoo", route.Defaults["Foo"]);
            Assert.Empty(route.Constraints);
            Assert.Empty(route.DataTokens);
        }
开发者ID:marojeri,项目名称:aspnetwebstack,代码行数:19,代码来源:RouteCollectionExtensionsTest.cs

示例15: VirtualDirWithChild

        public void VirtualDirWithChild()
        {
            //Arrange
            var portalInfo = new ArrayList { new PortalInfo { PortalID = 0 } };
            _mockPortalController.Setup(x => x.GetPortals()).Returns(portalInfo);

            var mockPac = new Mock<IPortalAliasController>();
            mockPac.Setup(x => x.GetPortalAliasByPortalId(0)).Returns(new[] { new PortalAliasInfo { HTTPAlias = "www.foo.com/vdir" }, new PortalAliasInfo{HTTPAlias = "www.foo.com/vdir/child"} });
            TestablePortalAliasController.SetTestableInstance(mockPac.Object);

            var mockGlobals = new Mock<IGlobals>();
            mockGlobals.Setup(x => x.ApplicationPath).Returns("/vdir");
            TestableGlobals.SetTestableInstance(mockGlobals.Object);

            var routeCollection = new RouteCollection();
            var srm = new ServicesRoutingManager(routeCollection);

            //Act
            srm.MapRoute("folder", "url", new[] { "foo" });

            //Assert
            Assert.AreEqual(2, routeCollection.Count);
            var urls = routeCollection.Cast<Route>().Select(x => x.Url).ToList();
            Assert.AreEqual(1, urls.Count(x => x.Contains("{prefix0}")));
            //if 2 urls and only 1 has prefix 0 then the other has no prefixesed wcon
        }
开发者ID:biganth,项目名称:Curt,代码行数:26,代码来源:ServiceRoutingManagerTests.cs


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