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 Settings.settings
file having application scope and suitable default values. When the library is used by the application these settings can be overriden in the App.Config
file. If not the default values are used. That's exactly how I want it to be.
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.
In my library class I access the settings like this:
var mySetting1 = Settings.Default.MySetting1;
var mySetting2 = Settings.Default.MySetting2;
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.