예제 #1
0
        public void TestCanInheritValuesFromParentWenUsingGenericCreate()
        {
            CustomConfigurations.ConfigSection configSection = new CustomConfigurations.Config("inheritanceSection").GetSection("clienta");
            Assert.IsNotNull(configSection);

            Assert.IsTrue(configSection.ContainsSubCollections);
            Assert.AreEqual(1, configSection.ValuesAsDictionary.Count);
            string globalKey = "mykey1";

            Assert.IsTrue(configSection.ValuesAsDictionary.ContainsKey(globalKey));

            string globalValue = configSection.ValuesAsDictionary[globalKey];

            Assert.IsFalse(string.IsNullOrEmpty(globalValue));

            foreach (CustomConfigurations.ConfigSection childSection in configSection.Collections.GetCollections())
            {
                InheritanceTester test = childSection.Create <InheritanceTester>();
                if (test.Name.Equals("child1"))
                {
                    Assert.AreEqual(test.mykey1, globalValue);
                    Assert.AreEqual(test.Key2, "123");
                    Assert.IsTrue(string.IsNullOrEmpty(test.Key3));
                }

                if (test.Name.Equals("child2"))
                {
                    Assert.AreEqual(test.mykey1, globalValue);
                    Assert.AreEqual(test.Key3, "456");
                    Assert.IsTrue(string.IsNullOrEmpty(test.Key2));
                }
            }
        }
예제 #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);
        }
예제 #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));
        }
예제 #4
0
 public void Init()
 {
     ConfigLoader = new CustomConfigurations.Config("myCustomGroup/mysection");
     Assert.IsNotNull(ConfigLoader);
     ConfigurationSection = ConfigLoader.GetSection("client1");
     Assert.IsNotNull(ConfigurationSection);
 }
 public void Init()
 {
     ConfigLoader = new CustomConfigurations.Config("myCustomGroup/mysection");
     Assert.IsNotNull(ConfigLoader);
     ConfigurationSection = ConfigLoader.GetSection("client1");
     Assert.IsNotNull(ConfigurationSection);
 }
예제 #6
0
        public void TestCanGetAllSectionNames()
        {
            Configloader = new CustomConfigurations.Config("testsection2");
            Assert.IsNotNull(Configloader);

            Assert.Contains("clienta", Configloader.SectionNames.ToArray());
            Assert.Contains("clientb", Configloader.SectionNames.ToArray());
        }
예제 #7
0
        public void TestCanGetAllSectionNames()
        {
            Configloader = new CustomConfigurations.Config("testsection2");
            Assert.IsNotNull(Configloader);

            Assert.Contains("clienta", Configloader.SectionNames.ToArray());
            Assert.Contains("clientb", Configloader.SectionNames.ToArray());
        }
예제 #8
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);
        }
        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);
        }
예제 #10
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 TestCanCreateObjectThatHasDefaultValuesAssignedInConstructorAnyDontGetOverwrittenIfNoSettingFound()
        {
            DefaultsDomainModel model = new CustomConfigurations.Config("DefaultedTypedDataConfig").GetSection("model").Create<DefaultsDomainModel>();

            Assert.AreEqual("model", model.Name);
            Assert.IsTrue(model.CanExecute);
            Assert.AreEqual("My Default Description", model.Description);
            Assert.AreEqual(5, model.NumberUnits);
            Assert.AreEqual(DomainModelType.TheirType, model.ModelType);
            Assert.AreEqual(3, model.MySecretNumber);
        }
예제 #12
0
        public void TestCanCreateObjectThatHasDefaultValuesAssignedInConstructorAnyDontGetOverwrittenIfNoSettingFound()
        {
            DefaultsDomainModel model = new CustomConfigurations.Config("DefaultedTypedDataConfig").GetSection("model").Create <DefaultsDomainModel>();

            Assert.AreEqual("model", model.Name);
            Assert.IsTrue(model.CanExecute);
            Assert.AreEqual("My Default Description", model.Description);
            Assert.AreEqual(5, model.NumberUnits);
            Assert.AreEqual(DomainModelType.TheirType, model.ModelType);
            Assert.AreEqual(3, model.MySecretNumber);
        }
예제 #13
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);
        }
        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);
        }
예제 #15
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);
        }
