我有一个使用Xunit的单元测试项目,我们正在测试的方法返回IActionResult.
我看到有些人建议使用"NegotiatedContentResult"获取内容,IActionResult但这在Xunit中不起作用.
所以我想知道如何获取IActionResultXunit中的内容值?
测试代码示例如下:
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);
}
Run Code Online (Sandbox Code Playgroud)
有没有人知道如何在XUnit中这样做?