nUnit:抛出HttpResponseException并访问嵌入的HttpResponseMessage

时间:2014-02-19 05:19:05

标签: exception nunit httpresponse http-status-codes

Assert.Throws<HttpResponseException>(() => ApiController.Post("query-params-string", "request-body-json"));

现在我想查看HttpResponseException.Response.StatusCode

的内容

有什么办法吗?

1 个答案:

答案 0 :(得分:2)

HttpResponseException ex = Assert.Throws<HttpResponseException>(() => ApiController.Post("query-params-string", "request-body-json"));<br>
Assert.AreEqual(ex.Response.StatusCode, HttpStatusCode.NotFound);