예제 #16
0
        public void TestCanCreateTypedObjectAndPopulatePublicAndPrivateValuesFromValueItems()
        {
            CustomConfigurations.ConfigSection configSection = new CustomConfigurations.Config("TypedDataConfig").GetSection("model");
            Assert.IsNotNull(configSection);

            DomainModel model = configSection.Create <DomainModel>(false);

            Assert.AreEqual("model", model.Name);
            Assert.IsTrue(model.CanExecute);
            Assert.AreEqual("domain model template desciption field", model.Description);
            Assert.AreEqual(DomainModelType.TheirType, model.ModelType);
            Assert.AreEqual(2, model.GetResultFromMySecretNumberPrivateSetter());
        }
        public void TestCanCreateTypedObjectAndPopulatePublicValuesFromValueItems()
        {
            CustomConfigurations.ConfigSection configSection = new CustomConfigurations.Config("TypedDataConfig").GetSection("model");
            Assert.IsNotNull(configSection);

            DomainModel model = configSection.Create<DomainModel>();

            Assert.AreEqual("model", model.Name);
            Assert.IsTrue(model.CanExecute);
            Assert.AreEqual("domain model template desciption field", model.Description);
            Assert.AreEqual(5, model.NumberUnits);
            Assert.AreEqual(DomainModelType.TheirType, model.ModelType);
            Assert.AreEqual(int.MinValue, model.GetResultFromMySecretNumberPrivateSetter());
        }
예제 #18
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 TestCanCreateTypedObjectAndPopulateWithFieldMappings()
        {
            CustomConfigurations.ConfigSection configSection = new CustomConfigurations.Config("TypedDataConfig").GetSection("model");
            Assert.IsNotNull(configSection);

            IDictionary<string, string> mappings = new Dictionary<string, string>();
            mappings.Add("NoUnits", "NumberUnits");

            DomainModel model = configSection.Create<DomainModel>(false, mappings);

            Assert.AreEqual("model", model.Name);
            Assert.IsTrue(model.CanExecute);
            Assert.AreEqual("domain model template desciption field", model.Description);
            Assert.AreEqual(23, model.NumberUnits);
            Assert.AreEqual(DomainModelType.TheirType, model.ModelType);
            Assert.AreEqual(int.MinValue, model.GetResultFromMySecretNumberPrivateSetter());
        }
예제 #20
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);
        }
예제 #21
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);
        }
예제 #22
0
        public void TestCanLoadFileFromThatIsNotDefaultConfigPath()
        {
            //Copy test file so it can be reused many times:

            string tempFilePath = "app.Testfile.config";
            if (File.Exists(tempFilePath))
            {
                File.Delete(tempFilePath);
            }
            File.Copy("App.Test.config", tempFilePath);
            Assert.IsTrue(File.Exists(tempFilePath));

            Configloader = new CustomConfigurations.Config(tempFilePath, "testsection5");
            Assert.IsNotNull(Configloader);
            Assert.AreEqual(3, Configloader.Count);
            //clean up after ones self! :p
            File.Delete(tempFilePath);
        }
예제 #23
0
        public void TestCanCreateTypedObjectAndPopulateWithFieldMappings()
        {
            CustomConfigurations.ConfigSection configSection = new CustomConfigurations.Config("TypedDataConfig").GetSection("model");
            Assert.IsNotNull(configSection);

            ConfigValueDictionary mappings = new ConfigValueDictionary();

            mappings.Add("NoUnits", "NumberUnits");

            DomainModel model = configSection.Create <DomainModel>(mappings, true);

            Assert.AreEqual("model", model.Name);
            Assert.IsTrue(model.CanExecute);
            Assert.AreEqual("domain model template desciption field", model.Description);
            Assert.AreEqual(23, model.NumberUnits);
            Assert.AreEqual(DomainModelType.TheirType, model.ModelType);
            Assert.AreEqual(int.MinValue, model.GetResultFromMySecretNumberPrivateSetter());
        }
        public void TestCanCreateObjectThatDoesntHaveEmptyConstructor()
        {
            CustomConfigurations.ConfigSection configSection = new CustomConfigurations.Config("TypedDataConfig").GetSection("model");
            Assert.IsNotNull(configSection);

            ConfigValueDictionary mappings = new ConfigValueDictionary();
            mappings.Add("NoUnits", "NumberUnits");
            mappings.Add("name", "Name");
            mappings.Add("canExecute", "CanExecute");

            ComplexDomainModel model = configSection.Create<ComplexDomainModel>(mappings, true);

            Assert.AreEqual("model", model.GetResultOfConstructorSetName());
            Assert.IsTrue(model.GetResultOfConstructorSetCanExecute());
            Assert.AreEqual("domain model template desciption field", model.Description);
            Assert.AreEqual(23, model.NumberUnits);
            Assert.AreEqual(DomainModelType.TheirType, model.ModelType);
            Assert.AreEqual(int.MinValue, model.GetResultFromMySecretNumberPrivateSetter());
        }
