title: Unit testing, using Moq to verify the exception message
body: <p>So, I have this test I have setup. It looks like this:</p>
  
  <pre><code>[Test]
  public async Task LogErrorAndReturnSuccessIfNoLines()
  {
      // Assemble
      const string orderNumber = "00000000";
      const string lineNumber = "001";
      var model = new OCS { Request = new strOCS { OrderLineID = $"{orderNumber}/{lineNumber}" } }; // NB: 12 characters means carpet
      var services = WmsContext.GivenServices();
  
      services.MockConfig.Setup(x =&gt; x.Live).Returns(false);
      services.MockOrderProvider.Setup(x =&gt; x.GetAsync(orderNumber, null, "Lines.Delivery")).Returns(Task.FromResult(services.WhenGetOrder()));
  
      var wmsProvider = services.WhenCreateWmsProvider();
  
      // Act
      var response = await wmsProvider.ReceiveOrderCompletedAsync(model);
  
      // Assert
      response.Should().Be("success");
      services.MockLogProvider.Verify(x =&gt; x.LogExceptionAsync(new Exception("Order doesn't exist on ERP"), It.IsAny&lt;string&gt;(), It.IsAny&lt;string&gt;(), It.IsAny&lt;Dictionary&lt;string, string&gt;&gt;(), It.IsAny&lt;string&gt;(), It.IsAny&lt;string&gt;(), It.IsAny&lt;int&gt;()));
  }
  </code></pre>
  
  <p>This fails because of this line:</p>
  
  <pre><code>services.MockLogProvider.Verify(x =&gt; x.LogExceptionAsync(new Exception("Order doesn't exist on ERP"), It.IsAny&lt;string&gt;(), It.IsAny&lt;string&gt;(), It.IsAny&lt;Dictionary&lt;string, string&gt;&gt;(), It.IsAny&lt;string&gt;(), It.IsAny&lt;string&gt;(), It.IsAny&lt;int&gt;()));
  </code></pre>
  
  <p>If I change it to this:</p>
  
  <pre><code>services.MockLogProvider.Verify(x =&gt; x.LogExceptionAsync(It.IsAny&lt;Exception&gt;(), It.IsAny&lt;string&gt;(), It.IsAny&lt;string&gt;(), It.IsAny&lt;Dictionary&lt;string, string&gt;&gt;(), It.IsAny&lt;string&gt;(), It.IsAny&lt;string&gt;(), It.IsAny&lt;int&gt;()));
  </code></pre>
  
  <p>It passes. But I want to make sure that the message sent is exactly <strong>Order doesn't exist on ERP</strong>.
  When it fails, it says this:</p>
  
  <blockquote>
    <p>Message: Moq.MockException : 
    Expected invocation on the mock at least once, but was never performed: x => x.LogExceptionAsync(System.Exception: Order doesn't exist on ERP, It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), It.IsAny())
    No setups configured.</p>
  </blockquote>
  
  <p>It also states that the performed invocations are:</p>
  
  <blockquote>
    <p>ILogProvider.LogTrace("OCS Received", ...</p>
  </blockquote>
  
  <p>and </p>
  
  <blockquote>
    <p>ILogProvider.LogExceptionAsync(System.Exception: Order doesn't exist on ERP, ...</p>
  </blockquote>
  
  <p>As you can see, the second one is the one I am after.
  Can anyone see what I am doing wrong?</p>
  
  <hr>
  
  <p>Here is my <strong>WmsContext</strong> so you can see how the Mocks are created:</p>
  
  <pre><code>public class WmsContext
  {
      public readonly Mock&lt;ICormarConfig&gt; MockConfig;
      public readonly Mock&lt;IComplaintsProvider&gt; MockComplaintsProvider;
      public readonly Mock&lt;IDistributionProvider&gt; MockDistributionProvider;
      public readonly Mock&lt;IListItemProvider&gt; MockListItemProvider;
      public readonly Mock&lt;ILogProvider&gt; MockLogProvider;
      public readonly Mock&lt;IMessageProvider&gt; MockMessageProvider;
      public readonly Mock&lt;IOrderLineProvider&gt; MockOrderLineProvider;
      public readonly Mock&lt;IOrderProvider&gt; MockOrderProvider;
      public readonly Mock&lt;IStockProvider&gt; MockStockProvider;
      public readonly Mock&lt;IProofOfDeliveryService&gt; MockProofOfDeliveryService;
  
      private readonly Lazy&lt;IComplaintsProvider&gt; _lazyComplaintsProvider;
      private readonly Lazy&lt;IDistributionProvider&gt; _lazyDistributionProvider;
      private readonly Lazy&lt;IListItemProvider&gt; _lazyListItemProvider;
      private readonly Lazy&lt;ILogProvider&gt; _lazyLogProvider;
      private readonly Lazy&lt;IMessageProvider&gt; _lazyMessageProvider;
      private readonly Lazy&lt;IOrderLineProvider&gt; _lazyOrderLineProvider;
      private readonly Lazy&lt;IOrderProvider&gt; _lazyOrderProvider;
      private readonly Lazy&lt;IStockProvider&gt; _lazyStockProvider;
      private readonly Lazy&lt;IProofOfDeliveryService&gt; _lazyProofOfDeliveryService;
  
      private WmsContext()
      {
          MockConfig = new Mock&lt;ICormarConfig&gt;();
          MockComplaintsProvider = new Mock&lt;IComplaintsProvider&gt;();
          MockDistributionProvider = new Mock&lt;IDistributionProvider&gt;();
          MockListItemProvider = new Mock&lt;IListItemProvider&gt;();
          MockLogProvider = new Mock&lt;ILogProvider&gt;();
          MockMessageProvider = new Mock&lt;IMessageProvider&gt;();
          MockOrderLineProvider = new Mock&lt;IOrderLineProvider&gt;();
          MockOrderProvider = new Mock&lt;IOrderProvider&gt;();
          MockStockProvider = new Mock&lt;IStockProvider&gt;();
          MockProofOfDeliveryService = new Mock&lt;IProofOfDeliveryService&gt;();
  
          _lazyComplaintsProvider = new Lazy&lt;IComplaintsProvider&gt;(() =&gt; MockComplaintsProvider.Object);
          _lazyDistributionProvider = new Lazy&lt;IDistributionProvider&gt;(() =&gt; MockDistributionProvider.Object);
          _lazyListItemProvider = new Lazy&lt;IListItemProvider&gt;(() =&gt; MockListItemProvider.Object);
          _lazyLogProvider = new Lazy&lt;ILogProvider&gt;(() =&gt; MockLogProvider.Object);
          _lazyMessageProvider = new Lazy&lt;IMessageProvider&gt;(() =&gt; MockMessageProvider.Object);
          _lazyOrderLineProvider = new Lazy&lt;IOrderLineProvider&gt;(() =&gt; MockOrderLineProvider.Object);
          _lazyOrderProvider = new Lazy&lt;IOrderProvider&gt;(() =&gt; MockOrderProvider.Object);
          _lazyStockProvider = new Lazy&lt;IStockProvider&gt;(() =&gt; MockStockProvider.Object);
          _lazyProofOfDeliveryService = new Lazy&lt;IProofOfDeliveryService&gt;(() =&gt; MockProofOfDeliveryService.Object);
      }
  
      public static WmsContext GivenServices() =&gt; new WmsContext();
  
      public IWmsProvider WhenCreateWmsProvider() =&gt;
          new WmsProvider(
              MockConfig.Object, 
              _lazyDistributionProvider, 
              _lazyLogProvider, 
              _lazyComplaintsProvider, 
              _lazyStockProvider, 
              _lazyProofOfDeliveryService, 
              _lazyMessageProvider, 
              _lazyOrderProvider, 
              _lazyOrderLineProvider, 
              _lazyListItemProvider
              );
  
      public OrderViewModel WhenGetOrder(params string[] lineNumbers)
      {
          var lines = lineNumbers.Select(lineNumber =&gt; new OrderLineViewModel {Id = lineNumber}).ToList();
  
          return new OrderViewModel
          {
              Lines = lines
          };
      }
  }
  </code></pre>