title: Multi threading unit test
body: <p>I have a C# method that will be called multiple times using different threads.
  So I want to create a unit test that will test this method on several threads, but I'm not sure I'm doing it right.</p>
  
  <p>This is my unit test without threading:</p>
  
  <pre><code>    [TestMethod]
      public void FromLocalPoints()
      {
          var projectedCoordinates = this.ConvertFromLocalPoints();
          foreach (var projectedCoordinate in projectedCoordinates)
          {
              Debug.Write(projectedCoordinate.X);
              Debug.Write("; ");
              Debug.WriteLine(projectedCoordinate.Y);
          }
      }
  </code></pre>
  
  <p>this.ConvertFromLocalPoints() is calling the actual method I want to test.</p>
  
  <p>I've created a delegate, an event and an handler:</p>
  
  <pre><code>public delegate void ReprojectCompleteHandler(IEnumerable&lt;Coordinate&gt; projectedCoordinates);
  public event ReprojectCompleteHandler ReprojectCompleteEvent;
  private void ReprojectHandler(IEnumerable&lt;Coordinate&gt; projectedCoordinates)
  {
          Debug.WriteLine("Conversion is complete");
  }
  </code></pre>
  
  <p>In my TestSetup I listen to my event:</p>
  
  <pre><code>    [TestInitialize]
      public void TestSetup()
      {
          this.ReprojectCompleteEvent += this.ReprojectHandler;
      }
  </code></pre>
  
  <p>My unit test is:</p>
  
  <pre><code>    [TestMethod]
      public void FromLocalPointsThreaded()
      {
          // Call FromLocalPoints multiple times in separate threads to check if it is thread safe
          for (var i = 0; i &lt; 10; i++)
          {
              var myThread = new Thread(this.ConvertFromLocalPointsThreaded);    
          }
  
          Debug.WriteLine("FromLocalPointsThreaded is done");
      }
  
      private void ConvertFromLocalPointsThreaded()
      {
          var projectedCoordinates = this.ConvertFromLocalPoints();
  
          // Send result to delegate/event:
          if (this.ReprojectCompleteEvent != null)
          {
              this.ReprojectCompleteEvent(projectedCoordinates);
          }
      }
  </code></pre>
  
  <p>When I run this unit test I get once 'FromLocalPointsThreaded is done' in my output but no 'Conversion is complete'.</p>
  
  <p>What am I missing to get this working? Or should I use a different approach?</p>
  
  <p><strong>Update</strong>
  We're currently switching libraries which is doing the actual conversion. The old library isn't thread-safe so we added locks. The new library should be thread-safe so I want to remove the locks. But I need a unit test which will prove our method using the new lib is really thread-safe.</p>