예제 #25
0
        public void TestCanLoadFileFromThatIsNotDefaultConfigPath()
        {
            //Copy test file so it can be reused many times:

            string tempFilePath = "app.Testfile.config";

            if (File.Exists(tempFilePath))
            {
                File.Delete(tempFilePath);
            }
            File.Copy("App.Test.config", tempFilePath);
            Assert.IsTrue(File.Exists(tempFilePath));

            Configloader = new CustomConfigurations.Config(tempFilePath, "testsection5");
            Assert.IsNotNull(Configloader);
            Assert.AreEqual(3, Configloader.Count);
            //clean up after ones self! :p
            File.Delete(tempFilePath);
        }
예제 #26
0
        public void TestCanInheritValuesFromParentCanBeTurnedOff()
        {
            CustomConfigurations.ConfigSection configSection = new CustomConfigurations.Config("inheritanceSection", false).GetSection("clienta");
            Assert.IsNotNull(configSection);

            Assert.IsTrue(configSection.ContainsSubCollections);
            Assert.AreEqual(1, configSection.ValuesAsDictionary.Count);
            string globalKey = "mykey1";

            Assert.IsTrue(configSection.ValuesAsDictionary.ContainsKey(globalKey));

            string globalValue = configSection.ValuesAsDictionary[globalKey];

            Assert.IsFalse(string.IsNullOrEmpty(globalValue));

            foreach (CustomConfigurations.ConfigSection childSection in configSection.Collections.GetCollections())
            {
                Assert.IsFalse(childSection.ValuesAsDictionary.ContainsKey(globalKey));
            }
        }
예제 #27
0
        public void TestCanCreateObjectThatDoesntHaveEmptyConstructor()
        {
            CustomConfigurations.ConfigSection configSection = new CustomConfigurations.Config("TypedDataConfig").GetSection("model");
            Assert.IsNotNull(configSection);

            ConfigValueDictionary mappings = new ConfigValueDictionary();

            mappings.Add("NoUnits", "NumberUnits");
            mappings.Add("name", "Name");
            mappings.Add("canExecute", "CanExecute");

            ComplexDomainModel model = configSection.Create <ComplexDomainModel>(mappings, true);

            Assert.AreEqual("model", model.GetResultOfConstructorSetName());
            Assert.IsTrue(model.GetResultOfConstructorSetCanExecute());
            Assert.AreEqual("domain model template desciption field", model.Description);
            Assert.AreEqual(23, model.NumberUnits);
            Assert.AreEqual(DomainModelType.TheirType, model.ModelType);
            Assert.AreEqual(int.MinValue, model.GetResultFromMySecretNumberPrivateSetter());
        }
        public void TestCanCreateObjectWithDefaultValuesUsingObjectCreationSettingsCollection()
        {
            const string description = "This is my Test description";
            const string numberUnitsStr = "4456";
            const int numberUnitsInt = 4456;

            CustomConfigurations.ConfigSection configSection = new CustomConfigurations.Config("MinDefaultedTypedDataConfig").GetSection("model");
            ObjectCreationSettingsCollection settings = configSection.CreateCreationSettingsCollection();
            settings.SetValue("NumberUnits", numberUnitsStr);
            settings.SetValue("Description", description);

            DefaultsDomainModel model = configSection.Create<DefaultsDomainModel>(settings);

            Assert.AreEqual("model", model.Name);
            Assert.IsTrue(model.CanExecute);
            Assert.AreEqual(description, model.Description);
            Assert.AreEqual(numberUnitsInt, model.NumberUnits);
            Assert.AreEqual(DomainModelType.TheirType, model.ModelType);
            Assert.AreEqual(2, model.MySecretNumber);
        }
