private void SetupValues(ConfigValueDictionary fieldValues)
        {
            foreach (ConfigValueItem item in fieldValues)
            {
                if (!string.IsNullOrEmpty(item.Key))
                {
                    if (!ContainsOriginalMappingName(item.Key))
                    {
                        SettingItems.Add(
                            (
                                new ObjectCreationSettingItem()
                        {
                            OriginalName = item.Key,
                            MapToName = item.Key,
                            DefaultValue = item.Value,
                            OriginalValue = item.Value,
                            CreationSettingType = ObjectCreationSettingType.ConstructorOrProperty
                        }
                            )

                            );
                    }
                    else
                    {
                        SetValue(item.Key, item.Value);
                    }
                }
            }
        }
Exemplo n.º 2
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));
        }
 private void SetupMappings(ConfigValueDictionary fieldMappings)
 {
     foreach (ConfigValueItem item in fieldMappings)
     {
         if (!string.IsNullOrEmpty(item.Key) && !string.IsNullOrEmpty(item.Value))
         {
             if (ContainsOriginalMappingName(item.Key))
             {
                 SettingItems.First(x => x.OriginalName.Equals(item.Key)).MapToName = item.Value;
             }
             if (ContainsMapToName(item.Value))
             {
                 SettingItems.First(x => x.MapToName.Equals(item.Value)).OriginalName = item.Key;
             }
             else
             {
                 SettingItems.Add(
                     (
                         new ObjectCreationSettingItem()
                 {
                     OriginalName = item.Key,
                     MapToName = item.Value,
                     CreationSettingType = ObjectCreationSettingType.ConstructorOrProperty
                 }
                     )
                     );
             }
         }
     }
 }
        public static AutoGenerateModelsFromConfig.DomainModel LoadDomainModelTemplate()
        {
            ConfigValueDictionary mappings = new ConfigValueDictionary();
            mappings.Add("NoUnits", "NumberUnits");

            return new Config(@"MoreComplexExamples\MappingFieldsAutoGen\mapping.config", "domainModelTemplate")
                .GetSection("model")
                .Create<AutoGenerateModelsFromConfig.DomainModel>(mappings, true);
        }
        public static AutoGenerateModelsFromConfig.DomainModel LoadDomainModelTemplate()
        {
            ConfigValueDictionary mappings = new ConfigValueDictionary();

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

            return(new Config(@"MoreComplexExamples\MappingFieldsAutoGen\mapping.config", "domainModelTemplate")
                   .GetSection("model")
                   .Create <AutoGenerateModelsFromConfig.DomainModel>(mappings, true));
        }
        public static DomainModel LoadDomainModelTemplate()
        {
            ConfigSection configSection = new Config(@"MoreComplexExamples\AutoGenWithNonEmptyConstructor\autogenctor.config", "domainModelTemplate").GetSection("model");

            ConfigValueDictionary mappings = new ConfigValueDictionary();
            mappings.Add("mySecretNum", "MySecretNumber");  //pass in the param name for the constructor and the key of the corresponding ValueItem from config
            mappings.Add("numberUnits", "NumberUnits");    //remember that all params are case sensitive

            //if mappings had not been used it would not have known what values to use for both of these values which it got from config
            return configSection.Create<DomainModel>(mappings, true);
        }
Exemplo n.º 7
0
        public static DomainModel LoadDomainModelTemplate()
        {
            ConfigSection configSection = new Config(@"MoreComplexExamples\AutoGenWithNonEmptyConstructor\autogenctor.config", "domainModelTemplate").GetSection("model");

            ConfigValueDictionary mappings = new ConfigValueDictionary();

            mappings.Add("mySecretNum", "MySecretNumber"); //pass in the param name for the constructor and the key of the corresponding ValueItem from config
            mappings.Add("numberUnits", "NumberUnits");    //remember that all params are case sensitive

            //if mappings had not been used it would not have known what values to use for both of these values which it got from config
            return(configSection.Create <DomainModel>(mappings, true));
        }
Exemplo n.º 8
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"]);
        }
Exemplo n.º 9
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());
        }
