Confusion with OnlyContain usage

Nov 9, 2011 at 2:44 PM

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?

Coordinator
Nov 13, 2011 at 3:45 PM

You're right. When the collection is empty, it should throw. I've fixed this in this changeset.

Nov 16, 2011 at 12:00 PM

Thanks!