views:

69

answers:

3

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!

+1  A: 

Take a look here : http://stackoverflow.com/questions/168931/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".

Dave Swersky
+1  A: 

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
A: 

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
You should accept your own answer
scottschulthess