本文整理汇总了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);
}
示例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");
}
示例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);
}
示例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());
}
}
示例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));
}
示例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());
}
}
}
示例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;
}
示例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());
}
}
示例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());
}
}
示例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");
}
示例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);
}
示例12: GetRouteDataForUrl
private static RouteData GetRouteDataForUrl(string relativeUrl)
{
var routes = new RouteCollection();
MvcApplication.RegisterRoutes(routes);
var context = new FakeHttpContext(relativeUrl);
return routes.GetRouteData(context);
}
示例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;
}
示例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;
}
示例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);
}