Closed GoogleCodeExporter closed 8 years ago
It's not a bug, but rather a common misunderstanding of how loops and closures
are working together in C#. Please see the following question in Stackoverflow
for more info
(http://stackoverflow.com/questions/227820/why-is-it-bad-to-use-a-iteration-vari
able-in-a-lambda-expression)
Basically, you should use an intermediate variable. Like this:
[StaticTestFactory]
public static IEnumerable<Test> CreateStaticTests()
{
foreach (int searchTerm in new int[] { 1, 2, 3, 4, 5 })
{
int i = searchTerm;
yield return new TestCase("Search Term: " + i.ToString(), () =>
{
Assert.AreEqual(2, i);
});
}
}
Hope it helps,
Yann.
Original comment by Yann.Tre...@gmail.com
on 5 Sep 2010 at 2:34
Thank you very much. That helped.
A small hint on the documentataion here:
http://www.gallio.org/api/html/T_MbUnit_Framework_StaticTestFactoryAttribute.htm
would be useful. To me the example code looks the same as my one.
Sebastian
Original comment by snie...@gmail.com
on 5 Sep 2010 at 4:43
You are absolutely right. The example in the documentation does not work at all
for the exact same reason. I will fix that.
Regards,
Yann
Original comment by Yann.Tre...@gmail.com
on 5 Sep 2010 at 5:11
Original issue reported on code.google.com by
snie...@gmail.com
on 4 Sep 2010 at 4:19