ConfigurationManager Wrapper for Unit Testing

Ever needed to unit test .NETs System.Configuration.ConfigurationManager class? I had to today so produced a wrapper class and interface to make the task a bit easier.

using System.Configuration;

namespace Chris.Blog
{
	public interface IConfigurationManager
	{
		/// <summary>
		/// Gets the System.Configuration.AppSettingsSection data for the current application's default configuration.
		/// </summary>
		/// <returns>Returns a System.Collections.Specialized.NameValueCollection object that contains the contents of the System.Configuration.AppSettingsSection object for the current application's default configuration.</returns>
		/// <exception cref="System.Configuration.ConfigurationErrorsException">A configuration file could not be loaded.</exception>
		System.Collections.Specialized.NameValueCollection AppSettings { get; }

		/// <summary>
		/// Gets the System.Configuration.ConnectionStringsSection data for the current application's default configuration.
		/// </summary>
		/// <returns>Returns a System.Configuration.ConnectionStringSettingsCollection object that contains the contents of the System.Configuration.ConnectionStringsSection object for the current application's default configuration.</returns>
		/// <exception cref="System.Configuration.ConfigurationErrorsException">A configuration file could not be loaded.</exception>
		ConnectionStringSettingsCollection ConnectionStrings { get; }

		/// <summary>
		/// Retrieves a specified configuration section for the current application's default configuration.
		/// </summary>
		/// <param name="sectionName">The configuration section path and name.</param>
		/// <returns>The specified System.Configuration.ConfigurationSection object, or null if the section does not exist.</returns>
		/// <exception cref="System.Configuration.ConfigurationErrorsException">A configuration file could not be loaded.</exception>
		object GetSection(string sectionName);

		/// <summary>
		/// Retrieves a specified configuration section for the current application's default configuration.
		/// </summary>
		/// <typeparam name="T">The type to cast the return value to.</typeparam>
		/// <param name="sectionName">The configuration section path and name.</param>
		/// <returns>The specified System.Configuration.ConfigurationSection object, or null if the section does not exist.</returns>
		/// <exception cref="System.Configuration.ConfigurationErrorsException">A configuration file could not be loaded.</exception>
		/// <exception cref="System.InvalidCastException">The section could not be cast to an object of type <typeparamref name="T"/>.</exception>
		T GetSection<T>(string sectionName);

		/// <summary>
		/// Opens the configuration file for the current application as a System.Configuration.Configuration object.
		/// </summary>
		/// <param name="userLevel">The System.Configuration.ConfigurationUserLevel for which you are opening the configuration.</param>
		/// <returns>A System.Configuration.Configuration object.</returns>
		/// <exception cref="System.Configuration.ConfigurationErrorsException">A configuration file could not be loaded.</exception>
		Configuration OpenExeConfiguration(ConfigurationUserLevel userLevel);

		/// <summary>
		/// Opens the specified client configuration file as a System.Configuration.Configuration object.
		/// </summary>
		/// <param name="exePath">The path of the configuration file. The configuration file resides in the same directory as the executable file.</param>
		/// <returns>A System.Configuration.Configuration object.</returns>
		/// <exception cref="System.Configuration.ConfigurationErrorsException">A configuration file could not be loaded.</exception>
		Configuration OpenExeConfiguration(string exePath);

		/// <summary>
		/// Opens the machine configuration file on the current computer as a System.Configuration.Configuration object.
		/// </summary>
		/// <returns>A System.Configuration.Configuration object.</returns>
		/// <exception cref="System.Configuration.ConfigurationErrorsException">A configuration file could not be loaded.</exception>
		Configuration OpenMachineConfiguration();

		/// <summary>
		/// Opens the specified client configuration file as a System.Configuration.Configuration object that uses the specified file mapping and user level.
		/// </summary>
		/// <param name="fileMap">An System.Configuration.ExeConfigurationFileMap object that references configuration file to use instead of the application default configuration file.</param>
		/// <param name="userLevel">The System.Configuration.ConfigurationUserLevel object for which you are opening the configuration.</param>
		/// <returns>A System.Configuration.Configuration object.</returns>
		/// <exception cref="System.Configuration.ConfigurationErrorsException">A configuration file could not be loaded.</exception>
		Configuration OpenMappedExeConfiguration(ExeConfigurationFileMap fileMap, ConfigurationUserLevel userLevel);

		/// <summary>
		/// Opens the machine configuration file as a System.Configuration.Configuration object that uses the specified file mapping.
		/// </summary>
		/// <param name="fileMap">An System.Configuration.ExeConfigurationFileMap object that references configuration file to use instead of the application default configuration file.</param>
		/// <returns>A System.Configuration.Configuration object.</returns>
		/// <exception cref="System.Configuration.ConfigurationErrorsException">A configuration file could not be loaded.</exception>
		Configuration OpenMappedMachineConfiguration(ConfigurationFileMap fileMap);

		/// <summary>
		/// Refreshes the named section so the next time that it is retrieved it will be re-read from disk.
		/// </summary>
		/// <param name="sectionName">The configuration section name or the configuration path and section name of the section to refresh.</param>
		void RefreshSection(string sectionName);
	}
}

using System.Configuration;

