Created
June 6, 2012 16:05
-
-
Save eugeneagafonov/2882940 to your computer and use it in GitHub Desktop.
How to run unit tests in new web api builds
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
// assuming we have an IoC container. Autofac example | |
var builder = new ContainerBuilder(); | |
// assuming your global.asax.cs defines WebApiApplication : HttpApplication | |
builder.RegisterApiControllers(typeof(WebApiApplication).Assembly); | |
var container = builder.Build(); | |
// getting the controller | |
var target = container.Resolve<MyController>(); | |
var request = new HttpRequestMessage(); | |
request.Properties[HttpPropertyKeys.HttpConfigurationKey] = new HttpConfiguration(); | |
target.Request = request; | |
// now we can test | |
var correct = target.Get(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment