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