我有一个使用Xunit的单元测试项目,我们正在测试的方法返回 IActionResult
。
我看到有人建议使用 "NegotiatedContentResult" 来获取 IActionResult
的内容,但在Xunit中无法使用该方法。
所以我想知道如何在Xunit中获取 IActionResult
的内容值?
以下是测试代码示例:
public void GetTest()
{
var getTest = new ResourcesController(mockDb);
var result = getTest.Get("1");
//Here I want to convert the result to my model called Resource and
//compare the attribute Description like below.
Resource r = ?? //to get the content value of the IActionResult
Assert.Equal("test", r.Description);
}
有人知道如何在XUnit中实现这个吗?