我正在编写单元测试,我有一些看起来像这样的东西:

[Fact]
public void GetFoos_only_gets_foo1()
{
    _foo1.included = true; //Foo object
    _foo2.included = false; //Foo object
    _sut.GetFoos().Should().OnlyContain(_foo1); // this doesn't work, is there a specific syntax to use?
}

GetFoos() 返回和 IEnumberable<Foo>

最佳答案

OnlyContain 需要一个谓词 -

 GetFoos().Should().OnlyContain(x => _foo1.Equals(x));

关于c# - FluentAssertions,确保 IEnumerable 只包含单个元素,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31525434/

10-11 21:45