Created
October 6, 2010 17:57
-
-
Save MarkBorcherding/613785 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[When(@"I get the URL for the route")] | |
public void Given_I_get_the_URL_for_the_route() { | |
_path = LookupOutboundUrlFrom(_routeData, usingRoutes:MyRoutes(), whileRequestingUrl:_currentPage); | |
} | |
static string LookupOutboundUrlFrom( RouteValueDictionary givenRouteValues = null, | |
object givenRouteData = null, | |
RouteCollection usingRoutes = null, | |
string whileRequestingUrl = "~/", | |
string applicationPath = "/") | |
{ | |
usingRoutes = usingRoutes ?? new RouteCollection(); | |
var context = new Mock<HttpContextBase>(); | |
var request = new Mock<HttpRequestBase>(); | |
var response = new Mock<HttpResponseBase>(); | |
context.Setup(c => c.Request).Returns(request.Object); | |
context.Setup(c => c.Response).Returns(response.Object); | |
request.Setup(c => c.ApplicationPath).Returns(applicationPath); | |
request.Setup(x=>x.AppRelativeCurrentExecutionFilePath).Returns(whileRequestingUrl); | |
response.Setup(c => c.ApplyAppPathModifier(It.IsAny<string>())).Returns((string s) => s); | |
var requestedRoute = usingRoutes.GetRouteData(context.Object); | |
var defaultRouteData = new RouteData(); | |
defaultRouteData.Values.Add("controller",requestedRoute.Values["controller"]); | |
defaultRouteData.Values.Add("action",requestedRoute.Values["action"]); | |
var helper = new UrlHelper(new RequestContext(context.Object,defaultRouteData),usingRoutes); | |
return givenRouteData == null | |
? helper.RouteUrl(givenRouteValues) | |
: helper.RouteUrl(givenRouteData); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment