小编Cho*_*isi的帖子

如何在 Assert.All 函数中使用多个断言

我不确定是否可能,但我相信应该。我希望我不会错过一些很容易的事情。

我正在使用.Net CorewithXUnit并尝试在Assert.All.

一个断言正常工作,而两个断言导致编译时错误Operator '&&' cannot be applied to operands of type 'void' and 'void'.。不知道是什么意思。

这编译。

Assert.All(users, user => Assert.True(user.IsAdministrator));
Assert.All(users, user => Assert.True(user.Age >= YOUNG_AGE));
Run Code Online (Sandbox Code Playgroud)

这不编译。

Assert.All(users, user => (Assert.True(user.IsAdministrator) && Assert.True(user.Age >= YOUNG_AGE)));
Run Code Online (Sandbox Code Playgroud)

如果您能帮助我,我将不胜感激,谢谢!

c# assert xunit .net-core asp.net-core

2
推荐指数
1
解决办法
40
查看次数

标签 统计

.net-core ×1

asp.net-core ×1

assert ×1

c# ×1

xunit ×1