title: Moq Func Parameter
body: <p>I have a unit test using a Func parameter that I can't seem to get working with MOQ. Looking at other examples of Func parameters on StackOverflow, this is what I think should work:</p>
  <p>Code to test:</p>
  <pre><code>public class PatternManager : IPatternManager
  {
      private readonly ICacheManager _cacheManager;
      private readonly IDataRepo _data;
  
      public PatternManager(ICacheManager cacheManager, IDataRepo dataRepo)
      {
          _cacheManager = cacheManager;
          _data = dataRepo;
      }
  
      public List&lt;Pattern&gt; GetAllPatterns()
      {
          var allPatterns = _cacheManager.Get(() =&gt; _data.GetAllPatterns(), nameof(_data.GetAllPatterns));
  
          return allPatterns;
      }
  
      public Pattern GetBestPattern(int[] ids)
      {
          var patternList = GetAllPatterns().Where(w =&gt; w.PatternId &gt; 1);
  
          ... More code...
      }
      ...
  }
  
  
  public interface ICacheManager
  {
      T Get&lt;T&gt;(Func&lt;T&gt; GetMethodIfNotCached, string cacheName = null, int? cacheDurationInSeconds = null, string cachePath = null);
  
  }
  </code></pre>
  <p>Instead of the list of Pattern that I expect from GetAllPatterns(), I am getting null.</p>
  <pre><code>[Test]
  public void PatternManager_GetBestPattern()
  {
      var cacheManager = new Mock&lt;ICacheManager&gt;();
      var dataRepo = new Mock&lt;IDataRepo&gt;();
  
      dataRepo.Setup(d =&gt; d.GetAllPatterns())
                      .Returns(GetPatternList());
  
      cacheManager.Setup(s =&gt; s.Get(It.IsAny&lt;Func&lt;List&lt;Pattern&gt;&gt;&gt;(), &quot;&quot;, 100, &quot;&quot;)) // Has optional params
                      .Returns(dataRepo.Object.GetAllPatterns());
  
      patternManager = new PatternManager(cacheManager.Object, dataRepo.Object);
  
      int[] pattern = { 1, 2, 3};
  
      var bestPattern = patternManager.GetBestPattern(pattern);
  
      Assert.AreEqual(1, bestPattern.PatternId);
  }
  
  private static List&lt;Pattern&gt; GetPatternList()
  { 
      ... returns a list of Pattern
  }
  </code></pre>
  <p>What is wrong with this setup?</p>