title: Consumer not getting called when unit testing MassTransit
body: <p>I'm trying to write unit tests using MassTransit. When looking online, I found the best way to access the Bus would be creating it using an <code>InMemoryTestHarness</code>. I add my consumers and a <code>PublishObserver</code> to get the resulting behavior.</p>
  
  <p>In the example below, I send a <code>TestRequest</code> message to the bus, then my consumer reads the request and puts a <code>TestResponse</code> message back on the bus. Finally, an observer gets the response.</p>
  
  <p>I don't know if the problem is with some configuration I'm missing, or if there is some task I'm not waiting, but the request message never even arrives at the consumer. </p>
  
  <p>What am I missing?</p>
  
  <p>The test</p>
  
  <pre><code>[TestMethod]
  public void RequestResponseBusTest()
  {
      var harness = new InMemoryTestHarness();
  
      var consumer = new TestConsumer();
      harness.OnConfigureInMemoryBus += c =&gt;
      {
          c.ReceiveEndpoint("testqueue", e =&gt;
              e.Consumer(() =&gt; consumer));
      };
  
      var observer = new TestPublishObserver();
      harness.OnConnectObservers += c =&gt;
      {
          c.ConnectPublishObserver(observer);
      };
  
      harness.Start().Wait();
      var bus = harness.Bus;
  
      bus.Publish(new TestRequest() { X = 99 }).Wait();
  
      Assert.AreEqual(1, consumer.ConsumedMessages.Count, "consumed");
      Assert.AreEqual(1, observer.PublishedRequests.Count, "requests");
      Assert.AreEqual(1, observer.PublishedResponses.Count, "responses");
  
  }
  </code></pre>
  
  <p>And supporting classes</p>
  
  <pre><code>[Serializable]
  public class TestRequest
  {
      public int X { get; set; }
  }
  
  [Serializable]
  public class TestResponse
  {
      public int Y { get; set; }
  }
  
  public class TestConsumer : IConsumer&lt;TestRequest&gt;
  {
      public List&lt;TestRequest&gt; ConsumedMessages { get; } = new List&lt;TestRequest&gt;();
  
      public Task Consume(ConsumeContext&lt;TestRequest&gt; context)
      {
          ConsumedMessages.Add(context.Message);
          context.Publish(new TestResponse() { Y = 123 }).Wait();
          return Task.CompletedTask;
      }
  }
  
  private class TestPublishObserver : IPublishObserver
  {
      public List&lt;TestRequest&gt; PublishedRequests { get; } = new List&lt;TestRequest&gt;();
      public List&lt;TestResponse&gt; PublishedResponses { get; } = new List&lt;TestResponse&gt;();
  
      public Task PrePublish&lt;T&gt;(PublishContext&lt;T&gt; context) where T : class
      {
          return Task.CompletedTask;
      }
  
      public Task PostPublish&lt;T&gt;(PublishContext&lt;T&gt; context) where T : class
      {
          var msg = context.Message;
  
          if (msg is TestRequest)
              PublishedRequests.Add((TestRequest)(object)msg);
  
          if (msg is TestResponse)
              PublishedResponses.Add((TestResponse)(object)msg);
  
          return Task.CompletedTask;
      }
  
      public Task PublishFault&lt;T&gt;(PublishContext&lt;T&gt; context, Exception exception) where T : class
      {
          return Task.CompletedTask;
      }
  }
  </code></pre>