public void Config_should_always_come_from_cache_if_server_returns_invalid_data()
        {
            ConfigRoot configFromMockCache = MockHabitatServer.GetConfigRoot(TestComponentName);

            configFromMockCache.Data.Children[0].Value = "fromcache";
            CreateMockDurableCacheEntry(configFromMockCache);

            _mockConfigServiceHttpClient = HttpClientTestHelper.CreateClientThatAlwaysReturnsGibberish();
            var testFactory = new ConfigProviderFactory(TestAssemblyName, _mockConfigServiceHttpClient, _mockFileSystem.Object);

            IConfigProvider             configProvider = testFactory.Create(TestComponentName, new Dictionary <string, Func <string, bool> >());
            ConfigRoot                  config         = configProvider.GetAndValidateConfiguration();
            Dictionary <string, string> dictionary     = config.Data.ToDictionary();

            Assert.AreEqual("fromcache", dictionary[string.Format("{0}.N1", TestComponentName)]);
        }
Exemplo n.º 2
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());
        }
        public void Cache_should_never_be_updated_when_invalid_data_is_retrieved_from_server()
        {
            ConfigRoot originalConfigFromMockCache = MockHabitatServer.GetConfigRoot(TestComponentName);

            originalConfigFromMockCache.Data.Children[0].Value = "fromcache";
            CreateMockDurableCacheEntry(originalConfigFromMockCache);

            _mockConfigServiceHttpClient = HttpClientTestHelper.CreateClientThatAlwaysReturnsGibberish();
            var testFactory = new ConfigProviderFactory(TestAssemblyName, _mockConfigServiceHttpClient, _mockFileSystem.Object);

            IConfigProvider configProvider     = testFactory.Create(TestComponentName, new Dictionary <string, Func <string, bool> >());
            ConfigRoot      configFromProvider = configProvider.GetAndValidateConfiguration();

            ConfigRoot updatedConfigFromMockCache = ReadMockDurableCacheEntry();

            Assert.IsTrue(_objectComparer.Compare(originalConfigFromMockCache, updatedConfigFromMockCache).AreEqual);
            Assert.IsTrue(_objectComparer.Compare(configFromProvider, originalConfigFromMockCache).AreEqual);
        }