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?
Asked
Active
Viewed 1,214 times
0
-
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 Dec 15 '11 at 18:08
-
Possible duplicate of http://stackoverflow.com/questions/360024/how-do-i-set-a-connection-string-config-programatically-in-net – Jed Dec 15 '11 at 18:09
-
1Possible dup http://stackoverflow.com/q/4738/706456 – oleksii Dec 15 '11 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 tests – Didaxis Dec 15 '11 at 18:33
-
1@oleksii -I think the solution in that question will do the trick. Thank you! – Didaxis Dec 15 '11 at 18:34
1 Answers
1
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

Johannes
- 77
- 1