Esempio n. 1
0
 public void Init()
 {
     ConfigLoader = new CustomConfigurations.Config("myCustomGroup/mysection");
     Assert.IsNotNull(ConfigLoader);
     ConfigurationSection = ConfigLoader.GetSection("client1");
     Assert.IsNotNull(ConfigurationSection);
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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 Init()
 {
     ConfigLoader = new CustomConfigurations.Config("myCustomGroup/mysection");
     Assert.IsNotNull(ConfigLoader);
     ConfigurationSection = ConfigLoader.GetSection("client1");
     Assert.IsNotNull(ConfigurationSection);
 }
Esempio n. 5
0
 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);
 }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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.ContainsSubCollections);

            ConfigLoader = new CustomConfigurations.Config("testsection2");
            Assert.IsNotNull(ConfigLoader);
            ConfigurationSection = ConfigLoader.GetSection("clienta");
            Assert.IsNotNull(ConfigurationSection);

            Assert.IsFalse(ConfigurationSection.ContainsSubCollections);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        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);
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        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);
        }
Esempio n. 17
0
        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);
        }
        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 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 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"]);
        }
Esempio n. 23
0
 public void Init()
 {
     ConfigLoader = new CustomConfigurations.Config("testsection2");
     Section      = ConfigLoader.GetSection("clienta");
     Assert.IsNotNull(Section);
 }
        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);
        }