Exemplo n.º 11
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());
        }
        internal ObjectCreationSettingsCollection(ConfigValueDictionary fieldMappings, ConfigValueDictionary fieldValues, bool onlySetPublicProperties)
        {
            OnlySetPublicProperties = onlySetPublicProperties;
            SettingItems = new List<ObjectCreationSettingItem>();

            //setup the field mappings
            OnlySetPublicProperties = onlySetPublicProperties;
            SettingItems = new List<ObjectCreationSettingItem>();

            if (fieldValues != null)
            {
                SetupValues(fieldValues);
            }

            //add any overrides and values as required.
            if (fieldMappings != null)
            {
                SetupMappings(fieldMappings);
            }
        }
        internal ObjectCreationSettingsCollection(ConfigValueDictionary fieldMappings, ConfigValueDictionary fieldValues, bool onlySetPublicProperties)
        {
            OnlySetPublicProperties = onlySetPublicProperties;
            SettingItems            = new List <ObjectCreationSettingItem>();

            //setup the field mappings
            OnlySetPublicProperties = onlySetPublicProperties;
            SettingItems            = new List <ObjectCreationSettingItem>();

            if (fieldValues != null)
            {
                SetupValues(fieldValues);
            }

            //add any overrides and values as required.
            if (fieldMappings != null)
            {
                SetupMappings(fieldMappings);
            }
        }
 private void SetupMappings(ConfigValueDictionary fieldMappings)
 {
     foreach (ConfigValueItem item in fieldMappings)
     {
         if (!string.IsNullOrEmpty(item.Key) && !string.IsNullOrEmpty(item.Value))
         {
             if (ContainsOriginalMappingName(item.Key))
             {
                 SettingItems.First(x => x.OriginalName.Equals(item.Key)).MapToName = item.Value;
             }
             if (ContainsMapToName(item.Value))
             {
                 SettingItems.First(x => x.MapToName.Equals(item.Value)).OriginalName = item.Key;
             }
             else
             {
                 SettingItems.Add(
                     (
                         new ObjectCreationSettingItem()
                         {
                             OriginalName = item.Key,
                             MapToName = item.Value,
                             CreationSettingType = ObjectCreationSettingType.ConstructorOrProperty
                         }
                     )
                 );
             }
         }
     }
 }
 /// <summary>
 /// Maps the dictionry key to the dictionary value for a field, only set public properties.
 /// </summary>
 /// <param name="fieldMappings"></param>
 internal ObjectCreationSettingsCollection(ConfigValueDictionary fieldMappings)
     : this(fieldMappings, true)
 {
 }
 internal ObjectCreationSettingsCollection(ConfigValueDictionary fieldMappings, bool onlySetPublicProperties)
     : this(fieldMappings, null, onlySetPublicProperties)
 {
 }
        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());
        }
        private void SetupValues(ConfigValueDictionary fieldValues)
        {
            foreach (ConfigValueItem item in fieldValues)
            {
                if (!string.IsNullOrEmpty(item.Key))
                {
                    if (!ContainsOriginalMappingName(item.Key))
                    {
                        SettingItems.Add(
                            (
                                new ObjectCreationSettingItem()
                                    {
                                        OriginalName = item.Key,
                                        MapToName = item.Key,
                                        DefaultValue = item.Value,
                                        OriginalValue = item.Value,
                                        CreationSettingType = ObjectCreationSettingType.ConstructorOrProperty
                                    }
                            )

                        );
                    }
                    else
                    {
                        SetValue(item.Key, item.Value);
                    }
                }
            }
        }
 /// <summary>
 /// Maps the dictionry key to the dictionary value for a field, only set public properties.
 /// </summary>
 /// <param name="fieldMappings"></param>
 internal ObjectCreationSettingsCollection(ConfigValueDictionary fieldMappings) : this(fieldMappings, true)
 {
 }
 internal ObjectCreationSettingsCollection(ConfigValueDictionary fieldMappings, bool onlySetPublicProperties) : this(fieldMappings, null, onlySetPublicProperties)
 {
 }