namespace Chris.Blog
{
	public class ConfigurationManagerWrapper : IConfigurationManager
	{
		/// <summary>
		/// Retrieves a specified configuration section for the current application's default configuration.
		/// </summary>
		/// <param name="sectionName">The configuration section path and name.</param>
		/// <returns>The specified System.Configuration.ConfigurationSection object, or null if the section does not exist.</returns>
		/// <exception cref="System.Configuration.ConfigurationErrorsException">A configuration file could not be loaded.</exception>
		public object GetSection(string sectionName)
		{
			return ConfigurationManager.GetSection(sectionName);
		}
		
		/// <summary>
		/// Retrieves a specified configuration section for the current application's default configuration.
		/// </summary>
		/// <typeparam name="T">The type to cast the return value to.</typeparam>
		/// <param name="sectionName">The configuration section path and name.</param>
		/// <returns>The specified System.Configuration.ConfigurationSection object, or null if the section does not exist.</returns>
		/// <exception cref="System.Configuration.ConfigurationErrorsException">A configuration file could not be loaded.</exception>
		/// <exception cref="System.InvalidCastException">The section could not be cast to an object of type <typeparamref name="T"/>.</exception>
		public T GetSection<T>(string sectionName)
		{
			return (T)ConfigurationManager.GetSection(sectionName);
		}

		/// <summary>
		/// Opens the specified client configuration file as a System.Configuration.Configuration object.
		/// </summary>
		/// <param name="exePath">The path of the configuration file. The configuration file resides in the same directory as the executable file.</param>
		/// <returns>A System.Configuration.Configuration object.</returns>
		/// <exception cref="System.Configuration.ConfigurationErrorsException">A configuration file could not be loaded.</exception>
		public Configuration OpenExeConfiguration(string exePath)
		{
			return ConfigurationManager.OpenExeConfiguration(exePath);
		}

		/// <summary>
		/// Opens the configuration file for the current application as a System.Configuration.Configuration object.
		/// </summary>
		/// <param name="userLevel">The System.Configuration.ConfigurationUserLevel for which you are opening the configuration.</param>
		/// <returns>A System.Configuration.Configuration object.</returns>
		/// <exception cref="System.Configuration.ConfigurationErrorsException">A configuration file could not be loaded.</exception>
		public Configuration OpenExeConfiguration(ConfigurationUserLevel userLevel)
		{
			return ConfigurationManager.OpenExeConfiguration(userLevel);
		}

		/// <summary>
		/// Opens the machine configuration file on the current computer as a System.Configuration.Configuration object.
		/// </summary>
		/// <returns>A System.Configuration.Configuration object.</returns>
		/// <exception cref="System.Configuration.ConfigurationErrorsException">A configuration file could not be loaded.</exception>
		public Configuration OpenMachineConfiguration()
		{
			return ConfigurationManager.OpenMachineConfiguration();
		}

		/// <summary>
		/// Opens the specified client configuration file as a System.Configuration.Configuration object that uses the specified file mapping and user level.
		/// </summary>
		/// <param name="fileMap">An System.Configuration.ExeConfigurationFileMap object that references configuration file to use instead of the application default configuration file.</param>
		/// <param name="userLevel">The System.Configuration.ConfigurationUserLevel object for which you are opening the configuration.</param>
		/// <returns>A System.Configuration.Configuration object.</returns>
		/// <exception cref="System.Configuration.ConfigurationErrorsException">A configuration file could not be loaded.</exception>
		public Configuration OpenMappedExeConfiguration(ExeConfigurationFileMap fileMap, ConfigurationUserLevel userLevel)
		{
			return ConfigurationManager.OpenMappedExeConfiguration(fileMap, userLevel);
		}

		/// <summary>
		/// Opens the machine configuration file as a System.Configuration.Configuration object that uses the specified file mapping.
		/// </summary>
		/// <param name="fileMap">An System.Configuration.ExeConfigurationFileMap object that references configuration file to use instead of the application default configuration file.</param>
		/// <returns>A System.Configuration.Configuration object.</returns>
		/// <exception cref="System.Configuration.ConfigurationErrorsException">A configuration file could not be loaded.</exception>
		public Configuration OpenMappedMachineConfiguration(ConfigurationFileMap fileMap)
		{
			return ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
		}

		/// <summary>
		/// Refreshes the named section so the next time that it is retrieved it will be re-read from disk.
		/// </summary>
		/// <param name="sectionName">The configuration section name or the configuration path and section name of the section to refresh.</param>
		public void RefreshSection(string sectionName)
		{
			ConfigurationManager.RefreshSection(sectionName);
		}

		/// <summary>
		/// Gets the System.Configuration.AppSettingsSection data for the current application's default configuration.
		/// </summary>
		/// <returns>Returns a System.Collections.Specialized.NameValueCollection object that contains the contents of the System.Configuration.AppSettingsSection object for the current application's default configuration.</returns>
		/// <exception cref="System.Configuration.ConfigurationErrorsException">A configuration file could not be loaded.</exception>
		public System.Collections.Specialized.NameValueCollection AppSettings
		{
			get
			{
				return ConfigurationManager.AppSettings;
			}
		}

		/// <summary>
		/// Gets the System.Configuration.ConnectionStringsSection data for the current application's default configuration.
		/// </summary>
		/// <returns>Returns a System.Configuration.ConnectionStringSettingsCollection object that contains the contents of the System.Configuration.ConnectionStringsSection object for the current application's default configuration.</returns>
		/// <exception cref="System.Configuration.ConfigurationErrorsException">A configuration file could not be loaded.</exception>
		public ConnectionStringSettingsCollection ConnectionStrings
		{
			get
			{
				return ConfigurationManager.ConnectionStrings;
			}
		}
	}
}