예제 #29
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);
        }
예제 #30
0
        public void TestCanCreateObjectWithDefaultValuesUsingObjectCreationSettingsCollection()
        {
            const string description    = "This is my Test description";
            const string numberUnitsStr = "4456";
            const int    numberUnitsInt = 4456;

            CustomConfigurations.ConfigSection configSection = new CustomConfigurations.Config("MinDefaultedTypedDataConfig").GetSection("model");
            ObjectCreationSettingsCollection   settings      = configSection.CreateCreationSettingsCollection();

            settings.SetValue("NumberUnits", numberUnitsStr);
            settings.SetValue("Description", description);

            DefaultsDomainModel model = configSection.Create <DefaultsDomainModel>(settings);

            Assert.AreEqual("model", model.Name);
            Assert.IsTrue(model.CanExecute);
            Assert.AreEqual(description, model.Description);
            Assert.AreEqual(numberUnitsInt, model.NumberUnits);
            Assert.AreEqual(DomainModelType.TheirType, model.ModelType);
            Assert.AreEqual(2, model.MySecretNumber);
        }
예제 #31
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]);
        }
예제 #32
0
        public void TestCanPopulateExistingObjectAndOverrideSomeValues()
        {
            CustomConfigurations.ConfigSection configSection = new CustomConfigurations.Config("TypedDataConfig").GetSection("model");
            Assert.IsNotNull(configSection);

            var model = configSection.Create <DomainModel>();

            Assert.AreEqual("model", model.Name);
            Assert.IsTrue(model.CanExecute);
            Assert.AreEqual("domain model template desciption field", model.Description);
            Assert.AreEqual(DomainModelType.TheirType, model.ModelType);
            Assert.AreEqual(int.MinValue, model.GetResultFromMySecretNumberPrivateSetter());

            CustomConfigurations.ConfigSection subConfigSection = new CustomConfigurations.Config("SubTypedDataConfig").GetSection("subModel");
            Assert.IsNotNull(subConfigSection);

            subConfigSection.Populate(model);

            Assert.AreEqual("subModel", model.Name);
            Assert.IsFalse(model.CanExecute);
            Assert.AreEqual("my description", model.Description);
            Assert.AreEqual(DomainModelType.TheirType, model.ModelType);
            Assert.AreEqual(int.MinValue, model.GetResultFromMySecretNumberPrivateSetter());
        }
 public void Init()
 {
     ConfigLoader = new CustomConfigurations.Config("testsection2");
     Section = ConfigLoader.GetSection("clienta");
     Assert.IsNotNull(Section);
 }
예제 #34
0
 public void TestCanLoadConfigurationWithOnlySectionGiven()
 {
     Configloader = new CustomConfigurations.Config("testsection2");
     Assert.IsNotNull(Configloader);
     Assert.AreEqual(2, Configloader.Count);
 }
예제 #35
0
 public void TestCanLoadConfigurationWithNoConfigurationPathGiven()
 {
     Configloader = new CustomConfigurations.Config();
     Assert.IsNotNull(Configloader);
     Assert.AreEqual(2, Configloader.Count);
 }
