public void Init() { ConfigLoader = new CustomConfigurations.Config("myCustomGroup/mysection"); Assert.IsNotNull(ConfigLoader); ConfigurationSection = ConfigLoader.GetSection("client1"); Assert.IsNotNull(ConfigurationSection); }
public void TestConfigurationLoaderAssignsAllIndexesCorrectly() { CustomConfigurations.ConfigSection configSection = Configloader.GetSection("client1"); Assert.AreEqual(0, configSection.Index); Assert.AreEqual(0, configSection.GetValueItemIndex("key2")); Assert.AreEqual(2, configSection.GetValueItemIndex("key4")); Assert.AreEqual(1, configSection.GetValueItemIndex("key3")); Assert.AreEqual(3, configSection.GetValueItemIndex("key5")); Assert.AreEqual(4, configSection.GetValueItemIndex("key6")); CustomConfigurations.ConfigSection innerCol1 = configSection.Collections.GetCollection("col1"); Assert.AreEqual(0, innerCol1.Index); Assert.AreEqual(0, innerCol1.GetValueItemIndex("key2")); Assert.AreEqual(1, innerCol1.GetValueItemIndex("key3")); CustomConfigurations.ConfigSection innerCol2 = configSection.Collections.GetCollection("col2"); Assert.AreEqual(1, innerCol2.Index); Assert.AreEqual(1, innerCol2.GetValueItemIndex("key4")); Assert.AreEqual(0, innerCol2.GetValueItemIndex("key3")); Assert.AreEqual(2, innerCol2.GetValueItemIndex("key5")); CustomConfigurations.ConfigSection innerCol3 = innerCol2.Collections.GetCollection("col3"); Assert.AreEqual(0, innerCol3.Index); Assert.AreEqual(0, innerCol3.GetValueItemIndex("key2a")); Assert.AreEqual(1, innerCol3.GetValueItemIndex("key3a")); //Test other config section as it has multiple config groups section Configloader = new CustomConfigurations.Config("testsection2"); Assert.IsNotNull(Configloader); Assert.AreEqual(0, Configloader.GetSection("clienta").Index); Assert.AreEqual(1, Configloader.GetSection("clientb").Index); }
public void TestInheritedFlagIsSetCorrectly() { CustomConfigurations.ConfigSection configSection = new CustomConfigurations.Config("inheritanceSectionLocal").GetSection("clienta"); Assert.IsNotNull(configSection); string globalKey1 = "mykey1"; string globalKey2 = "globalkey"; Assert.IsTrue(configSection.ValuesAsDictionary.ContainsKey(globalKey1)); string globalValue = configSection.ValuesAsDictionary[globalKey1]; Assert.IsFalse(string.IsNullOrEmpty(globalValue)); CustomConfigurations.ConfigSection childSection = configSection.Collections.GetCollection("child"); Assert.IsNotNull(childSection); Assert.IsTrue(childSection.ValuesAsDictionary.ContainsKey(globalKey1)); Assert.AreNotEqual(globalValue, childSection.ValuesAsDictionary[globalKey1]); Assert.AreEqual("123", childSection.ValuesAsDictionary[globalKey1]); ConfigValueDictionary values = childSection.ValuesAsDictionary; Assert.AreEqual(3, values.Count); string childKey = "mykey2"; Assert.IsTrue(childSection.ValuesAsDictionary.ContainsKey(childKey)); Assert.IsFalse(values.IsInherited(globalKey1)); Assert.IsFalse(values.IsInherited(childKey)); Assert.IsTrue(values.IsInherited(globalKey2)); }
public void TestReturningCorrectInnerCollection() { CustomConfigurations.ConfigSection innerSection = ConfigurationSection.Collections.GetCollection("col2"); Assert.IsNotNull(innerSection); Assert.AreEqual("col2", innerSection.Name); Assert.AreEqual(3, innerSection.Count); Assert.AreEqual("8", innerSection["key5"]); Assert.IsTrue(innerSection.ContainsSubCollections); }
public void TestContainsInnerCollection() { Assert.IsFalse(Section.ContainsSubCollections); //load the one that has collections ConfigLoader = new CustomConfigurations.Config("myCustomGroup/mysection"); Section = ConfigLoader.GetSection("client1"); Assert.IsTrue(Section.ContainsSubCollections); }
public void TesthasCollections() { Assert.IsTrue(ConfigurationSection.ContainsSubCollections); ConfigLoader = new CustomConfigurations.Config("testsection2"); Assert.IsNotNull(ConfigLoader); ConfigurationSection = ConfigLoader.GetSection("clienta"); Assert.IsNotNull(ConfigurationSection); Assert.IsFalse(ConfigurationSection.ContainsSubCollections); }
public void TestIsChildLink() { ConfigLoader = new CustomConfigurations.Config("myCustomGroup/mysection"); Section = ConfigLoader.GetSection("client1"); Assert.IsNotNull(Section); Assert.IsFalse(Section.IsChild); CustomConfigurations.ConfigSection childSection = Section.Collections.GetCollection("col2"); Assert.IsNotNull(childSection); Assert.IsTrue(childSection.IsChild); }
public void TestHasCollections() { Assert.IsTrue(ConfigurationSection.Collections.HasCollections); CustomConfigurations.ConfigSection coll2 = ConfigurationSection.Collections.GetCollection("col2"); Assert.IsNotNull(coll2); Assert.IsTrue(coll2.Collections.HasCollections); CustomConfigurations.ConfigSection coll3 = coll2.Collections.GetCollection("col3"); Assert.IsNotNull(coll3); Assert.IsNull(coll3.Collections); }
public void TestParentLinksWork() { ConfigLoader = new CustomConfigurations.Config("myCustomGroup/mysection"); Section = ConfigLoader.GetSection("client1"); Assert.IsNotNull(Section); Assert.IsNull(Section.Parent); CustomConfigurations.ConfigSection childSection = Section.Collections.GetCollection("col2"); Assert.IsNotNull(childSection); Assert.AreEqual(Section, childSection.Parent); }
public void TestNestedCollections() { CustomConfigurations.ConfigSection firstInner = ConfigurationSection.Collections.GetCollection("col2"); Assert.IsNotNull(firstInner); CustomConfigurations.CollectionsGroup nestedInner = firstInner.Collections; Assert.IsNotNull(nestedInner); Assert.IsTrue(nestedInner.HasCollections); CustomConfigurations.ConfigSection coll3InnerNested = nestedInner.GetCollection("col3"); Assert.IsNotNull(coll3InnerNested); Assert.IsNull(coll3InnerNested.Collections); }
public void TestReturningValuesAsDictionaryWorks() { ConfigLoader = new CustomConfigurations.Config("myCustomGroup/mysection"); Section = ConfigLoader.GetSection("client1"); ConfigValueDictionary dictionary = Section.ValuesAsDictionary; Assert.IsNotNull(dictionary); Assert.AreEqual(5, dictionary.Count); Assert.AreEqual("value2", dictionary["key2"]); Assert.AreEqual("value4", dictionary["key4"]); Assert.AreEqual("0.6", dictionary["key6"]); }
public void Init() { //Copy test file so it can be reused many times: if (File.Exists(TempFilePath)) { File.Delete(TempFilePath); } Assert.IsFalse(File.Exists(TempFilePath)); Assert.IsTrue(File.Exists(SourceAppConfig)); File.Copy(SourceAppConfig, TempFilePath); Assert.IsTrue(File.Exists(TempFilePath)); Configloader = new CustomConfigurations.Config(TempFilePath, "testsection5"); Assert.IsNotNull(Configloader); ClientSection = Configloader.GetSection("clienta"); Assert.IsNotNull(ClientSection); }
public void TestGenericCastingOfValueToTypes() { ConfigLoader = new CustomConfigurations.Config("myCustomGroup/mysection"); Section = ConfigLoader.GetSection("client1"); Assert.IsNotNull(Section); bool result = false; int myInt = Section.TryParse <int>("key5", out result); Assert.IsNotNull(myInt); Assert.AreEqual(7, myInt); Assert.IsTrue(result); result = false; float myfloat = Section.TryParse <float>("key6", out result); Assert.IsNotNull(myfloat); Assert.AreEqual(0.6f, myfloat); Assert.IsTrue(result); }
public void TestCanInheritValuesFromParentWillNotOverwriteLocalValue() { CustomConfigurations.ConfigSection configSection = new CustomConfigurations.Config("inheritanceSectionLocal").GetSection("clienta"); Assert.IsNotNull(configSection); Assert.IsTrue(configSection.ContainsSubCollections); Assert.AreEqual(2, configSection.ValuesAsDictionary.Count); string globalKey = "mykey1"; Assert.IsTrue(configSection.ValuesAsDictionary.ContainsKey(globalKey)); string globalValue = configSection.ValuesAsDictionary[globalKey]; Assert.IsFalse(string.IsNullOrEmpty(globalValue)); CustomConfigurations.ConfigSection childSection = configSection.Collections.GetCollection("child"); Assert.IsNotNull(childSection); Assert.IsTrue(childSection.ValuesAsDictionary.ContainsKey(globalKey)); Assert.AreNotEqual(globalValue, childSection.ValuesAsDictionary[globalKey]); Assert.AreEqual("123", childSection.ValuesAsDictionary[globalKey]); }
public void Init() { ConfigLoader = new CustomConfigurations.Config("testsection2"); Section = ConfigLoader.GetSection("clienta"); Assert.IsNotNull(Section); }
public void TestGenericCastingOfValueToTypes() { ConfigLoader = new CustomConfigurations.Config("myCustomGroup/mysection"); Section = ConfigLoader.GetSection("client1"); Assert.IsNotNull(Section); bool result = false; int myInt = Section.TryParse<int>("key5", out result); Assert.IsNotNull(myInt); Assert.AreEqual(7, myInt); Assert.IsTrue(result); result = false; float myfloat = Section.TryParse<float>("key6", out result); Assert.IsNotNull(myfloat); Assert.AreEqual(0.6f, myfloat); Assert.IsTrue(result); }