如何做一个“ allnotsatatify”富有量的条件
考虑以下代码:
var ints = new List<Dictionary<string, string>>()
{
new Dictionary<string, string>() { { "1", "bill" }, { "2", "john" } },
new Dictionary<string, string>() { { "2", "jane" }, { "3", "alex" } }
};
这有效:
ints.Should().AllSatisfy(x => x.ContainsKey("2"));
但是,我想写一个断言,断言词典都没有一个“ 4”作为钥匙...
最初我认为我可以做到这一点:
ints.Should().AllSatisfy(x => !x.ContainsKey("2"));
但是那是不起作用的...我获取仅分配,呼叫,增量,减少,等待表达和新对象表达式可以用作语句
有没有任何方法可以在fluentAssertions中进行愚蠢地进行此操作?
我知道我可以做:
ints.Where(x => x.ContainsKey("2")).Should().BeEmpty();
对于为什么流利的断言可以将动作作为这种情况,我有些困惑。
Consider this code:
var ints = new List<Dictionary<string, string>>()
{
new Dictionary<string, string>() { { "1", "bill" }, { "2", "john" } },
new Dictionary<string, string>() { { "2", "jane" }, { "3", "alex" } }
};
This works:
ints.Should().AllSatisfy(x => x.ContainsKey("2"));
However, I want to write an assertions that asserts that none of the dictionaries contains a "4" as key...
Initially I thought I could do this:
ints.Should().AllSatisfy(x => !x.ContainsKey("2"));
But that doesn't work... I get Only assignment, call, increment, decrement, await expression, and new object expressions can be used as a statement
Is there any way to do this idiomatically in FluentAssertions?
I know that I can do:
ints.Where(x => x.ContainsKey("2")).Should().BeEmpty();
I'm a little stumped as to why fluent assertions can use actions as conditions like this where the return type is ignored.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用:
You can use: