[英]Unit test ASP.NET MVC 5 Controller with async Task<ActionResult>
您應該await
異步方法,並且應該遵循“一路異步”規則。
var result = await _controller.Index("644405",DateTime.Now);
而且,您必須將單元測試方法更改為async
。
您的單元測試應如下所示:(NUnit示例)
[Test]
public async Task ShouldGetValidViewObject_async()
{
var result = await _controller.Index("644405", DateTime.Now);
Assert.// your assertion goes here
}
或像這樣(同步)
[Test]
public void ShouldGetValidViewObject()
{
var result = _controller.Index("644405",DateTime.Now).Result;
Assert.// your assertion goes here
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.