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 s开发者_运维技巧ee any app.config in the project, so I'm not sure if that's an option in this instance. Thanks!
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".
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);
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.
精彩评论