I have a custom configuration section, and i'm constructing some unit tests for it. I'd like to be able to specify, somehow, different .config files programatically to test. Is there a way to do this?
-
what would be different within the different config files.. could you possibly add differect sections to the existing config file..? what do you have so far..?MethodMan– MethodMan2011-12-15 18:08:28 +00:00Commented Dec 15, 2011 at 18:08
-
Possible duplicate of stackoverflow.com/questions/360024/…Jed– Jed2011-12-15 18:09:04 +00:00Commented Dec 15, 2011 at 18:09
-
1Possible dup stackoverflow.com/q/4738/706456oleksii– oleksii2011-12-15 18:12:36 +00:00Commented Dec 15, 2011 at 18:12
-
@DJKRAZE -I have a custom configuration collection. I want to test that certain supplied config values throw an exception if they are invalid. However, this test will have the side-effect of breaking my other unit tests. The solution, in my mind, is to have a separate config file where I can supply invalid entries without breaking my other testsDidaxis– Didaxis2011-12-15 18:33:43 +00:00Commented Dec 15, 2011 at 18:33
-
1@oleksii -I think the solution in that question will do the trick. Thank you!Didaxis– Didaxis2011-12-15 18:34:22 +00:00Commented Dec 15, 2011 at 18:34
Add a comment
|
1 Answer
I don't know what exactly your unit tests look like. If you have an app.config file in your unit test project where your custom configuration resides, a possible solution would be to open the configuration in a writeable mode and change the config values to your need. After the unit test, restore the old config values.
Use
ConfigurationManager.OpenExeConfiguration(...)
See also msdn
If you are looking for a unit testable configuration solutions try out DslConfig