/// <summary>
        /// public for unittesting purposes.
        /// </summary>
        /// <param name="configurationSource"></param>
        /// <param name="reconfiguringEventSource"></param>
        /// <returns></returns>
        public static IEnumerable <ITypeRegistrationsProvider> CreateTypeRegistrationsProviderLocators(IConfigurationSource configurationSource, IContainerReconfiguringEventSource reconfiguringEventSource)
        {
            TypeRegistrationProvidersConfigurationSection section = configurationSource.GetSection(TypeRegistrationProvidersConfigurationSection.SectionName) as TypeRegistrationProvidersConfigurationSection;

            if (section == null)
            {
                section = new TypeRegistrationProvidersConfigurationSection();
            }

            foreach (TypeRegistrationProviderElement typeRegistrationProviderElement in section.TypeRegistrationProviders)
            {
                if (!string.IsNullOrEmpty(typeRegistrationProviderElement.SectionName) &&
                    !string.IsNullOrEmpty(typeRegistrationProviderElement.ProviderTypeName))
                {
                    throw new ConfigurationErrorsException(
                              string.Format("Type Registration Provider Settings '{0}' cannot declare both sectionName and providerType attributes",
                                            typeRegistrationProviderElement.Name));
                }
                if (!string.IsNullOrEmpty(typeRegistrationProviderElement.SectionName))
                {
                    yield return(new ConfigSectionLocator(typeRegistrationProviderElement.SectionName, reconfiguringEventSource));
                }
                else if (!string.IsNullOrEmpty(typeRegistrationProviderElement.ProviderTypeName))
                {
                    yield return(new TypeLoadingLocator(typeRegistrationProviderElement.ProviderTypeName, reconfiguringEventSource));
                }
            }
        }
        /// <summary>
        /// public for unittesting purposes.
        /// </summary>
        /// <param name="configurationSource"></param>
        /// <param name="reconfiguringEventSource"></param>
        /// <returns></returns>
        public static IEnumerable<ITypeRegistrationsProvider> CreateTypeRegistrationsProviderLocators(IConfigurationSource configurationSource, IContainerReconfiguringEventSource reconfiguringEventSource)
        {
            TypeRegistrationProvidersConfigurationSection section = configurationSource.GetSection(TypeRegistrationProvidersConfigurationSection.SectionName) as TypeRegistrationProvidersConfigurationSection;
            if (section == null)
            {
                section = new TypeRegistrationProvidersConfigurationSection();
            }

            foreach (TypeRegistrationProviderElement typeRegistrationProviderElement in section.TypeRegistrationProviders)
            {
                if (!string.IsNullOrEmpty(typeRegistrationProviderElement.SectionName) &&
                    !string.IsNullOrEmpty(typeRegistrationProviderElement.ProviderTypeName))
                {
                    throw new ConfigurationErrorsException(
                        string.Format("Type Registration Provider Settings '{0}' cannot declare both sectionName and providerType attributes",
                        typeRegistrationProviderElement.Name));
                }
                if (!string.IsNullOrEmpty(typeRegistrationProviderElement.SectionName))
                {
                    yield return new ConfigSectionLocator(typeRegistrationProviderElement.SectionName, reconfiguringEventSource);
                }
                else if (!string.IsNullOrEmpty(typeRegistrationProviderElement.ProviderTypeName))
                {
                    yield return new TypeLoadingLocator(typeRegistrationProviderElement.ProviderTypeName, reconfiguringEventSource);
                }
            }
        }
        public void Initialize()
        {
            ConfigurationSource = new FileConfigurationSource("typeRegistrationProviderSettings.config", false);

            TypeRegistrationProvidersSection = Given(ConfigurationSource);

        }
예제 #4
0
        protected TypeRegistrationProvidersConfigurationSection GetTypeRegistrationSection()
        {
            IConfigurationSource source = new DictionaryConfigurationSource();

            base.ConfigurationSourceBuilder.UpdateConfigurationWithReplace(source);

            TypeRegistrationProvidersConfigurationSection section = (TypeRegistrationProvidersConfigurationSection)source.GetSection(TypeRegistrationProvidersConfigurationSection.SectionName);

            return(section);
        }
예제 #5
0
        public void Then_ThereAreNoTypeRegistrations()
        {
            IConfigurationSource source = new DictionaryConfigurationSource();

            base.ConfigurationSourceBuilder.UpdateConfigurationWithReplace(source);

            TypeRegistrationProvidersConfigurationSection section = (TypeRegistrationProvidersConfigurationSection)source.GetSection(TypeRegistrationProvidersConfigurationSection.SectionName);

            Assert.AreEqual(0, section.TypeRegistrationProviders.Count);
        }
예제 #6
0
        public void WhenBothSectionAndProviderTypeAreSpecified_ThenThrowsConfigurationErrorsException()
        {
            TypeRegistrationProvidersConfigurationSection section = new TypeRegistrationProvidersConfigurationSection();

            section.TypeRegistrationProviders.Clear();
            section.TypeRegistrationProviders.Add(new TypeRegistrationProviderElement {
                Name = "test", SectionName = "Section Name", ProviderTypeName = "ProviderType"
            });
            configurationSource.Add(TypeRegistrationProvidersConfigurationSection.SectionName, section);


            ConfigurationBasedTypeRegistrationsProviderFactory.CreateProvider(configurationSource, new NullContainerReconfiguringEventSource()).GetRegistrations(configurationSource);
        }
        protected override void Arrange()
        {
            var source = new DictionaryConfigurationSource();

            source.Add(RetryPolicyConfigurationSettings.SectionName, GetSettings());

            var typeRegistrationSettings = new TypeRegistrationProvidersConfigurationSection();

            typeRegistrationSettings.TypeRegistrationProviders.Add(new TypeRegistrationProviderElement() { SectionName = RetryPolicyConfigurationSettings.SectionName });

            source.Add(TypeRegistrationProvidersConfigurationSection.SectionName, typeRegistrationSettings);

            EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(source);
        }
예제 #8
0
        public void WhenConfigurationContainsSectionName_ThenConfigSectionLocatorIsUsedToRetrieveRegistrations()
        {
            TypeRegistrationProvidersConfigurationSection section = new TypeRegistrationProvidersConfigurationSection();

            section.TypeRegistrationProviders.Clear();
            section.TypeRegistrationProviders.Add(new TypeRegistrationProviderElement {
                Name = "test", SectionName = "Section Name"
            });
            configurationSource.Add(TypeRegistrationProvidersConfigurationSection.SectionName, section);

            var locators = ConfigurationBasedTypeRegistrationsProviderFactory.CreateTypeRegistrationsProviderLocators(configurationSource, new NullContainerReconfiguringEventSource());

            Assert.AreEqual(1, locators.Count());
            Assert.IsInstanceOfType(locators.First(), typeof(ConfigSectionLocator));
        }
        public void Initialize()
        {
            ConfigurationSource = new FileConfigurationSource("typeRegistrationProviderSettings.config", false);

            TypeRegistrationProvidersSection = Given(ConfigurationSource);
        }