【问题标题】:FluentAssertions: match each object of a collectionFluentAssertions:匹配集合的每个对象
【发布时间】:2014-06-15 11:16:27
【问题描述】:

如何检查集合的每个对象是否符合给定的谓词?例如:检查每个项目(来自给定集合)是否匹配给定谓词(MyPredicate)。代码应该看起来像这样:

collection.Should().AllMatch(item => MyPredicate(item));

有类似的东西,还是我必须自己写?

【问题讨论】:

    标签: c# .net fluent-assertions


    【解决方案1】:

    Fluent Assertions 2.x 似乎不支持这种情况。使用 Fluent Assertions 3.x 可以使用:

    collection.Should().OnlyContain(predicate)
    

    【讨论】:

      猜你喜欢
      • 2016-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多