Hi,
I am writing a method which needs to check some parameters and if they are validated return an IEnumerable. E.g.
public static IEnumerable<double> GetEnum(int param)
{
if (!IsValidParameter(param))
{
throw new Exception();
}
while(true)
{
yield return 5.0;
}
}
However, I believe because of lazy evaluation, when I run my unit tests with bad parameters, but don't call any of the IEnumerable methods yet, the Exception is not thrown.
[Test]
[ExpectedException(typeof(Exception))]
void Test()
{
var ie = GetEnum(bad_param);
}
I can fix things by building the IEnumerable in another function (say Foo), then check parameters in GetEnum and call Foo but is there a solution without having to create multiple functions?
Cheers, Jurgen