Use the Facade Pattern (
http://www.dofactory.com/Patterns/PatternFacade.aspx) to wrap the ConfigurationManager in an interface that you can then mock and set proper expectations upon.
public interface IManageConfigSettings
{
CultureConstant GetCulture();
}
public class MyAppsConfigManager : IManageConfigSettings
{
public CultureConstant GetCulture()
{
return ConfigurationManager.AppSettings[Constants.CultureToUse];
}
}
In your tests, inject a mocked IManageConfigSettings and set your expectation on it.
In general, you should do this anyway (Facade Pattern around annoying bits of the Framework) as an overall design strategy for your application so that you don't take a concrete dependency on the ConfigurationManager class in 100s of places throughout your code. As an example, what would happen if you later decide to store current culture settings per user in a database somewhere? You want to be able to update *only* the MyAppConfigManager class' GetCulture() method in one place rather than having to reach all over your application to change calls to ConfigurationManager.AppSettings[Constants.CultureToUse] everywhere :)
Best of luck,
Steve Bohlen
sbo...@gmail.comhttp://blog.unhandled-exceptions.comhttp://twitter.com/sbohlen