title: Access App.Config Settings from Class Library Called through Unit Test Project
body: <p>I have the following setup:</p>
  
  <ul>
  <li>ASP.net 3.5 Web Site Project</li>
  <li>C# Class Library with business logic</li>
  <li>C# Class Library for unit testing</li>
  </ul>
  
  <p>The business logic library does all of the db access. It gets connection strings from the web.config file of the web site by accessing System.Configuration.ConfigurationManager.ConnectionStrings. When the library is called by the web site, this works fine, as the library looks for the config of the caller.</p>
  
  <p>I want to be able to test my business logic through the unit testing class library. I have put an App.config file in the root of the testing class library. From what I read, when the testing library calls data access procedures that are part of the business logic library, the connection settings from the App.config file of the testing library should be accessed and used. However, when I try to run my unit tests, I am getting errors back that indicate that the testing library's App.config file (and/or its contents) is not being accessed successfully.</p>
  
  <p>My retrieval of the config properties (from within the business logic library) looks like this:</p>
  
  <pre><code>public SqlConnection MainConnection {
    get {
      string conn = "";
      try {
        conn = System.Configuration.ConfigurationManager.ConnectionStrings["connString"].ConnectionString;
      } catch {
        // might be calling from test project. Need to reference app settings
        conn = System.Configuration.ConfigurationManager.AppSettings["connString"];
      }
      return new SqlConnection(conn);
    }
  }
  </code></pre>
  
  <p>When this is called from the website project, it works. From within the unit test, the conn variable is never set to anything (I have also tried System.Configuration.ConfigurationSettings.AppSettings, and using  instead of  with the same result). What do I need to do to make the business logic class library successfully retrieve the unit test class libraries settings, when called from within the NUnit GUI?</p>