Created
September 16, 2013 15:41
-
-
Save FernandoVezzali/6582368 to your computer and use it in GitHub Desktop.
Unit Testing ASP.NET Web API
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
//http://www.peterprovost.org/blog/2012/06/16/unit-testing-asp-dot-net-web-api/ | |
private static void SetupControllerForTests(ApiController controller) | |
{ | |
var config = new HttpConfiguration(); | |
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/products"); | |
var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}"); | |
var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "products" } }); | |
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