Web での単純な検索だと思っていたことが、それ以上のものであることが判明しました。
ソリューションに最も近いのは、最初にルーティングに属性を使用できるようにしたものです:
しかし、ASP.NET Web Api 2 はどうでしょうか。
私の単体テスト
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);
}
}
コントローラーを挿入して、コントローラーの属性を読み取り、ルートを設定して、実際にテストを実行できるようにするにはどうすればよいですか?