public void Should_be_able_to_use_type_name_from_types_section_in_plcae_of_full_type_as_provider_type()
            {
                string configSectionName = "commonProvider";
                var configSection = new ProviderConfigSection();

                configSection.Types.Add(
                    new TypeElement()
                    {
                        Name = "FooProvider",
                        Type = "CommonProvider.Tests.TestClasses.FooProvider,CommonProvider.Tests"
                    });

                configSection.Types.Add(
                    new TypeElement()
                    {
                        Name = "BarProvider",
                        Type = "CommonProvider.Tests.TestClasses.BarProvider,CommonProvider.Tests"
                    });

                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 = "FooProvider",
                };
                fooProvider.Settings.Add(providerSettingElement);
                configSection.Providers.Add(fooProvider);

                var barProvider = new ProviderElement()
                {
                    Name = "Bar",
                    Group = "BarGroup",
                    IsEnabled = true,
                    Type = "BarProvider",
                };
                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));
            }
 /// <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;
 }
        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;
        }
        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;
     }
 }
            public void Should_not_get_disabled_providers_from_config()
            {
                string configSectionName = "commonProvider";
                var configSection = new ProviderConfigSection();

                configSection.Types.Add(
                    new TypeElement()
                    {
                        Name = "FooProvider",
                        Type = "CommonProvider.Tests.TestClasses.FooProvider,CommonProvider.Tests"
                    });

                configSection.Types.Add(
                    new TypeElement()
                    {
                        Name = "BarProvider",
                        Type = "CommonProvider.Tests.TestClasses.BarProvider,CommonProvider.Tests"
                    });

                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 = false,
                    Type = "FooProvider",
                };
                fooProvider.Settings.Add(providerSettingElement);
                configSection.Providers.Add(fooProvider);

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

                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(1));
                Assert.That(providerConfig.ProviderDescriptors.First().ProviderName, Is.EqualTo("Bar"));
                Assert.That(providerConfig.Settings.Count, Is.EqualTo(1));
                Assert.That(providerConfig.ProviderDescriptors.Sum(x => x.ProviderSettings.Count), Is.EqualTo(1));
            }
            public void Should_get_enabled_providers_when_provider_settings_not_defined()
            {
                string configSectionName = "commonProvider";
                var configSection = new ProviderConfigSection();

                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",
                };
                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, Is.Null);
                Assert.That(providerConfig.ProviderDescriptors.Where(x => x.ProviderSettings != null)
                    .Sum(x => x.ProviderSettings.Count), Is.EqualTo(1));
            }