title: How to Mock ILogger / ILoggerService using Moq
body: <p>I'm writing some unit tests for my View Model class. The constructor of this class is injected with an ILoggerService. This interface defines 1 method GetLog which returns an ILogger. Something like below where <strong><em>this</em></strong> represents a class that implements ILoggable:-</p>
  
  <pre><code>protected ViewModelBase(ILoggerService loggerService)
      {
          Logger = loggerService.GetLog(this);
      }
  </code></pre>
  
  <p>I'm trying to unit test my CreateNewOrder method that looks like below:</p>
  
  <pre><code>private void CreateNewOrder(INewOrderViewModel newOrderViewModel)
      {
          Logger.Log("Sending Create New Order Message", LogCategory.Info);
          var createNewOrderMessage = new OrderMessage(newOrderViewModel);
          _eventAggregator.GetEvent&lt;CreateOrderEvent&gt;().Publish(createNewOrderMessage);
      }
  </code></pre>
  
  <p>How would I go about Mocking the ILoggerService so that a valid Logger is returned? At the moment my Unit test throws a NullReferenceExeception.</p>
  
  <p>I'm using Moq to do my mocking.</p>
  
  <p>I'm imagining I need to do something along the lines of</p>
  
  <pre><code>var loggerService = new Mock&lt;ILoggerService&gt;();
          loggerService.Setup(svc =&gt; svc.GetLog(??))
  </code></pre>
  
  <p>But I can't see how without making my test class implement ILoggable.</p>
  
  <p>Thanks in advance.</p>