title: MOQ - How to verify static class call and delegates?
body: <p>I just started reading on Moq framework and thought of applying it to my existing code. I could come up with a test case to verify basic function calls. But now stuck at applying it to delegates and static classes. </p>
  
  <p>Below is the system under test (SUT)   </p>
  
  <pre><code>public class SUT : ISUT
  {
     private IInterface1 i1;,
     private IInterface2 i2;
  
     public SUT(IInterface1 i1, IInterface2 i2)
     { 
        this.i1 = i1;
        this.i2 = i2;
     }
  
     public void FunctionToTest(Action&lt;string&gt; someDelegate, Action otherDelegate)
     {
         var list = i2.GetList();
  
         foreach(var r in list)
         {
        i1.SomeFunction(r);
  
            if(someDelegate != null)
                someDelegate("message");                        
  
            SomeHelper.LogData(r);
         }   
  
         if(otherDelegate != null)    
               otherDelegate();
     }
  }
  </code></pre>
  
  <p>I have setup my test as below</p>
  
  <pre><code>[TestFixture]
  public class when_list_contains_atleast_one_item
  {
     ISUT sut;
     Mock&lt;IInterface1&gt; mockI1;
     Mock&lt;IInterface2&gt; mockI2;
  
     public SUT_Tester()
     {
         mockI1 = new Mock&lt;IInterface1&gt;();
         mockI2 = new Mock&lt;IInterface2&gt;();
         sut = new SUT(mockI1.Object, mockI2.Object);
     }
  
     [Test]
     public void it_should_call_somefunction_calldelegates_and_log_data()
     {
         var dummyList = new List&lt;string&gt; { "string1", "string2" };
         mockI2.Setup(m2 =&gt; m2.GetList()).Returns(dummyList).Verifiable();
  
         sut.FunctionToTest(It.IsAny&lt;Action&lt;string&gt;&gt;(), It.IsAny&lt;Action&gt;());   
  
         // How to verify delegates were raised
         // How to verify SomeHelper.LogData was called                
  
         mockI1.Verify(m =&gt; m.SomeFunction(It.IsAny&lt;string&gt;()), Times.Exactly(2));
         mockI2.Verify();
     }
  }
  </code></pre>
  
  <p>How to verify that someDelegate and otherDelegate were raised ?
  SomeHelper is a static class and LogData is a static function. How to verify that LogData was called?</p>
  
  <p>Below is the SomeHelper class</p>
  
  <pre><code>public static class SomeHelper
  {
      static ILogger logger = LoggerManager.GetLogger("Something");
      public static void LogData(string input)
      {
          logger.Info(input);
      }
  }
  </code></pre>