Last active
August 29, 2015 14:27
-
-
Save johnmmoss/a633b30955d2916a5783 to your computer and use it in GitHub Desktop.
Mocking Web API Controller Context
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
var controller = new TestController(); | |
var config = new HttpConfiguration(); | |
var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/api/test"); | |
var route = config.Routes.MapHttpRoute("default", "api/{controller}/{id}"); | |
var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "test" } }); | |
controller.ControllerContext = new HttpControllerContext(config, routeData, request); | |
controller.Request = request; | |
controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment