Esempio n. 1
0
        public void When_there_is_no_value_for_a_nullable_property()
        {
            var config = new StronkConfig()
                         .From.Source(_source)
                         .Build <NullablePropertyConfig>();

            config.SomeValue.HasValue.ShouldBeFalse();
        }
Esempio n. 2
0
        public void Consul_can_be_added_via_the_dsl()
        {
            var config = new StronkConfig().From.Consul() as IStronkConfig;

            config.ConfigSources
            .ShouldHaveSingleItem()
            .ShouldBeOfType <ConsulConfigurationSource>();
        }
Esempio n. 3
0
        public ConfigBuilderTests()
        {
            _target   = new TargetConfig();
            _settings = new Dictionary <string, string>();

            _options = new StronkConfig()
                       .From.Source(new DictionarySource(_settings));

            _builder = new ConfigBuilder(_options);
        }
Esempio n. 4
0
        public void When_there_is_a_value_for_a_nullable_property()
        {
            _settings["SomeValue"] = "17";

            var config = new StronkConfig()
                         .From.Source(_source)
                         .Build <NullablePropertyConfig>();

            config.SomeValue.HasValue.ShouldBeTrue();
            config.SomeValue.ShouldBe(17);
        }
Esempio n. 5
0
        protected ValidationTests()
        {
            var source = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            source[nameof(TargetParent.ParentValue)] = "1";
            source[nameof(Target.TargetValue)]       = "2";
            source[nameof(TargetChild.ChildValue)]   = "3";

            _builder = new StronkConfig();
            _builder.From.Source(new DictionarySource(source));
        }
Esempio n. 6
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Reading from settings.json...");
            Console.WriteLine("");

            var config = new StronkConfig()
                         .From.Source(new JsonConfigFile("settings.json"))
                         .Build <Configuration>();

            Console.WriteLine($"{nameof(config.Timeout)}: {config.Timeout.TotalSeconds} seconds");
            Console.WriteLine($"{nameof(config.Callback)}: {config.Callback}");
        }
Esempio n. 7
0
        public void When_a_property_is_selected_by_two_different_writers()
        {
            var config = new StronkConfig()
                         .From.Source(new DictionarySource(new Dictionary <string, string> {
                { "TestValue", "16" }
            }))
                         .Write.To(new BackingFieldPropertyWriter())
                         .Write.To(new PrivateSetterPropertyWriter())
                         .Build <MultiWriteConfig>();

            config.AlreadySet.ShouldBe(false);
            config.TestValue.ShouldBe(16);
        }
Esempio n. 8
0
        public static async Task <int> Main(string[] args)
        {
            using (var consul = await LaunchConsul())
            {
                var config = new StronkConfig()
                             .From.Consul(prefix: ApplicationName)
                             .Build <Configuration>();

                Console.WriteLine("Values read from Consul:");
                Console.WriteLine($"* {nameof(config.Timeout)}: {config.Timeout.TotalSeconds} seconds");
                Console.WriteLine($"* {nameof(config.Callback)}: {config.Callback}");

                consul.Close();
            }

            return(0);
        }
Esempio n. 9
0
        public static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Try changing the app.config values to be invalid:");
                Console.WriteLine("* Timeout should be between 1 and 120 seconds");
                Console.WriteLine("* Callback should be HTTPS, and the host should be either 'localhost' or 'internal'");
                Console.WriteLine("");

                var config = new StronkConfig()
                             .Validate.With <ConfigurationValidator>()
                             .Build <Configuration>();

                Console.WriteLine($"{nameof(config.Timeout)}: {config.Timeout.TotalSeconds} seconds");
                Console.WriteLine($"{nameof(config.Callback)}: {config.Callback}");
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(e.ToString());
                Console.ResetColor();
            }
        }
Esempio n. 10
0
 public ValidationExpression(StronkConfig configRoot)
 {
     _configRoot = configRoot;
     _validators = new List <IValidator>();
 }
Esempio n. 11
0
 public LogExpression(StronkConfig configRoot)
 {
     _configRoot = configRoot;
     _loggers    = new List <Action <LogMessage> >();
 }
Esempio n. 12
0
 public ConversionExpression(StronkConfig configRoot)
 {
     _configRoot = configRoot;
     _converters = new List <IValueConverter>();
     _onlySpecifiedConverters = false;
 }
Esempio n. 13
0
 public MapExpression(StronkConfig configRoot)
 {
     _configRoot = configRoot;
     _selectors  = new List <IPropertyMapper>();
 }
Esempio n. 14
0
 public SourceExpression(StronkConfig configRoot)
 {
     _configRoot = configRoot;
     _sources    = new List <IConfigurationSource>();
 }
Esempio n. 15
0
 public WriterExpression(StronkConfig configRoot)
 {
     _configRoot = configRoot;
     _writers    = new List <IPropertyWriter>();
 }