I have a class library that is using application settings to determine the behavior of a particular method.
I realize that the argument could be made that this is a Bad Thing, but we know that the behavior of the site is going to change about a week after launch (no real definitive time), and it will be easiest to just c开发者_JS百科hange the setting in the config file to change the behavior of the site.
Anyways, on to my question... I would like to be able to test a method who's behavior changes based on the true/false value of an applicationSetting. How do I create a unit test to test the value that is not defined in the unit test's app.config? The setting is an Application setting, so it is read-only in the Settings.Default instance.
If you create a repository for the ApplicationSettings, you can substitute your test repository at runtime, and do whatever you want with the settings during test.
You test that the part of the system that changes behaves correctly when the values are passed to it. You the App_Start pull the values from the config file and push them to the specific part of the system, not have it pull the config values itself. That way your unit tests can actually test the behavior without mucking with the config file.
精彩评论