title: Unit testing for a publish method in mass transit using in memory bus
body: <p>I am new to MassTransit and messaging. I am trying to write a unit test for a <code>IBus.Publish</code> and am not able to succeed with the result.</p>
  
  <p>I am observing the fault from RabbitMQ and my observer looks like this:</p>
  
  <pre><code>public class FaultObserver : IReceiveObserver
  {
      public FaultObserver(IRequestUpdater statusUpdater,Lazy&lt;IBus&gt; bus)
      {
          this.statusUpdater = statusUpdater;
          this.bus = bus;
      }
  
      public async Task ConsumeFault&lt;T&gt;(ConsumeContext&lt;T&gt; context, TimeSpan                                    duration, string consumerType, Exception exception) where T : class
      {
      }
   }
  </code></pre>
  
  <p>and my tests looks like the below code</p>
  
  <pre><code>var bus = fixture.Freeze&lt;Mock&lt;IBus&gt;&gt;();
  
  bus.Setup(bu =&gt; bu.Publish&lt;ReportFailedEvent&gt;(It.IsAny&lt;ReportFailedEvent&gt;(),It.IsAny&lt;CancellationToken&gt;())).Verifiable();
  
  var sut = fixture.Create&lt;ReportRequestedFaultObserver&gt;();
  // Act
  await sut.ConsumeFault(context.Object,new TimeSpan(0,0,1),string.Empty,exception);
  
  // Assert
  //bus.Verify(b =&gt; b.Publish&lt;ReportFailedEvent&gt;(It.IsAny&lt;ReportFailedEvent&gt;(), It.IsAny&lt;CancellationToken&gt;()), Times.Exactly(1));
  bus.Verify(b =&gt;b.Publish&lt;ReportFailedEvent&gt;(new ReportFailedEvent(request,exception.Message),It.IsAny&lt;CancellationToken&gt;()),Times.Once());
  </code></pre>
  
  <p>my setup looks like </p>
  
  <pre><code>[SetUp]
  public void SetUp()
  {
      fixture.Customize(new AutoMoqCustomization());
      var inMemoryTransportCache = new InMemoryTransportCache(Environment.ProcessorCount);
  
      bus = Bus.Factory.CreateUsingInMemory(configure =&gt;
      {
          configure.SetTransportProvider(inMemoryTransportCache);
          configure.ReceiveEndpoint("input_queue", configurator =&gt; 
          { 
              configurator.Handler&lt;(cc =&gt; 
              {
              });
          }); 
  
      });
  
      bus.Start().Ready.Wait();
  }
  </code></pre>
  
  <p>I am not able to mock my <code>Publish</code> method. Does anyone knows what I am doing wrong?</p>