public void TestValue() { var configuration = new ConfigurationNode(ROOT_SECTION); var builder = new ConfigurationBuilder(configuration); builder.AddValue(TEST_VALUE_NAME, TEST_VALUE); var testValue = configuration.GetValue <int>(TEST_VALUE_NAME); Assert.AreEqual(testValue.Value, TEST_VALUE); }
public void TestGetUnkownSection() { var configuration = new ConfigurationNode(ROOT_SECTION); var builder = new ConfigurationBuilder(configuration); builder.AddSection(TEST1_SECTION); var testSection = configuration.GetOptionalSection("UnkownSection"); Assert.IsFalse(testSection.HasValue); }
public void TestSection() { var configuration = new ConfigurationNode(ROOT_SECTION); var builder = new ConfigurationBuilder(configuration); builder.AddSection(TEST1_SECTION); var testSection = configuration.GetSection(TEST1_SECTION); Assert.AreEqual(testSection.Section, TEST1_SECTION); }
public void TestMultiSectionUseResolveExtentions() { var configuration = new ConfigurationNode(ROOT_SECTION); var builder = new ConfigurationBuilder(configuration); builder.AddSection(TEST_MULTISECTION); var test2Section = configuration.ResolveSection(TEST_MULTISECTION); Assert.IsTrue(test2Section.HasValue); Assert.AreEqual(test2Section.Value.Section, TEST2_SECTION); }
public static IOptional <IConfigurationNode> ResolveSection(this ConfigurationNode configuration, string section) { var sectionParts = section.Split('.'); var queue = new Queue <string>(sectionParts); var currentConfiguration = configuration; while (queue.Count > 0) { var sectionName = queue.Dequeue(); if (currentConfiguration.Sections.TryGetValue(sectionName, out ConfigurationNode configurationNode)) { currentConfiguration = configurationNode; } else { return(Optional <IConfigurationNode> .Empty()); } } return(Optional <IConfigurationNode> .Of(currentConfiguration)); }
public IConfigurationBuilder AddSection(string section) { var sectionParts = new Queue <String>(section.Split('.')); ConfigurationNode current = currentConfiguration; while (sectionParts.Count > 0) { var sectionName = sectionParts.Dequeue(); if (current.Sections.TryGetValue(sectionName, out ConfigurationNode configurationNode)) { current = configurationNode; } else { var configurationNew = new ConfigurationNode(sectionName); current.Sections.Add(sectionName, configurationNew); current = configurationNew; } } return(new ConfigurationBuilder(current)); }
public ConfigurationNode(string section, ConfigurationNode parentConfiguration) : this(section) { ParentConfiguration = parentConfiguration; }
public ConfigurationBuilder(ConfigurationNode current) { this.currentConfiguration = current; }
public void TestSectionName() { var configuration = new ConfigurationNode(ROOT_SECTION); Assert.AreEqual(configuration.Section, ROOT_SECTION); }