流畅的断言应该大于总是通过

Sim*_*ons 1 .net c# unit-testing fluent-assertions

我正在尝试使用以下方法测试我的集合:

  var costByFactoryt = dataAccess.GetcostPerFactoryt(null, null);
  costByFactoryt.Count().Should().BeGreaterThan(0);
  costByFactoryt.Select(x => x.Cost.Should().BeGreaterThan(100));
Run Code Online (Sandbox Code Playgroud)

但问题是,如果我将最后一行代码更改为,

 costByFactoryt.Select(x => x.Cost.Should().BeGreaterThan(1000));
Run Code Online (Sandbox Code Playgroud)

或者

costingByCircuit.Select(x => x.Cost.Should().BeLessThan(100));
Run Code Online (Sandbox Code Playgroud)

它仍然通过,这是错误的。

我想测试的是,所有成本应该大于100。

Kie*_*Chu 5

它根本无法以这种方式工作,因为 LINQ Select 不会迭代集合 => 您的测试代码不会执行

根据Fluent Assertions 文档

正确的语法应该是

costingByCircuit.Select(x => x.Cost).Should().OnlyContain(x => x > 100);
Run Code Online (Sandbox Code Playgroud)