title: Async does not continue on same thread in unit test
body: <p>Given the following code:</p>
  
  <pre><code>public static async void CurrentThreadCall()
  {
      Console.WriteLine("Begin on thread {0}", Thread.CurrentThread.ManagedThreadId);
      await BackgroundCall();
      Console.WriteLine("Completed on thread {0}", Thread.CurrentThread.ManagedThreadId);
  }
  
  private static async Task BackgroundCall()
  {
      await Task
          .Run(() =&gt;
              {
                  Console.WriteLine("Task run on thread: {0}", Thread.CurrentThread.ManagedThreadId);
                  Thread.Sleep(TimeSpan.FromMilliseconds(100));
              })
          .ConfigureAwait(false);
  }
  </code></pre>
  
  <p>Calling the <code>CurrentThreadCall()</code> method from a WPF application, the Begin and Completed outputs will run on the same threads (just as I would expect):</p>
  
  <pre><code>BackgroundCall begin: 9
  Task run on thread: 6
  Completed on thread 9   &lt;--- As expected
  </code></pre>
  
  <p>If I call the method from a unit test and use the ReSharper testrunner (2016.2 in VS2015), the Completed output will instead run on the same thread as the task:</p>
  
  <pre><code>Begin on thread 11
  Task run on thread: 4
  Completed on thread 4   &lt;-- Not what I expected
  </code></pre>
  
  <p>Why is this, and can I do something in my test to make it work like in the WPF application?</p>
  
  <p><strong>What I have tried...</strong></p>
  
  <p>I have tried to make the test method async:</p>
  
  <pre><code>[Test]
  public async Task MyTest()
  {
      await CurrentThreadCall();
  }
  </code></pre>
  
  <p>In desperation, I have tried to <a href="https://stackoverflow.com/a/8246053/617658">set the <code>SynchronizationContext</code></a> from the test:</p>
  
  <pre><code>[Test]
  public void MyTest()
  {
      SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
      CurrentThreadCall();
  }
  </code></pre>
  
  <p>...with no luck.</p>