Say we have a method that looks like this:
public IEnumerable<Dog> GrowAll(this IEnumerable<Puppy> puppies)
{
if(subjects == null)
throw new ArgumentNullException("subjects");
foreach(var puppy in puppies)
yield return puppy.Grow();
}
If I test that by doing this:
Puppy[] puppies = null;
Assert.Throws<ArgumentNullException>(() => puppies.GrowAll());
The test will fail saying that it
Expected:
<System.ArgumentNullException>
But was:null
I can fix that by changing the test to
Puppy[] puppies = null;
Assert.Throws<ArgumentNullException>(() => puppies.GrowAll().ToArray());
Is this just how you would usually do it? Or is there a better way to write the test? Or maybe a better way to write the method itself?
Tried to do the same with the built-in Select
method, and it failed even without a ToArray
or anything like that, so apparently there is something you can do about it... I just don't know what :p