ASP.NET WebApi unit testing with Request.CreateResponse
Another way to solve this is to do the following: controller.Request = new HttpRequestMessage(); controller.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); If you are upgrading to webapi 5.0, then you’ll need to change this to: controller.Request = new HttpRequestMessage(); controller.Request.SetConfiguration(new HttpConfiguration()); The reason why you need to do this is because you have to have Request populated on the … Read more