larryq
larryq

Reputation: 16299

AppConfig in a VS 2008 test project?

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!

Upvotes: 0

Views: 369

Answers (3)

larryq
larryq

Reputation: 16299

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.

Upvotes: 0

joerage
joerage

Reputation: 4923

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);

Upvotes: 1

Dave Swersky
Dave Swersky

Reputation: 34810

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".

Upvotes: 1

Related Questions