title: Wait until all Task finish in unit test
body: <p>I have this class I want to unit test:</p>
  
  <pre><code>public class SomeClass
  {
      public void Foo()
      {
          Bar();
      }
  
      private void Bar()
      {
          Task.Factory.StartNew(() =&gt;
          {
              // Do something that takes some time (e.g. an HTTP request)
          });
      }
  }
  </code></pre>
  
  <p>And this is how my unit test looks like:</p>
  
  <pre><code>[TestMethod]
  public void TestFoo()
  {
      // Arrange
      var obj = new SomeClass();
  
      // Act
      obj.Foo();
      obj.Foo();
      obj.Foo();
  
      // Assert
      /* I need something to wait on all tasks to finish */
      Assert.IsTrue(...);
  }
  </code></pre>
  
  <p>So, I need to make the unit test thread wait until all tasks started in the <code>Bar</code> method have finished their job before starting my assertions.</p>
  
  <p><strong>IMPORTANT</strong>: I cannot change <code>SomeClass</code></p>
  
  <p><strong>How can I do that?</strong></p>