I've just added my first test project to a VS 2008 solution. I have a component I'd like to use in a unit test; the component calls System.Configuration.ConfigurationSettings.GetConfig() to get a setting, and I'd like for that call to work in my test. Any ideas how I can do this? I don't see any app.config in the project, so I'm not sure if that's an option in this instance. Thanks!
Asked
Active
Viewed 363 times
3 Answers
1
Take a look here : Unit testing the app.config file with NUnit
I believe you can set up a config file to work with the test runner. Find its executable and use a post-build action to copy the application file to "[TestRunner.exe].config".

Community
- 1
- 1

Dave Swersky
- 34,502
- 9
- 78
- 118
1
You can mock that call. Using TypeMock, you would go like this:
var mockConfigurationManager = MockManager.Mock(typeof(ConfigurationManager));
var appSettings = new NameValueCollection { { "key", "value" } };
mockConfigurationManager.ExpectGetAlways("AppSettings", appSettings);

joerage
- 4,863
- 4
- 38
- 48
0
Thanks guys. Great info, but what I wound up putting an App.Config in the test project and adding the appropriate sections in it. Works good now.

larryq
- 15,713
- 38
- 121
- 190