public void GivenAConfigurationWithTwoSourcesAndOnlyTheLastHasAMatchingKey()
        {
            var fixture = new Fixture();

            _key           = fixture.Create <string>();
            _configuration = new Configuration();

            _source1 = new ConfigurationSourceStub();

            _source2 = new ConfigurationSourceStub();
            _source2.AppSettings.Add(_key, fixture.Create <TValue>());

            _configuration.AddConfigurationSource(_source1);
            _configuration.AddConfigurationSource(_source2);
        }
Exemplo n.º 2
0
        public void GivenAConfigurationWithMultipleSourcesAndAllHaveMatchingKeys()
        {
            var fixture = new Fixture();

            _key           = fixture.Create <string>();
            _configuration = new Configuration();

            _source1 = new ConfigurationSourceStub();
            _source1.AppSettings.Add(_key, fixture.Create <TValue>());

            _source2 = new ConfigurationSourceStub();
            _source2.AppSettings.Add(_key, fixture.Create <TValue>());

            _configuration.AddConfigurationSource(_source1);
            _configuration.AddConfigurationSource(_source2);
        }
        public void GivenAConfigurationWithOneSourceThatHasNoMatchingKey()
        {
            _configuration = new Configuration();

            var source = new ConfigurationSourceStub();

            _configuration.AddConfigurationSource(source);
        }
Exemplo n.º 4
0
        public static Configuration AddMongoDb(this Configuration configuration, MongoUrl mongoUrl, string collectionName)
        {
            var mongoClient = new MongoClient(mongoUrl);
            var database    = mongoClient.GetDatabase(mongoUrl.DatabaseName);
            var collection  = database.GetCollection <AppSetting>(collectionName);

            configuration.AddConfigurationSource(new MongoDbSource(collection));

            return(configuration);
        }
Exemplo n.º 5
0
        public void GivenAConfigurationWithOneSourceThatHasAMatchingKey()
        {
            var fixture = new Fixture();

            _key           = fixture.Create <string>();
            _configuration = new Configuration();

            _source = new ConfigurationSourceStub();
            _source.AppSettings.Add(_key, fixture.Create <TValue>());
            _configuration.AddConfigurationSource(_source);
        }
Exemplo n.º 6
0
        public void GivenAnConfigurationWithACustomKeyFormatter()
        {
            _key          = _fixture.Create <string>();
            _formattedKey = _fixture.Create <string>();
            var value        = _fixture.Create <TValue>();
            var keyFormatter = new Mock <IKeyFormatter>();

            keyFormatter.Setup(x => x.FormatKey(_key))
            .Returns(_formattedKey);

            _source = new Mock <IConfigurationSource>();
            _source.Setup(x => x.GetAppSettingAsync <TValue>(_formattedKey, default(CancellationToken)))
            .ReturnsAsync(ConfigurationSourceResult <TValue> .SuccessResult(value));

            _configuration = new Configuration();
            _configuration.AddConfigurationSource(_source.Object);
            _configuration.SetKeyFormatter(keyFormatter.Object);
        }
Exemplo n.º 7
0
        public static Configuration AddConfigurationManager(this Configuration configuration)
        {
            configuration.AddConfigurationSource(new ConfigurationManagerSource());

            return(configuration);
        }
        public static Configuration AddEnvironmentVariables(this Configuration configuration)
        {
            configuration.AddConfigurationSource(new EnvironmentVariablesSource());

            return(configuration);
        }
Exemplo n.º 9
0
        public static Configuration AddConfigR(this Configuration configuration, IConfig config)
        {
            configuration.AddConfigurationSource(new ConfigRSource(config));

            return(configuration);
        }
Exemplo n.º 10
0
        public static Configuration AddInMemory(this Configuration configuration, IDictionary <string, object> appSettings)
        {
            configuration.AddConfigurationSource(new InMemorySource(appSettings));

            return(configuration);
        }