Example #1
0
        public void Missing_environment_configuration_should_throw_typed_exception()
        {
            ConfigRoot originalApplicationConfig = CreateCannedApplicationConfig();
            ConfigRoot originalEnvironmentConfig = CreateCannedEnvironmentConfig();

            originalEnvironmentConfig.Data.Children.RemoveAt(1);

            Mock <IConfigProviderFactory> mockFactory = CreateFactory(originalApplicationConfig, originalEnvironmentConfig);
            var configProvider = new SampleApplicationConfigProvider(mockFactory.Object);

            try
            {
                configProvider.GetConfiguration();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(UnableToAccessConfigurationException));
                Assert.IsNotNull(ex.InnerException);
                Assert.IsInstanceOfType(ex.InnerException, typeof(ConfigValidationException));
                var validationException = (ConfigValidationException)ex.InnerException;
                Assert.IsNotNull(validationException.ValidationErrors);
                Assert.AreEqual(1, validationException.ValidationErrors.Count);
                var error = validationException.ValidationErrors[0];
                Assert.AreEqual("Environment.ConnectionString", error);
                Assert.IsTrue(ex.ToString().Contains("Environment.ConnectionString"));
            }
        }
        public void Missing_environment_configuration_should_throw_typed_exception()
        {
            ConfigRoot originalApplicationConfig = CreateCannedApplicationConfig();
            ConfigRoot originalEnvironmentConfig = CreateCannedEnvironmentConfig();
            originalEnvironmentConfig.Data.Children.RemoveAt(1);

            Mock<IConfigProviderFactory> mockFactory = CreateFactory(originalApplicationConfig, originalEnvironmentConfig);
            var configProvider = new SampleApplicationConfigProvider(mockFactory.Object);

            try
            {
                configProvider.GetConfiguration();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof (UnableToAccessConfigurationException));
                Assert.IsNotNull(ex.InnerException);
                Assert.IsInstanceOfType(ex.InnerException, typeof (ConfigValidationException));
                var validationException = (ConfigValidationException) ex.InnerException;
                Assert.IsNotNull(validationException.ValidationErrors);
                Assert.AreEqual(1, validationException.ValidationErrors.Count);
                var error = validationException.ValidationErrors[0];
                Assert.AreEqual("Environment.ConnectionString", error);
                Assert.IsTrue(ex.ToString().Contains("Environment.ConnectionString"));
            }
        }
Example #3
0
        public void Test_successful_conversion_of_generic_config_root_to_typed_object_graph()
        {
            ConfigRoot originalApplicationConfig = CreateCannedApplicationConfig();
            ConfigRoot originalEnvironmentConfig = CreateCannedEnvironmentConfig();

            Mock <IConfigProviderFactory> mockFactory = CreateFactory(originalApplicationConfig, originalEnvironmentConfig);
            var configProvider = new SampleApplicationConfigProvider(mockFactory.Object);

            SampleApplicationConfig actualConfig = configProvider.GetConfiguration();

            Assert.AreEqual(_expectedConfig.RestUrl, actualConfig.RestUrl);
            Assert.AreEqual(_expectedConfig.ConnectionString, actualConfig.ConnectionString);
            Assert.AreEqual(_expectedConfig.Timeout, actualConfig.Timeout);
            Assert.AreEqual(_expectedConfig.ConfigObject.Name, actualConfig.ConfigObject.Name);
            Assert.AreEqual(_expectedConfig.ConfigObject.Number, actualConfig.ConfigObject.Number);
        }
        public void Test_successful_conversion_of_generic_config_root_to_typed_object_graph()
        {
            ConfigRoot originalApplicationConfig = CreateCannedApplicationConfig();
            ConfigRoot originalEnvironmentConfig = CreateCannedEnvironmentConfig();

            Mock<IConfigProviderFactory> mockFactory = CreateFactory(originalApplicationConfig, originalEnvironmentConfig);
            var configProvider = new SampleApplicationConfigProvider(mockFactory.Object);

            SampleApplicationConfig actualConfig = configProvider.GetConfiguration();
            Assert.AreEqual(_expectedConfig.RestUrl, actualConfig.RestUrl);
            Assert.AreEqual(_expectedConfig.ConnectionString, actualConfig.ConnectionString);
            Assert.AreEqual(_expectedConfig.Timeout, actualConfig.Timeout);
            Assert.AreEqual(_expectedConfig.ConfigObject.Name, actualConfig.ConfigObject.Name);
            Assert.AreEqual(_expectedConfig.ConfigObject.Number, actualConfig.ConfigObject.Number);
        }