/// <summary>
        /// Creates a concrete Config Provider instance
        /// </summary>
        /// <param name="componentName">The name of the component that this Provider will manage</param>
        /// <param name="validationHandlers">A collection of functions that will validate config data for use with the specified Component</param>
        /// <returns>A new instance of the Config Provider</returns>
        public IConfigProvider Create(string componentName, Dictionary<string, Func<string, bool>> validationHandlers)
        {
            string repositoryDataDirectory = Path.Combine(_fileSystem.GetTempDirectoryPath(), _applicationAssemblyName);

            var configServiceProvider = new ConfigServiceProvider(componentName, _configServiceHttpClient);
            var cacheProvider = new DurableMemoryRepository<ConfigRoot>(repositoryDataDirectory, _fileSystem);
            var configProvider = new ConfigProvider(componentName, validationHandlers, configServiceProvider, cacheProvider);
            return configProvider;
        }
        public void Test_provider_behavior_when_config_service_address_does_not_resolve()
        {
            var provider = new ConfigServiceProvider(ResourceUrlTemplate, HttpClientTestHelper.CreateClientSimulatingABadAddress());

            ConfigServiceResponse response = provider.GetConfig();

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Config);
            Assert.AreEqual(ResourceUrlTemplate, response.Config.ComponentName);
            Assert.AreEqual(default(DateTime), response.Config.LastModified);
            Assert.IsNull(response.Config.Data);
            Assert.AreEqual(default(HttpStatusCode), response.StatusCode);
            Assert.IsNotNull(response.Exception);
            Assert.AreEqual(typeof(UnableToAccessConfigurationException), response.Exception.GetType());
            Assert.AreEqual(typeof(AggregateException), response.Exception.InnerException.GetType());
        }
Example #3
0
        public void Test_provider_behavior_when_config_service_returns_invalid_data()
        {
            var provider = new ConfigServiceProvider(ResourceUrlTemplate, HttpClientTestHelper.CreateClientThatAlwaysReturnsGibberish());

            ConfigServiceResponse response = provider.GetConfig();

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Config);
            Assert.AreEqual(ResourceUrlTemplate, response.Config.ComponentName);
            Assert.AreEqual(default(DateTime), response.Config.LastModified);
            Assert.IsNull(response.Config.Data);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsNotNull(response.Exception);
            Assert.AreEqual(typeof(UnableToAccessConfigurationException), response.Exception.GetType());
            Assert.AreEqual(typeof(AggregateException), response.Exception.InnerException.GetType());
        }
Example #4
0
        public void Test_provider_behavior_when_config_service_address_does_not_resolve()
        {
            var provider = new ConfigServiceProvider(ResourceUrlTemplate, HttpClientTestHelper.CreateClientSimulatingABadAddress());

            ConfigServiceResponse response = provider.GetConfig();

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Config);
            Assert.AreEqual(ResourceUrlTemplate, response.Config.ComponentName);
            Assert.AreEqual(default(DateTime), response.Config.LastModified);
            Assert.IsNull(response.Config.Data);
            Assert.AreEqual(default(HttpStatusCode), response.StatusCode);
            Assert.IsNotNull(response.Exception);
            Assert.AreEqual(typeof(UnableToAccessConfigurationException), response.Exception.GetType());
            Assert.AreEqual(typeof(AggregateException), response.Exception.InnerException.GetType());
        }
        public void Test_provider_behavior_when_config_service_returns_404()
        {
            HttpClient mockClient = HttpClientTestHelper.CreateStandardFakeClient(new MockHabitatServer());
            var provider = new ConfigServiceProvider("foo2", mockClient);

            ConfigServiceResponse response = provider.GetConfig();

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Config);
            Assert.AreEqual("foo2", response.Config.ComponentName);
            Assert.AreEqual(default(DateTime), response.Config.LastModified);
            Assert.IsNull(response.Config.Data);
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
            Assert.IsNotNull(response.Exception);
            Assert.AreEqual(typeof(UnableToAccessConfigurationException), response.Exception.GetType());
            Assert.IsNull(response.Exception.InnerException);
        }
Example #6
0
        public void Test_provider_behavior_when_config_service_returns_404()
        {
            HttpClient mockClient = HttpClientTestHelper.CreateStandardFakeClient(new MockHabitatServer());
            var        provider   = new ConfigServiceProvider("foo2", mockClient);

            ConfigServiceResponse response = provider.GetConfig();

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Config);
            Assert.AreEqual("foo2", response.Config.ComponentName);
            Assert.AreEqual(default(DateTime), response.Config.LastModified);
            Assert.IsNull(response.Config.Data);
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
            Assert.IsNotNull(response.Exception);
            Assert.AreEqual(typeof(UnableToAccessConfigurationException), response.Exception.GetType());
            Assert.IsNull(response.Exception.InnerException);
        }
        public void Test_provider_behavior_when_config_service_returns_valid_data()
        {
            ConfigRoot testConfig = MockHabitatServer.GetConfigRoot(ResourceName);
            DateTime expectedDate = testConfig.LastModified;

            HttpClient mockClient = HttpClientTestHelper.CreateStandardFakeClient(new MockHabitatServer());
            var provider = new ConfigServiceProvider(ResourceName, mockClient);

            ConfigServiceResponse response = provider.GetConfig();

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Config);
            Assert.AreEqual(ResourceName, response.Config.ComponentName);
            Assert.AreEqual(expectedDate, response.Config.LastModified);
            Assert.IsNotNull(response.Config.Data);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsNull(response.Exception);
            Assert.IsNotNull(response.Config);
            Assert.IsTrue(_objectComparer.Compare(testConfig, response.Config).AreEqual);
        }
Example #8
0
        public void Test_provider_behavior_when_config_service_returns_valid_data()
        {
            ConfigRoot testConfig   = MockHabitatServer.GetConfigRoot(ResourceName);
            DateTime   expectedDate = testConfig.LastModified;

            HttpClient mockClient = HttpClientTestHelper.CreateStandardFakeClient(new MockHabitatServer());
            var        provider   = new ConfigServiceProvider(ResourceName, mockClient);

            ConfigServiceResponse response = provider.GetConfig();

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Config);
            Assert.AreEqual(ResourceName, response.Config.ComponentName);
            Assert.AreEqual(expectedDate, response.Config.LastModified);
            Assert.IsNotNull(response.Config.Data);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsNull(response.Exception);
            Assert.IsNotNull(response.Config);
            Assert.IsTrue(_objectComparer.Compare(testConfig, response.Config).AreEqual);
        }
        public void Test_provider_behavior_when_config_service_returns_invalid_data()
        {
            var provider = new ConfigServiceProvider(ResourceUrlTemplate, HttpClientTestHelper.CreateClientThatAlwaysReturnsGibberish());

            ConfigServiceResponse response = provider.GetConfig();

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Config);
            Assert.AreEqual(ResourceUrlTemplate, response.Config.ComponentName);
            Assert.AreEqual(default(DateTime), response.Config.LastModified);
            Assert.IsNull(response.Config.Data);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsNotNull(response.Exception);
            Assert.AreEqual(typeof(UnableToAccessConfigurationException), response.Exception.GetType());
            Assert.AreEqual(typeof(AggregateException), response.Exception.InnerException.GetType());
        }