If I have code like this:
public XALServiceConfiguration CreateInstance()
{
var config = ConfigurationManager.GetSection(ConfigurationSectionName) as XALServiceConfiguration;
if (config == null)
throw new ConfigurationErrorsException("Configuration element 'xalService' was not found or is not of correct type.");
return config;
}
How can I test that the exception is thrown if the section is missing from the configuration file ? For other tests, the configuration section needs to be in the config file, so I cannot actually remove it from the file.
I am using the Visual Studio 2008 Unit test framework.