Joh*_*ohn 2 c# unit-testing asp.net-core-mvc asp.net-core
我有一个要测试的 API。这是一种方法的签名......
[HttpGet("{param}")]
public async Task<IActionResult> Get(string param, string param2)
{
...
}
Run Code Online (Sandbox Code Playgroud)
在测试项目中,我以这种方式构建调用...
HttpClient client = new HttpClient();
string uri = "http://localhost:63779/api/controller_name/param/";
HttpResponseMessage response = await client.GetAsync(uri);
Run Code Online (Sandbox Code Playgroud)
param 是路线的一部分,但如何将 param2 带到该方法?
param2作为查询字符串传递给服务器。客户端代码:
HttpClient client = new HttpClient();
string uri = "http://localhost:63779/api/controller_name/param/?param2=SOME_VALUE";
HttpResponseMessage response = await client.GetAsync(uri);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8799 次 |
| 最近记录: |