title: Unit Testing WPF Application with siteoforigin pack Uri
body: <p>I have some unit tests that I'm writing for a WPF application, and as much as I've tried to avoid it, I have some code under test that instantiates a View. As soon as the view is instantiated, all the markup extensions, styles, etc are evaluated. To resolve this I've created a dummy <em>Application</em> and registered any required resources when the test assembly is initialized:</p>
  
  <pre><code>[TestClass]
  public class AssemblyInitialize
  {
      [AssemblyInitialize]
      public static void SetupTestAssembly(TestContext context)
      {
          if (Application.Current == null)
              new Application();
  
          var resources = new List&lt;string&gt;
              {
                "pack://application:,,,/AssemblyName;component/ResourceDictionary.xaml"
              };
  
         foreach(var resource in resources)
         {
             var uri = new Uri(resource);
             var dictionary = new ResourceDictionary { Source = uri };
             Application.Current.Resources.MergedDictionaries.Add(dictionary);
         }
      }
  }
  </code></pre>
  
  <p>I've used this approach in the past, and it works ok.</p>
  
  <p>I've run into a small snag with this approach. I have a few resources that use <em>pack://siteoforigin:</em> in the pack Uri, and when the tests instantiate this view I get an error about not being able to resolve the file.</p>
  
  <p><strong>The XAML:</strong></p>
  
  <pre><code>&lt;ResourceDictionary
     xmlns="..."&gt;
  
     &lt;ImageBrush 
        x:Key="ResourceName"
        ImageSource="pack://siteoforigin:,,,/Resources/image.png" 
        /&gt;
  &lt;/ResourceDictionary&gt;
  </code></pre>
  
  <p><strong>Error Message:</strong></p>
  
  <pre><code> Could not find a part of the path 'C:\\Solution\\TestResults\\Workspace_2012-03-01 14_54_29\\Resources\\image.png'
  </code></pre>
  
  <p>I've added the Resources directory as a deployment item, and I've confirmed that the image is the TestRun output directory. It seems that the AppDomain is operating one folder above where the location of my test assemblies, because the file is actually located at:</p>
  
  <p>c:\Solution\TestResults\Workspace_2012-03-01 14_54_29\ <strong>Out</strong> \Resources\image.png</p>
  
  <p>Any suggestions on how I can get the WPF Application to use the Out directory as it's primary folder?</p>