title: How to mock/setup a method with IEnumerable input parameters using Moq?
body: <p>I have used <a href="https://stackoverflow.com/a/489421/1410876">this</a> DistinctBy method with that difference that i'm not using it as an extension. Now i want to write an unit test for another method that is calling this one, so i want to setup the return.</p>
  
  <p><b>The "DistinctBy" Metod</b>   </p>
  
  <pre><code>public IEnumerable&lt;TSource&gt; DistinctBy&lt;TSource, TKey&gt;(
        IEnumerable&lt;TSource&gt; source, Func&lt;TSource, TKey&gt; keySelector)
  {
      HashSet&lt;TKey&gt; seenKeys = new HashSet&lt;TKey&gt;();
      foreach (TSource element in source)
      {
          if (seenKeys.Add(keySelector(element)))
          {
              yield return element;
          }
      }
  }
  </code></pre>
  
  <p><b>The Initial Setup</b>
  For now i have something like this(I'm using Autofac's Moq, Automock functionality):</p>
  
  <pre><code>List&lt;Product&gt; listProduct = new List&lt;Product&gt;{ product1, product2 };
  mock.Mock&lt;IHelpers&gt;()
      .Setup(r =&gt; r.DistinctBy&lt;List&lt;BeautyBoutiqueArticle&gt;, int&gt;(It.IsAny&lt;List&lt;BeautyBoutiqueArticle&gt;&gt;(), It.IsAny&lt;Func&lt;List&lt;BeautyBoutiqueArticle&gt;, int&gt;&gt;()))
      .Returns(ieList)
      .Verifiable();
  </code></pre>
  
  <p>But it's not working. It's displaying errors like:</p>
  
  <blockquote>
    <p>The best overloaded method match for.... has some illegal arguments,
    and/or  Argument 1: cannot convert from
    'System.Collections.Generic.List' to
    'System.Collections.Generic.IEnumerable>'</p>
  </blockquote>