using System.Web;
using System.Web.Routing;
using Moq;
using Umbraco.Tests.TestHelpers;
namespace Umbraco.Tests.Routing
{
public static class RouteTestExtensions
{
///
/// Return the route data for the URL based on a mocked context
///
///
///
///
public static RouteData GetDataForRoute(this RouteCollection routes, string requestUrl)
{
var context = new FakeHttpContextFactory(requestUrl);
return routes.GetDataForRoute(context.HttpContext);
}
///
/// Get the route data based on the URL and HTTP context
///
///
///
///
public static RouteData GetDataForRoute(this RouteCollection routes, HttpContextBase httpContext)
{
var data = routes.GetRouteData(httpContext);
//set the route data on the request context
var requestMock = Mock.Get(httpContext.Request.RequestContext);
requestMock.Setup(x => x.RouteData).Returns(data);
return data;
}
///
/// Checks if the URL will be ignored in the RouteTable
///
///
///
///
/// MVCContrib has a similar one but is faulty:
/// http://mvccontrib.codeplex.com/workitem/7173
///
public static bool ShouldIgnoreRoute(this string url)
{
var http = new FakeHttpContextFactory(url);
var r = RouteTable.Routes.GetRouteData(http.HttpContext);
if (r == null) return false;
return (r.RouteHandler is StopRoutingHandler);
}
}
}