title: Unit Testing Synchronous Method With Code Calling Task
body: <p>Given the following class:</p>
  
  <pre><code>public class TestAttribute : ActionFilterAttribute
  {
      public bool SomeExampleBool = false;
  
      public override void OnActionExecuting(HttpActionContext actionContext)
      {
          Task.Factory.StartNew(() =&gt; { SomeExampleBool = true; });
      }
  }
  </code></pre>
  
  <p>How would you write a valid unit test for <code>OnActionExecuting</code> that Asserts that <code>SomeExampleBool</code> is equal to <code>true</code>?</p>
  
  <p>When writing a unit test and calling <code>OnActionExecuting</code>, then calling the Assert, the logic executes on a thread that will not have executed yet.  So the Assert fails.  Would you try something like <code>Thread.Sleep</code> for a couple of seconds?  Seems like a hack.  I'm sure there is a better way that I'm not thinking of but I'm reaching out to the community for some help.</p>