Quantcast
Channel: Fluent Assertions
Viewing all articles
Browse latest Browse all 1402

New Post: Confusion with OnlyContain usage

$
0
0

I came across something that I found counter-intuitive and I was just wondering if this was a bug or is the desired functionality...

[TestMethod]
public void TestMethod1()
{
	var myList = new List<string>();
	myList.Should().OnlyContain(x => x == "bar"); //This passes
	
	myList.Should().Contain(x => x == "bar"); //This fails

	myList.Add("foo");
	
	myList.Should().OnlyContain(x => x == "bar"); //This fails

}

To me it seems like OnlyContain should verify that "bar" is in the collection and if the collection is empty it should through an error.

Can someone describe a scenario where it would be acceptable for OnlyContain to not throw an error when the collection is empty?


Viewing all articles
Browse latest Browse all 1402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>