Skip to content

Instantly share code, notes, and snippets.

@mwrock
Created September 26, 2012 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mwrock/3789014 to your computer and use it in GitHub Desktop.
Save mwrock/3789014 to your computer and use it in GitHub Desktop.
Testing UrlHelper.Route
//This is test setup
var mockTeamFoundationFeatureAvailabilityService = new Mock<ITeamFoundationFeatureAvailabilityService>();
var testable = new ApiFeatureAvailabilityController(x => mockTeamFoundationFeatureAvailabilityService.Object);
var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:8080/path");
var config = new HttpConfiguration();
config.Routes.MapHttpRoute("FeatureAvailability", "path/{id}", new { Controller = "ApiFeatureAvailability", id = RouteParameter.Optional });
request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
request.Properties[HttpPropertyKeys.HttpRouteDataKey] = config.Routes.GetRouteData(request);
testable.Url = new UrlHelper(request);
testable.Request = request;
//line being tested
return service.GetFeatureInformation(RequestContext).Select(x => new FeatureFlag(x.Name, x.Description, baseUri + Url.Route("FeatureAvailability", new { id = x.Name }), x.AvailabilityState.ToString()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment