title: Unit Test event hub EventProcessor
body: <p>I am currently learning the Microsoft event hub and I followed the sample code <a href="https://code.msdn.microsoft.com/windowsapps/Service-Bus-Event-Hub-286fd097" rel="nofollow">here</a>. I changed the <code>ProcessEventsAsync(PartitionContext context, IEnumerable&lt;EventData&gt; events)</code> method so that now after I get the EventData, I store it to a database. For now, I want to use unit test to test my code. In the test class I set up a sender and send the data to the event hub in a initialize method, and that part works perfectly. Then I create a new test method to test the receiver side. The code looks like this:</p>
  
  <pre><code>[TestMethod]
  public void TestProcessEventsAsync()
  {
      //Initialize the receiver, and run it
      Receiver receiver = new Receiver();
      Receiver r = new Receiver(eventHubName, connectionString);
      r.MessageProcessingWithPartitionDistribution();
  
      //check if the data is stored in the database
      ...
  }
  </code></pre>
  
  <p>Here, I simply create a new instance of receiver and use it to process the data sent to the event hub. I only send three objectst to the event hub and two of them are using the same partition. The test failed and the output shows that not all partitions are initialized which means that the receiver is stopped before it has finished processing all the data.</p>
  
  <p>I am guessing that, since the <code>MessageProcessingWithPartitionDistribution()</code> method divided the task into multiple threads, the unit test doesn't work in this way. So my question is how can I test this <code>MessageProcessingWithPartitionDistribution()</code> method with unit test?</p>
  
  <p>Any help is appreciated!</p>