title: Unit test LINQ Enumerables
body: <p>I am currently getting myself educated on unittests and LINQ, but I need some help.</p>
  
  <p>What would be a correct way of unittesting methods like these:</p>
  
  
  
  <pre><code>    /// &lt;summary&gt;
      /// Returns the product of all numbers.
      /// &lt;/summary&gt;
      static public decimal Product&lt;TSource&gt;(this IEnumerable&lt;TSource&gt; source, Func&lt;TSource, decimal&gt; selector)
      {
          return source.Aggregate&lt;TSource, decimal&gt;(1, (current, s) =&gt; current * selector(s));
      }
  
      /// &lt;summary&gt;
      /// Returns the product of all numbers.
      /// &lt;/summary&gt;
      static public decimal? Product&lt;TSource&gt;(this IEnumerable&lt;TSource&gt; source, Func&lt;TSource, decimal?&gt; selector)
      {
          return source.Select(selector).Aggregate&lt;decimal?, decimal?&gt;(1, (current, i) =&gt; current * i ?? 1);
      }
  </code></pre>
  
  <p>I really couldn't figure out how. No matter what I keep trying; when running Code Coverage, a few blocks always stay uncovered.</p>
  
  <p>What I have tried:</p>
  
  <pre><code>    [TestMethod]
      public void ExtendedProductAOfDecimalTest()
      {
          List&lt;decimal?&gt; items = new List&lt;decimal?&gt;(new decimal?[] { 5, 10, 15, 20, 25, 30 });
          Assert.AreEqual(11250000, Enumerable.Product(items, i =&gt; i));
      }
  
      [TestMethod]
      public void ExtendedProductBOfDecimalTest()
      {
          List&lt;decimal&gt; items = new List&lt;decimal&gt;(new decimal[] { 5, 10, 15, 20, 25, 30 });
          Assert.AreEqual(11250000, Enumerable.Product(items, i =&gt; i));
      }
  </code></pre>