public void ReadMultipleTest() { Delete(); var configFile = new ConfigFile <Configuration>(FilePath); var one = new TestConfigSection() { Value = 1 }; var two = new AnotherConfigSection() { Number = 2 }; var three = new AThirdSection() { Int = 3 }; configFile.Write(one, two, three); var read = configFile.Read <TestConfigSection, AnotherConfigSection>(); Assert.AreEqual(1, read.Find <TestConfigSection>().Value); Assert.AreEqual(2, read.Find <AnotherConfigSection>().Number); read = configFile.Read <TestConfigSection, AnotherConfigSection, AThirdSection>(); Assert.AreEqual(1, read.Find <TestConfigSection>().Value); Assert.AreEqual(2, read.Find <AnotherConfigSection>().Number); Assert.AreEqual(3, read.Find <AThirdSection>().Int); }
public void WriteSectionTest() { Delete(); var configFile = new ConfigFile <Configuration>(FilePath); var input = new TestConfigSection(); configFile.Write(input); }
public void WriteReadSectionTest() { Delete(); var configFile = new ConfigFile <Configuration>(FilePath); var input = new TestConfigSection { Value = 12 }; configFile.Write(input); var output = configFile.Read <TestConfigSection>(); Assert.AreEqual(input.Value, output.Value); }
public void DeleteSectionTest() { Delete(); var configFile = new ConfigFile <Configuration>(FilePath); var another = new AnotherConfigSection(); var test = new TestConfigSection() { Value = 155 }; configFile.Write(another, test); Assert.AreEqual(155, configFile.Read <TestConfigSection>().Value); configFile.DeleteSection <TestConfigSection>(); Assert.AreEqual(15, configFile.Read <AnotherConfigSection>().Number); Assert.AreEqual(9, configFile.Read <TestConfigSection>().Value); }
public void DeepConfigManager_Serialize_Provider_Config_Section() { //Arrange var file = new FileInfo(Path.Combine(Environment.CurrentDirectory, "web.config")); var config = DeepConfigManager.CreateNewConfigFile(file, true); var section = new TestConfigSection { Address = "address1", Name = "name1", Age = 123 }; //Act DeepConfigManager.SerializeProviderConfigSection(config, section, "rebel/persistenceProviderSettings/nhibernate", true); //Assert Assert.AreEqual("configuration", config.Root.Name.LocalName); Assert.AreEqual("configSections", config.Root.Elements().First().Name.LocalName); Assert.AreEqual("sectionGroup", config.Root.Elements().First().Elements().First().Name.LocalName); Assert.AreEqual("name", config.Root.Elements().First().Elements().First().Attributes().First().Name.LocalName); Assert.AreEqual("rebel", config.Root.Elements().First().Elements().First().Attributes().First().Value); Assert.AreEqual("sectionGroup", config.Root.Elements().First().Elements().First().Elements().First().Name.LocalName); Assert.AreEqual("name", config.Root.Elements().First().Elements().First().Elements().First().Attributes().First().Name.LocalName); Assert.AreEqual("persistenceProviderSettings", config.Root.Elements().First().Elements().First().Elements().First().Attributes().First().Value); Assert.AreEqual("section", config.Root.Elements().First().Elements().First().Elements().First().Elements().First().Name.LocalName); Assert.AreEqual("name", config.Root.Elements().First().Elements().First().Elements().First().Elements().First().Attributes().First().Name.LocalName); Assert.AreEqual("nhibernate", config.Root.Elements().First().Elements().First().Elements().First().Elements().First().Attributes().First().Value); Assert.AreEqual("requirePermission", config.Root.Elements().First().Elements().First().Elements().First().Elements().First().Attributes().Last().Name.LocalName); Assert.AreEqual(section.GetType().AssemblyQualifiedName, config.Root.Descendants("section").Where(x => x.Attributes("type").Any()).FirstOrDefault().Attribute("type").Value); Assert.AreEqual("rebel", config.Root.Elements().Last().Name.LocalName); Assert.AreEqual("persistenceProviderSettings", config.Root.Elements().Last().Elements().First().Name.LocalName); Assert.AreEqual("nhibernate", config.Root.Elements().Last().Elements().First().Elements().First().Name.LocalName); Assert.AreEqual("name1", config.Root.Elements().Last().Elements().First().Elements().First().Attribute("name").Value); Assert.AreEqual("address1", config.Root.Elements().Last().Elements().First().Elements().First().Attribute("address").Value); Assert.AreEqual(123, (int)config.Root.Elements().Last().Elements().First().Elements().First().Attribute("age")); }