title: Application.Current is Null for Unit Tests
body: <p>I have some methods in the code base that rely on Application.Current.Dispatcher.Invoke... to make sure things run on the GUI thread. I am currently trying to write unit tests for these methods but (as expected) Application.Current is null so I'm getting a NullReferenceException.  </p>
  
  <p>I tried to run the affected tests in their own AppDomain as suggested here: <a href="http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/786d5c06-0511-41c0-a6a2-5c4e44f8ffb6/" rel="noreferrer">http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/786d5c06-0511-41c0-a6a2-5c4e44f8ffb6/</a></p>
  
  <p>But Application.Current is still null when I do that. Shouldn't starting up an AppDomain set the Application.Current for me? Why is it still null?</p>
  
  <p>My code:
  The base class:</p>
  
  <pre><code>[TestClass()]
  [Serializable]
  public class UnitTest
  {
      protected void ExecuteInSeparateAppDomain(string methodName)
      {
          AppDomainSetup appDomainSetup = new AppDomainSetup();
          appDomainSetup.ApplicationBase = Environment.CurrentDirectory;
          AppDomain appDomain = AppDomain.CreateDomain(methodName, null, appDomainSetup);
  
          try
          {
              appDomain.UnhandledException += delegate(object sender, UnhandledExceptionEventArgs e)
              {
                  throw e.ExceptionObject as Exception;
              };
  
              UnitTest unitTest = appDomain.CreateInstanceAndUnwrap(GetType().Assembly.GetName().Name, GetType().FullName) as UnitTest;
  
              MethodInfo methodInfo = unitTest.GetType().GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance);
  
              if (methodInfo == null)
              {
                  throw new InvalidOperationException(string.Format("Method '{0}' not found on type '{1}'.", methodName, unitTest.GetType().FullName));
              }
  
              try
              {
                  methodInfo.Invoke(unitTest, null);
              }
              catch (System.Reflection.TargetInvocationException e)
              {
                  throw e.InnerException;
              }
          }
          finally
          {
              AppDomain.Unload(appDomain);
          }
      }
  }
  </code></pre>
  
  <p>The calling unit test (contained in a class that inherits from UnitTest):</p>
  
  <pre><code>[TestMethod()]
  public void QualifierViewModel_FlagsAndLoadDatasets()
  {
      ExecuteInSeparateAppDomain("TestLoadDataSets");
  }
  </code></pre>