Exemplo 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();
        }
Exemplo 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>();
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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));
        }
Exemplo 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}");
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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();
            }
        }
Exemplo n.º 10
0
 public ValidationExpression(StronkConfig configRoot)
 {
     _configRoot = configRoot;
     _validators = new List <IValidator>();
 }
Exemplo n.º 11
0
 public LogExpression(StronkConfig configRoot)
 {
     _configRoot = configRoot;
     _loggers    = new List <Action <LogMessage> >();
 }
Exemplo n.º 12
0
 public ConversionExpression(StronkConfig configRoot)
 {
     _configRoot = configRoot;
     _converters = new List <IValueConverter>();
     _onlySpecifiedConverters = false;
 }
Exemplo n.º 13
0
 public MapExpression(StronkConfig configRoot)
 {
     _configRoot = configRoot;
     _selectors  = new List <IPropertyMapper>();
 }
Exemplo n.º 14
0
 public SourceExpression(StronkConfig configRoot)
 {
     _configRoot = configRoot;
     _sources    = new List <IConfigurationSource>();
 }
Exemplo n.º 15
0
 public WriterExpression(StronkConfig configRoot)
 {
     _configRoot = configRoot;
     _writers    = new List <IPropertyWriter>();
 }