this httpclientとhttpserverはMVC APIを使ってテストを統合しますが、500エラーが発生するため、私の動作に内部エラーはありませんフィドラーの間。私のコードは、refererとして非常に簡単です、私はそれらを貼り付けました。私はオリジナルの質問にコメントする十分な評判がないので、ここで新しい質問をしました。httpclientとhttpserverを使用してMVC Web APIをテストするとエラーが発生します
私のコントローラのアクションあなたがHttpClient
のデフォルトコンストラクタをテストする必要があります
[TestMethod]
public async Task InjectDocumentE2ETest()
{
var config = new HttpConfiguration();
//config.MapHttpAttributeRoutes();
//config.Routes.MapHttpRoute(name: "Default", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional });
WebApiConfig.Register(config);
using (var server = new HttpServer(config))
{
var client = new HttpClient(server);
// client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
string url = "http://localhost/api/InjectDocuments/hello";
var request = new HttpRequestMessage
{
RequestUri = new Uri(url),
Method = HttpMethod.Get
};
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
using (var response = await client.SendAsync(request))
{
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
}
using (var response = await client.GetAsync(url))
{
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
}
}
}
Ok()は何をしていますか? –
これを修正しましたか?私はまったく同じ問題を抱えています。 – gijswijs
代わりに、OWIN [TestServer](https://msdn.microsoft.com/en-us/library/microsoft.owin.testing.testserver(v = versus113).aspx)を使用することを検討してください。 –