对于ASP.Net Core2.2,我在PUT中使用了一个ModelBinder,如下所示:
[HttpPut("{taskIdentifier}/{number}")]
public async Task<IActionResult> Put(string taskIdentifier, string number,
[ModelBinder(typeof(TaskUpdateV1Binder<TaskUpdate>))]TaskUpdate value)
在运行时,TaskUpdateV1Binder被调用,它读取请求体并创建一个TaskUpdate对象。
我想对这个进行单元测试。我不能直接从单元测试中调用Put,因为这绕过了模型绑定。
我已经有了活页夹本身的测试,但是我需要测试控制器使用它。
我不是在测试MVC路由。
发布于 2019-09-27 22:48:32
这可以通过集成测试来实现,该测试可以在部署之前运行。在SO上提出了一个类似的问题,并很好地回答了(IMHO) here。如果你想看一个简短的解释和例子,看看它。
正如在回答中所建议的,我还建议您仔细阅读以下文档:https://learn.microsoft.com/en-us/aspnet/core/testing/integration-testing
https://stackoverflow.com/questions/58032923
复制相似问题