E
Eric
I'm trying to manipulae my app.config file. Below is code to test that I can
remove a ConfigurationSection. It looks like its working, but the app.config
file is not changed when I look at it after.
I think it has something to do with the file path; the .FilePath returned
<C:\Projects\MyProject\src\Core.Tests\bin\Debug\MyProject.Core.Tests.dll.temp.config>
isn't app.config but I've seen a couple of places that say that
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); is
how you get hold of it.
Thanks for helping - Eric
CODE
------
[Test]
public void RemoveASection() {
var config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var groups = config.Sections;
Console.WriteLine(config.FilePath);
if
(config.Sections[DomainObjectMappingConstants.ConfigurationSectionName] !=
null) {
var section =
config.Sections[DomainObjectMappingConstants.ConfigurationSectionName] ;
Assert.That(section.SectionInformation.Name,
Is.EqualTo(DomainObjectMappingConstants.ConfigurationSectionName));
groups.Remove(section.SectionInformation.Name);
config.Save(ConfigurationSaveMode.Full);
Assert.That(config.Sections[DomainObjectMappingConstants.ConfigurationSectionName]
== null);
}
}
APP.CONFIG
remove a ConfigurationSection. It looks like its working, but the app.config
file is not changed when I look at it after.
I think it has something to do with the file path; the .FilePath returned
<C:\Projects\MyProject\src\Core.Tests\bin\Debug\MyProject.Core.Tests.dll.temp.config>
isn't app.config but I've seen a couple of places that say that
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); is
how you get hold of it.
Thanks for helping - Eric
CODE
------
[Test]
public void RemoveASection() {
var config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var groups = config.Sections;
Console.WriteLine(config.FilePath);
if
(config.Sections[DomainObjectMappingConstants.ConfigurationSectionName] !=
null) {
var section =
config.Sections[DomainObjectMappingConstants.ConfigurationSectionName] ;
Assert.That(section.SectionInformation.Name,
Is.EqualTo(DomainObjectMappingConstants.ConfigurationSectionName));
groups.Remove(section.SectionInformation.Name);
config.Save(ConfigurationSaveMode.Full);
Assert.That(config.Sections[DomainObjectMappingConstants.ConfigurationSectionName]
== null);
}
}
APP.CONFIG