title: Branch coverage with foreach?
body: <p>I've got a simple method that calculate the total from a collection.</p>
  
  <pre><code>public void MethodToTest(Collection&lt;int&gt; collection)
  {
      int sum = 0;
      foreach (int value in collection)
      {
          sum += value;
      }
  }
  </code></pre>
  
  <p>The goal is to get a 100% at branch coverage using the opencoverage tool run in command line. I also got an Unit test that call the method MethodToTest :</p>
  
  <pre><code>[TestMethod]
  public void TestMethodToTest()
  {
      BomProviderMock mock = new BomProviderMock();
      BomManager bomManager = new BomManager(mock);
  
      List&lt;int&gt; list = new List&lt;int&gt;();
      for (int i = 0; i &lt;= Int16.MaxValue; i++)
      {
          list.Add(i);
      }
      // Firts attempt with a non empty collection
      bomManager.MethodToTest(new Collection&lt;int&gt;(list));
  
      // Second attempt with an empty collection
      bomManager.MethodToTest(new Collection&lt;int&gt;());
  }
  </code></pre>
  
  <p>After having used the tool opencover, the method MethodToTest got a 80% at branch coverage. My question is, does the foreach loop affect the branch coverage, if so, how can I get a 100% with this simple code?</p>