Tag: xunit asp.net core webapi

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

我有一个使用Xunit的unit testing项目,我们测试的方法返回IActionResult 。 我看到有些人建议使用“NegotiatedContentResult”来获取IActionResult的内容,但这在Xunit中不起作用。 所以我想知道如何在IActionResult中获取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中这样做?