我希望测试下面我的 API 请求之一的输出。
async Task DeleteNonExistantFoo()
{
using (HttpClient client = new HttpClient())
{
client.BaseAddress = new Uri("Http://localhost:43240/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
using (HttpResponseMessage response = await client.DeleteAsync("api/foos/1"))
{
var responseContent = await response.Content.ReadAsStringAsync();
//Assert.AreEqual(?????, "A Foo with ID of 1 does not exist.");
}
}
}
我想从下面的响应中获取 exceptionMessage,当我向 API 发送 DELETE 请求时,它作为响应给出。在 Visual Studio 中调试时,它不会让我查看响应内容对象,从而出现错误
“responseContent 无法获取局部变量或参数的值,因为它在此指令指针处不可用,可能是因为它已被优化掉。”
我是否需要将其转换为 JSON 对象才能读取它?
{
"message": "An error has occurred.",
"exceptionMessage": "A Foo with ID of 1 does not exist.",
"exceptionType": "System.Exception",
"stackTrace": "
}
幕布斯6054654
相关分类