title: Waiting for all the threads spawned by async method while unit Testing
body: <p>I am Unit Testing ViewModel in WPF application and there is a Delegate Command that calls a Method which further calls async method inside it . I have to wait for every Task to be finished before calling Assert statement. the Method called by the delegate command is like
   : </p>
  
  <pre><code>private void Methodcalled()
  {
      this.uiService.SetBusyState();
      UIExecuteHelper executeHelper = new UIExecuteHelper(ViewName.Window);
      executeHelper.ExecuteAsync(() =&gt;
          {
              // some stuff
               method1();
           }
  }
  </code></pre>
  
  <p>Now I am waiting for the method in the following way in my unit test:</p>
  
  <pre><code>try
  {
      var task = Task.Factory.StartNew(() =&gt;
          {
              classobj.DelegateCommand.Execute();
          });
      var afterTask = task.ContinueWith((myobject)=&gt;
          {
              classobj.Load();
              Assert.AreEqual(true, someflag);
          }, TaskContinuationOptions.OnlyOnRanToCompletion);
  
  }
  </code></pre>
  
  <p>But it is still not waiting for all the inner tasks spawned to be finished. Please suggest </p>