예제 #1
0
        public void Constructor_ThrowsExceptionIfNoProvidersAreSpecified()
        {
            var conversionManager = new DefaultConversionManager();

            Assert.Throws <ArgumentException>(() => new AggregateSettingsProvider(conversionManager, new List <ISettingsProvider>()));
            Assert.Throws <ArgumentException>(() => new AggregateSettingsProvider(conversionManager, null));
        }
예제 #2
0
        private void InitalizeFromConfigurationSource(IConfigurationInterpreter interpreter)
        {
            DefaultConversionManager conversionManager =
                (DefaultConversionManager)Kernel.GetSubSystem(SubSystemConstants.ConversionManagerKey);

            conversionManager.Add(new ConfigurationObjectConverter());

            interpreter.ProcessResource(interpreter.Source, Kernel.ConfigurationStore);
            RunInstaller();
        }
예제 #3
0
        private void InitalizeFromConfigurationSource(IConfigurationInterpreter interpreter,
                                                      IEnvironmentInfo env)
        {
            DefaultConversionManager conversionManager =
                (DefaultConversionManager)Kernel.GetSubSystem(SubSystemConstants.ConversionManagerKey);

            conversionManager.Add(new ConfigurationObjectConverter());

            if (env != null)
            {
                interpreter.EnvironmentName = env.GetEnvironmentName();
            }

            interpreter.ProcessResource(interpreter.Source, Kernel.ConfigurationStore);
            RunInstaller();
        }
예제 #4
0
        public void GetSetting_CanGetSettingFromAppSettings()
        {
            // Arrange
            const string key               = "StringSetting";
            var          expectedValue     = ConfigurationManager.AppSettings[key];
            var          conversionManager = new DefaultConversionManager();

            var provider = new AggregateSettingsProvider(conversionManager,
                                                         new[] { new AppSettingsProvider(conversionManager) });

            // Act
            var value = provider.GetSetting(key, typeof(string));

            // Assert
            Assert.AreEqual(expectedValue, value);
        }
예제 #5
0
        public void GetSetting_FallsBackToNextProviderIfFirstProviderHasNoValue()
        {
            // Arrange
            const string key               = "StringSetting";
            var          expectedValue     = ConfigurationManager.AppSettings[key];
            var          conversionManager = new DefaultConversionManager();

            Environment.SetEnvironmentVariable(key, null);

            var provider = new AggregateSettingsProvider(conversionManager,
                                                         new List <ISettingsProvider>
            {
                new EnvironmentSettingsProvider(conversionManager),
                new AppSettingsProvider(conversionManager)
            });

            // Act
            var value = provider.GetSetting(key, typeof(string));

            // Assert
            Assert.AreEqual(expectedValue, value);
        }
예제 #6
0
        public void GetSetting_CanGetSettingFromEnvironmentInsteadOfAppSettings()
        {
            // Arrange
            const string key               = "StringSetting";
            const string expectedValue     = "EnvironmentValue";
            var          conversionManager = new DefaultConversionManager();

            Environment.SetEnvironmentVariable(key, expectedValue);

            var provider = new AggregateSettingsProvider(conversionManager,
                                                         new List <ISettingsProvider>
            {
                new EnvironmentSettingsProvider(conversionManager),
                new AppSettingsProvider(conversionManager)
            });

            // Act
            var value = provider.GetSetting(key, typeof(string));

            // Assert
            Assert.AreEqual(expectedValue, value);
        }