需求如下:
有一个WebApi 是 HttpPatch 的源码如下:
[HttpPatch]
[Route("test/{testId}")]
public async Task<IActionResult> UpdateA([FromBody]TestItem test, int testId)
{
//.....
}
测试代码如下:
[Fact]
public async Task UpdateATest()
{
var requestMessage = new HttpRequestMessage(new HttpMethod("PATCH"), $"test/{testId}")
{
Content = new ObjectContent<dynamic>(new
{
UserID = 1,
Title = "Second Queston From Web Api",
Content = "Second Question from Web Api"
}, "application/json")
};
var response = await _httpClient.SendAsync(requestMessage);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
疑问
在.NET-Core 上 ObjectContent 是不支持的,请问,我需要如何进行测试 HttpPatch的请求呢?
1 回答
- 1 回答
- 0 关注
- 474 浏览
添加回答
举报
0/150
提交
取消