FluentAssertions,确保IEnumerable仅包含单个元素 [英] FluentAssertions, making sure IEnumerable contains only single element
本文介绍了FluentAssertions,确保IEnumerable仅包含单个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写单元测试,并且看起来像这样:
I am writing unit tests and I have something that looks like this:
[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需要一个谓词-
OnlyContain expects a predicate -
GetFoos().Should().OnlyContain(x => _foo1.Equals(x));
这篇关于FluentAssertions,确保IEnumerable仅包含单个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文