2015-07-20 115 views
2

我写单元测试,我有一些看起来像这样:FluentAssertions,确保了IEnumerable仅包含单元素

[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>

+0

你是什么意思 “不工作” 吗?请澄清问题 – Avery

回答

0

试试这个页面,看看是否有帮助。 https://github.com/dennisdoomen/fluentassertions/wiki

collection.Should().ContainSingle(); 
collection.Should().ContainSingle(x => x > 3); 
collection.Should().Contain(8).And.HaveElementAt(2, 5).And.NotBeSubsetOf(new[] {11, 56}); 
collection.Should().Contain(x => x > 3); 
collection.Should().Contain(collection, 5, 6); // It should contain the original items, plus 5 and 6. 
+0

这并不直接解决问题。 –

+0

它显示了不直接给出答案而获得结果的不同方式。感谢您的反对票。非常感激。 –

+0

虽然我认真,但也许我应该更具体。 –

4

OnlyContain预计谓语 -

GetFoos().Should().OnlyContain(x => _foo1.Equals(x)); 
相关问题