title: How to unit test a dictionary which returns a func?
body: <p>My code looks as below:</p>
  
  <pre><code>public class FileFormatLookup : Dictionary&lt;string,Func&lt;string&gt;&gt;
  {
      private Workbook workbook;
      private MemoryStream memoryStream;
  
      public  FileFormatLookup(Workbook workbook, MemoryStream memoryStream)
      {
          this.workbook = workbook;
          this.memoryStream = memoryStream;
          Add();
      }
  
      private void Add()
      {
          base.Add("xls", () =&gt;
                              {
                                  workbook.Save(memoryStream, SaveFormat.Excel97To2003);
                                  return "ms-excel";
                              });
      }
  }
  </code></pre>
  
  <p>And I am trying to write the test as below:</p>
  
  <pre><code>class FileFormatLookupTest
  {
      FileFormatLookup fileFormatLookup;
      private Workbook workbook;
      private MemoryStream memoryStream;
  
      [SetUp]
      public void SetUp()
      {
          fileFormatLookup = new FileFormatLookup(workbook, memoryStream);
          workbook = MockRepository.GenerateMock&lt;Workbook&gt;();
          memoryStream = MockRepository.GenerateMock&lt;MemoryStream&gt;();
      }
  
      [TearDown]
      public void TearDown()
      {
        workbook.VerifyAllExpectations();
      }
  
  
      [Test]
      public void ShouldHaveXlsKey()
      {
          var xlsResult = fileFormatLookup["xls"].Invoke();
          workbook.AssertWasCalled(x=&gt;x.Save(memoryStream,SaveFormat.Excel97To2003));
       }
  }
  </code></pre>
  
  <p>Is this the correct way to test a functor inside dictionary?
  It throws this error :</p>
  
  <pre><code>System.InvalidOperationException : No expectations were setup to be verified, ensure that the method call in the action is a virtual (C#) / overridable (VB.Net) method call
  </code></pre>
  
  <p>How do I test a dictionary which returns a function? Is it possible?
  I can assert the string value which is returned but not the method calls.</p>