예제 #36
0
 public void Init()
 {
     Configloader = new CustomConfigurations.Config("myCustomGroup/mysection");
 }
        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 TestCanInheritValuesFromParentCanBeTurnedOff()
        {
            CustomConfigurations.ConfigSection configSection = new CustomConfigurations.Config("inheritanceSection", false).GetSection("clienta");
            Assert.IsNotNull(configSection);

            Assert.IsTrue(configSection.ContainsSubCollections);
            Assert.AreEqual(1, configSection.ValuesAsDictionary.Count);
            string globalKey = "mykey1";
            Assert.IsTrue(configSection.ValuesAsDictionary.ContainsKey(globalKey));

            string globalValue = configSection.ValuesAsDictionary[globalKey];
            Assert.IsFalse(string.IsNullOrEmpty(globalValue));

            foreach (CustomConfigurations.ConfigSection childSection in configSection.Collections.GetCollections())
            {
                Assert.IsFalse(childSection.ValuesAsDictionary.ContainsKey(globalKey));
            }
        }
        public void TestCanInheritValuesFromParentWenUsingGenericCreate()
        {
            CustomConfigurations.ConfigSection configSection = new CustomConfigurations.Config("inheritanceSection").GetSection("clienta");
            Assert.IsNotNull(configSection);

            Assert.IsTrue(configSection.ContainsSubCollections);
            Assert.AreEqual(1, configSection.ValuesAsDictionary.Count);
            string globalKey = "mykey1";
            Assert.IsTrue(configSection.ValuesAsDictionary.ContainsKey(globalKey));

            string globalValue = configSection.ValuesAsDictionary[globalKey];
            Assert.IsFalse(string.IsNullOrEmpty(globalValue));

            foreach (CustomConfigurations.ConfigSection childSection in configSection.Collections.GetCollections())
            {
                InheritanceTester test = childSection.Create<InheritanceTester>();
                if (test.Name.Equals("child1"))
                {
                    Assert.AreEqual(test.mykey1, globalValue);
                    Assert.AreEqual(test.Key2, "123");
                    Assert.IsTrue(string.IsNullOrEmpty(test.Key3));
                }

                if (test.Name.Equals("child2"))
                {
                    Assert.AreEqual(test.mykey1, globalValue);
                    Assert.AreEqual(test.Key3, "456");
                    Assert.IsTrue(string.IsNullOrEmpty(test.Key2));
                }
            }
        }
예제 #40
0
 public void TestCanLoadConfigurationWithNoConfigurationPathGiven()
 {
     Configloader = new CustomConfigurations.Config();
     Assert.IsNotNull(Configloader);
     Assert.AreEqual(2, Configloader.Count);
 }
        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]);
        }
예제 #42
0
 public void Init()
 {
     Configloader = new CustomConfigurations.Config("myCustomGroup/mysection");
 }
예제 #43
0
 public void TestWhenGivenIncorrectFilePathWillDefaultBackToNormalConfigFile()
 {
     Configloader = new CustomConfigurations.Config("C:\temp\thisIsARubbishFilePath.config" ,"testsection2");
     Assert.IsNotNull(Configloader);
     Assert.AreEqual(2, Configloader.Count);
 }
예제 #44
0
 public void Init()
 {
     ConfigLoader = new CustomConfigurations.Config("testsection2");
     Section      = ConfigLoader.GetSection("clienta");
     Assert.IsNotNull(Section);
 }
        public void TestCanPopulateExistingObjectAndOverrideSomeValues()
        {
            CustomConfigurations.ConfigSection configSection = new CustomConfigurations.Config("TypedDataConfig").GetSection("model");
            Assert.IsNotNull(configSection);

            var model = configSection.Create<DomainModel>();

            Assert.AreEqual("model", model.Name);
            Assert.IsTrue(model.CanExecute);
            Assert.AreEqual("domain model template desciption field", model.Description);
            Assert.AreEqual(DomainModelType.TheirType, model.ModelType);
            Assert.AreEqual(int.MinValue, model.GetResultFromMySecretNumberPrivateSetter());

            CustomConfigurations.ConfigSection subConfigSection = new CustomConfigurations.Config("SubTypedDataConfig").GetSection("subModel");
            Assert.IsNotNull(subConfigSection);

            subConfigSection.Populate(model);

            Assert.AreEqual("subModel", model.Name);
            Assert.IsFalse(model.CanExecute);
            Assert.AreEqual("my description", model.Description);
            Assert.AreEqual(DomainModelType.TheirType, model.ModelType);
            Assert.AreEqual(int.MinValue, model.GetResultFromMySecretNumberPrivateSetter());
        }
        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);
        }
예제 #47
0
 public void TestWhenGivenIncorrectFilePathWillDefaultBackToNormalConfigFile()
 {
     Configloader = new CustomConfigurations.Config("C:\temp\thisIsARubbishFilePath.config", "testsection2");
     Assert.IsNotNull(Configloader);
     Assert.AreEqual(2, Configloader.Count);
 }
예제 #48
0
 public void TestCanLoadConfigurationWithOnlySectionGiven()
 {
     Configloader = new CustomConfigurations.Config("testsection2");
     Assert.IsNotNull(Configloader);
     Assert.AreEqual(2, Configloader.Count);
 }
        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 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));
        }
예제 #51
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);
        }
        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);
        }