小编Jul*_* C.的帖子

如果在IActionResult类型中返回结果,如何在Xunit中获取内容值

我有一个使用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中这样做?

c# unit-testing xunit asp.net-core asp.net-core-webapi

20
推荐指数
1
解决办法
1万
查看次数