title: Modifying application settings in unit tests
body: <p>I have a class library I want to unit test using Microsofts unit test framework. Some of the classes I want to test are configured using application settings. These settings are defined inside the <code>Settings.settings</code> file having application scope and suitable default values. When the library is used by the application these settings can be overriden in the <code>App.Config</code> file. If not the default values are used. That's exactly how I want it to be.</p>
  
  <p>In some of my test cases I want to test special combinations of setting values but I don't know how to change the values seen by the class under test from the unit test code. These settings will always have their default value loaded from the attributes of the code generated class.</p>
  
  <p>In my library class I access the settings like this:</p>
  
  <pre><code>var mySetting1 = Settings.Default.MySetting1;
  var mySetting2 = Settings.Default.MySetting2;
  </code></pre>
  
  <p>How do I modify these settings in an unit test before the setting is accessed by the class under test? Making the internal settings class accessible by the unit test does not solve the problem as the settings have application scope and are read-only properties on the settings class.</p>