本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
}
示例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());
}
示例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"]);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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
}