I have some unit tests that check a message in a WebApi project, it was a version of WebApi 1.0 that I upgraded to webapi 2.0, now, trying to build an answer, and add the location of the new ApiController resource. Url returns null. Prior to the upgrade, these unit tests passed. Here is the controller setup
var config = new HttpConfiguration();
SetDependencyResolver(config, type);
var request = new HttpRequestMessage(method, url);
var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}");
var routeData =
new HttpRouteData(
route,
new HttpRouteValueDictionary { { "controller", controllerName } });
request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
request.Properties[HttpPropertyKeys.HttpRouteDataKey] = routeData;
controller.Configuration = config;
controller.ControllerContext = new HttpControllerContext(config, routeData, request);
controller.Request = request;
Here is a challenge that fails. Note that the Url object returns null
response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = claimsCommand.Id }));
So what am I doing wrong right now when I have an update to the latest version?
source
share