What I thought was a simple search on the web turned out to be more than that.
The closest to a solution was the one that first made it possible to use Attributes for routing: AttributeRouting not working with HttpConfiguration object for writing Integration tests
But what about ASP.NET Web Api 2?
My unit test
HttpConfiguration config = new HttpConfiguration();
// config.MapHttpAttributeRoutes(); // This doesn't work. I guess there is needed some more plumbing to know what Controllers to search for attributes, but I'm lost here.
HttpServer server = new HttpServer(config);
using (HttpMessageInvoker client = new HttpMessageInvoker(server))
{
using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, "http://localhost/api/accounts/10"))
using(HttpResponseMessage response = client.SendAsync(request, CancellationToken.None).Result)
{
response.StatusCode.Should().Be(HttpStatusCode.Created);
}
}
How can I inject my controller so it reads attributes on the Controller and set the routes so I can actually do some testing?