private Type GetProviderType(ProviderConfigSection configSection, ProviderElement providerElement)
        {
            var  errorMessage = "The Type defined for Provider '{0}' is not valid.";
            Type providerType;

            var providerElementType = GetObjectType(configSection, providerElement.Type);

            if (!string.IsNullOrEmpty(providerElementType))
            {
                providerType = Type.GetType(providerElementType);
                if (providerType == null)
                {
                    throw new ConfigurationErrorsException(
                              string.Format(errorMessage, providerElement.Name));
                }
            }
            else
            {
                providerType = Type.GetType(providerElement.Type);
                if (providerType == null)
                {
                    throw new ConfigurationErrorsException(
                              string.Format(errorMessage, providerElement.Name));
                }
            }
            return(providerType);
        }
Example #2
0
            public void Should_get_enabled_providers_when_types_section_not_defined()
            {
                string configSectionName = "commonProvider";
                var    configSection     = new ProviderConfigSection();

                configSection.Settings.Add(new ProviderSettingElement()
                {
                    Key   = "GlobalTestSetting",
                    Value = "GlobalTestValue"
                });

                var providerSettingElement =
                    new ProviderSettingElement()
                {
                    Key   = "TestSetting",
                    Value = "TestValue"
                };

                var fooProvider = new ProviderElement()
                {
                    Name      = "Foo",
                    Group     = "FooGroup",
                    IsEnabled = true,
                    Type      = "CommonProvider.Tests.TestClasses.FooProvider,CommonProvider.Tests",
                };

                fooProvider.Settings.Add(providerSettingElement);
                configSection.Providers.Add(fooProvider);

                var barProvider = new ProviderElement()
                {
                    Name      = "Bar",
                    Group     = "BarGroup",
                    IsEnabled = true,
                    Type      = "CommonProvider.Tests.TestClasses.BarProvider,CommonProvider.Tests",
                };

                barProvider.Settings.Add(providerSettingElement);
                configSection.Providers.Add(barProvider);

                var xmlProviderConfigSource = new XmlProviderConfigSource(configSection);
                var providerConfig          = xmlProviderConfigSource.GetProviderConfiguration();

                Assert.That(providerConfig.ProviderDescriptors, Is.Not.Null);
                Assert.That(providerConfig.ProviderDescriptors.Count(), Is.EqualTo(2));
                Assert.That(providerConfig.Settings.Count, Is.EqualTo(1));
                Assert.That(providerConfig.ProviderDescriptors.Sum(x => x.ProviderSettings.Count), Is.EqualTo(2));
            }
        private string GetObjectType(ProviderConfigSection configSection, string typeName)
        {
            if (configSection.Types == null)
            {
                return(string.Empty);
            }

            string objectType = string.Empty;

            foreach (TypeElement objectTypeElement in configSection.Types)
            {
                if (objectTypeElement.Name.Equals(typeName, StringComparison.OrdinalIgnoreCase))
                {
                    objectType = objectTypeElement.Type;
                    break;
                }
            }
            return(objectType);
        }
        private string GetDataParserType(ProviderConfigSection configSection, string dataParserType)
        {
            var errorMessage          = "The data parser type is not valid.";
            var dataParserElementType = GetObjectType(configSection, dataParserType);

            if (!string.IsNullOrEmpty(dataParserElementType))
            {
                if (Type.GetType(dataParserElementType) == null)
                {
                    throw new ConfigurationErrorsException(errorMessage);
                }
                return(dataParserElementType);
            }
            else
            {
                if (Type.GetType(dataParserType) == null)
                {
                    throw new ConfigurationErrorsException(errorMessage);
                }
                return(dataParserType);
            }
        }
 /// <summary>
 /// Initializes an instance of XmlProviderConfigSource with a ProviderConfigSection
 /// </summary>
 /// <param name="configSection">The provider configuration section.</param>
 internal XmlProviderConfigSource(ProviderConfigSection configSection)
 {
     _configSection = configSection;
 }
 /// <summary>
 /// Initializes an instance of XmlProviderConfigSource
 /// </summary>
 public XmlProviderConfigSource()
 {
     _configSection = ConfigurationManager.GetSection(SectionName) as ProviderConfigSection;
 }