public void Configuration_values_are_read_from_a_series_of_json_files() { if (File.Exists("global.json")) { File.Delete("global.json"); } if (File.Exists("local.json")) { File.Delete("local.json"); } if (File.Exists("config.json")) { File.Delete("config.json"); } const string globalConf = @"{ key1: ""global-value-1"", key2: ""global-value-2""}"; const string localConf = @"{ key1: ""local-value-1""}"; const string configConf = @"{ key3: ""config-value-3""}"; File.AppendAllText("global.json", globalConf); File.AppendAllText("local.json", localConf); File.AppendAllText("config.json", configConf); _binder = ConfigurationBinderFactory.New(x => { // least specific to most specific // I assume that is reasonable x.AddJsonFile("global.json"); x.AddJsonFile("local.json"); x.AddJsonFile("config.json"); }); }
public RoleToServerMap Parse(FileInfo file) { var binder = ConfigurationBinderFactory.New(c => { //c.AddJsonFile(file.FullName); var content = File.ReadAllText(file.FullName); c.AddJson(content); }); var d = binder.GetAll(); var result = new RoleToServerMap(); foreach (var kvp in d) { result.AddMap(kvp.Key, kvp.Value.ToString()); } return(result); }
public void A_configuration_object_is_bound() { const string json = @"{ Value: [47,22] }"; _binder = ConfigurationBinderFactory.New(x => { x.AddJson(json); }); _configuration = _binder.Bind <ClassWithArray>(); }
public void A_configuration_object_is_bound() { const string json = @"{ Inner: { Value: 47 } }"; _binder = ConfigurationBinderFactory.New(x => { x.AddJson(json); }); _configuration = _binder.Bind <OuterLevel>(); }
public object Parse(Type t, FileInfo file, string commandLine, string environment) { var binder = ConfigurationBinderFactory.New(c => { //c.AddJsonFile("global.conf"); //c.AddJsonFile("{0}.conf".FormatWith(environment)); //c.AddJsonFile(file.FullName); var content = File.ReadAllText(file.FullName); c.AddJson(content); c.AddCommandLine(commandLine); }); object result = binder.Bind(t); return(result); }
public void A_single_json_configuration_file_is_loaded() { if (File.Exists("bob.json")) { File.Delete("bob.json"); } const string conf = @"{""my-key"": ""my-value""}"; File.AppendAllText("bob.json", conf); _binder = ConfigurationBinderFactory.New(x => { // a single json file x.AddJsonFile("bob.json"); }); }
public void A_configuration_object_is_bound() { const string json = @"{ Name: ""phatboyg"", Password: ""default""}"; var jsonStream = new MemoryStream(Encoding.UTF8.GetBytes(json)); string commandLineText = "-password:really_long_one --secure"; _binder = ConfigurationBinderFactory.New(x => { // least specific to most specific // I assume that is reasonable x.AddJson(jsonStream); x.AddCommandLine(commandLineText); }); _configuration = _binder.Bind <IMyConfiguration>(); }
public void Using_the_configuration_command_line_value_provider() { _binder = ConfigurationBinderFactory.New(x => { x.AddCommandLine("-name:dru"); }); }