[英]Testing the results from an IActionResult controller method, when the return is a Tuple value
I've got a controller method that returns this to the client我有一个控制器方法可以将它返回给客户端
return Ok(new { user, profile});
It used to return the user object on its own, so my unit test on the method looked like this它曾经自己返回用户对象,所以我对该方法的单元测试看起来像这样
var res = await _controller.Get(_userId);
var okResult = res as OkObjectResult;
var resUser = okResult.Value as User;
i could then test individule bits of my return然后我可以测试我返回的各个部分
Assert.Contains("user@domain.com", resUser.EmailAddress);
However, now i'm returning aa tuple object our of the controller method its not working.但是,现在我要返回一个元组对象,我们的控制器方法不起作用。 Ive tried doing
我试过做
var resUser1 = okResult.Value as Tuple<User, Profile>;
But that always returns me null.但这总是让我返回 null。 Any idea how i can convert my result from the controller into something i can look into now its not just a flat object?
知道如何将我的结果从控制器转换成我现在可以查看的东西,它不仅仅是一个平面对象吗?
Thanks谢谢
好的,所以我尝试使用 ValueTuple 来转换结果,但它仍然接缝带回了一个空对象,所以我最终只是为结果创建了一个真实的对象并转换到该对象工作正常
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.