M
Matt Adamson
Guys,
When writing unit tests for our assemblies we'd like to change configuration
values at runtime for some tests i.e. to test all code paths are executed.
e.g. one method would create a test with a value set to true and the next
test method would set it to false.
I can set the values in the config file easy enough using the following
approach
1) Get access to the app.config file full path from the process using
AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
2) Load the file into an XmlDocument
3) Extract the relevant node using code such as XmlNode node =
xmlDocument.SelectSingleNode(@"/configuration/appSettings/add[@key='" +
configurationName + "']");
4) Set the value of the "value" attribute using
node.Attributes.GetNamedItem("value").Value = configurationValue;
However is there any possible way to get the AppSettingsReader class to
reflect the changes at runtime. i.e. so you can execute code such as
AppSettingsReader appSettingsReader = new
System.Configuration.AppSettingsReader();
Boolean value = appSettingsReader.GetValue(key, typeof(Boolean));
and this would reflect the changes.
Any help appreciated
Cheers
Matt
When writing unit tests for our assemblies we'd like to change configuration
values at runtime for some tests i.e. to test all code paths are executed.
e.g. one method would create a test with a value set to true and the next
test method would set it to false.
I can set the values in the config file easy enough using the following
approach
1) Get access to the app.config file full path from the process using
AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
2) Load the file into an XmlDocument
3) Extract the relevant node using code such as XmlNode node =
xmlDocument.SelectSingleNode(@"/configuration/appSettings/add[@key='" +
configurationName + "']");
4) Set the value of the "value" attribute using
node.Attributes.GetNamedItem("value").Value = configurationValue;
However is there any possible way to get the AppSettingsReader class to
reflect the changes at runtime. i.e. so you can execute code such as
AppSettingsReader appSettingsReader = new
System.Configuration.AppSettingsReader();
Boolean value = appSettingsReader.GetValue(key, typeof(Boolean));
and this would reflect the changes.
Any help appreciated
Cheers
Matt