ForEach action issue

ForEach action issue

I'm using an attribute to exclude coverage. (Note: This is XNA stuff).

When I have the following code, everything gets excluded 100% which is correct...

    [CoverageExclude]
    public void Draw(SpriteBatch spriteBatch)
    {
        foreach (var item in Items)
        {
            item.Draw(spriteBatch);
        }
    }

But when I change the foreach to a ForEach, the "item.Draw(spriteBatch)" still gets covered anyway, even though I have set the method with the CoverageExclude attribute...

    [CoverageExclude]
    public void Draw(SpriteBatch spriteBatch)
    {
        Items.ForEach(item => item.Draw(spriteBatch));
    }

Because it is hard to unit test drawing on the screen with XNA, I want to exclude the entire method, but it doesn't seem to work correctly in my second example.

Here are the output from the report for that method.

Here are the output from the report for that method.

138    [CoverageExclude]
139    public void Draw(SpriteBatch spriteBatch)
140    {
141         //Items.ForEach(item => item.Draw(spriteBatch));
142         foreach (var item in Items)
143         {
144             item.Draw(spriteBatch);
145         }
146     }

AND

138     [CoverageExclude]
139     public void Draw(SpriteBatch spriteBatch)
140     {
141
 0         Items.ForEach(item => item.Draw(spriteBatch));
142     }


RE: ForEach action issue

Items.ForEach creates an anonymous method/class with a different name than Draw. This is why the Exclude attribute does not work.

You can still use the regular expressions to exclude this item.

Try to use reflector to determine the exact signature of the anonymous method/class.


RE: ForEach action issue

Thanks for the reply, jefohio1!

Regards,

NCover Support


RE: ForEach action issue

Thanks for the reply, jefohio1!

Regards,

NCover Support