Example #1
0
        public void ReadFromMultiEnvVariable()
        {
            Environment.SetEnvironmentVariable("Foo", "foo");
            var value = EnvironmentManager.Create().Env("Bar").Env("Foo").Build();

            Assert.Equal("foo", value);
        }
Example #2
0
        public void WithXmlFileTest()
        {
            var builder = EnvironmentManager.Create(x => x.WithXmlFile("xml1.xml"));
            var parser  = builder.Configuration.GetValue <XmlFileParser>(typeof(XmlFileParser).FullName);

            Assert.Contains("xml1.xml", parser.Files.Keys);
        }
        public void DefaultToValue()
        {
            var builder = EnvironmentManager.Create();
            var value   = builder.Arg("foo").Default("x").Bundle();

            Assert.Equal("x", value.Build());
        }
Example #4
0
        public void ReadFromVarWithArrayTypePrefix()
        {
            Environment.SetEnvironmentVariable("Foo", "foo;bar");
            var value = EnvironmentManager.Create().With("Foo").Env().Build <IEnumerable <string> >();

            Assert.True(new[] { "foo", "bar" }.SequenceEqual(value));
        }
        public void DefaultToException()
        {
            var builder = EnvironmentManager.Create();
            var value   = builder.Arg("foo").Throw("x").Bundle();

            Assert.Throws <ArgumentException>(() => value.Build());
        }
Example #6
0
        public void ParseEnvironmentVariableToEnum()
        {
            Environment.SetEnvironmentVariable(nameof(ParseEnvironmentVariableToEnum), "RandomValue1");
            var value = EnvironmentManager.Create().Env(nameof(ParseEnvironmentVariableToEnum)).Build <RandomEnum>();

            Assert.Equal(RandomEnum.RandomValue1, value);
        }
        public void WithJsonFileTest()
        {
            var builder = EnvironmentManager.Create(x => x.WithJsonFile("json1.json"));
            var parser  = builder.Configuration.GetValue <JsonFileParser>(typeof(JsonFileParser).FullName);

            Assert.Contains("json1.json", parser.Files.Keys);
        }
Example #8
0
        public void WithGlobalDescriptionTest()
        {
            var d   = "some description";
            var env = EnvironmentManager.Create(x => x.WithDescription(d));

            Assert.Equal(d, env.GetDescription());
        }
Example #9
0
        public void WithGlobalDescriptionRepeatedLastOneWinsTest()
        {
            var d   = "some description";
            var env = EnvironmentManager.Create(x => x.WithDescription("some other description").WithDescription(d));

            Assert.Equal(d, env.GetDescription());
        }
Example #10
0
        public void ReadFromVarWithLocalPrefix()
        {
            Environment.SetEnvironmentVariable("Foo", "foo");
            var value = EnvironmentManager.Create().With("Foo").Env().Build();

            Assert.Equal("foo", value);
        }
Example #11
0
        public void ReadFromVarWithGlobalPrefix()
        {
            Environment.SetEnvironmentVariable("x_Foo", "foo");
            var value = EnvironmentManager.Create(x => x.WithEnvironmentVariablePrefix("x_")).Env("Foo").Build();

            Assert.Equal("foo", value);
        }
Example #12
0
        public void WithValidStringPathAndMultiFileTest()
        {
            var builder = EnvironmentManager.Create(x => x.WithXmlFile("xml1.xml").WithXmlFile("xml2.xml"));
            var bundle  = builder.Xml("/bar", "xml2").Bundle();
            var value   = bundle.Build();

            Assert.Equal("baz", value);
        }
        public void DoNotLogWarning()
        {
            bool hit = false;

            _writer.TextWritten += (s, t) => hit = t.Text.Equals("[WARNING] Foo") || hit;
            EnvironmentManager.Create(c => c.WithTextWriterLogger(_writer, LogLevel.Error).LogWarning("Foo"));
            Assert.False(hit);
        }
        public void LogFatal()
        {
            bool hit = false;

            _writer.TextWritten += (s, t) => hit = t.Text.Equals("[FATAL] Foo") || hit;
            EnvironmentManager.Create(c => c.WithTextWriterLogger(_writer, LogLevel.Trace).LogFatal("Foo"));
            Assert.True(hit);
        }
        public void DoNotLogTrace()
        {
            bool hit = false;

            _writer.TextWritten += (s, t) => hit = t.Text.Equals("[TRACE] Foo") || hit;
            EnvironmentManager.Create(c => c.WithTextWriterLogger(_writer, LogLevel.Off).LogTrace("Foo"));
            Assert.False(hit);
        }
Example #16
0
        public void CreateBundleWithGenericValueAndBuildTest()
        {
            var builder = EnvironmentManager.Create()
                          .WithSource(cfg => "foo")
                          .Build();

            Assert.Equal("foo", builder);
        }
        public void JsonFileExtensions()
        {
            var env = EnvironmentManager.Create(config =>
                                                config.WithJsonFile("json1.json").WithJsonFile("json2.json"));

            Assert.Equal("bar", env.Json("$(json1).foo").Build());
            Assert.Equal("baz", env.Json("$(json2).bar").Build());
        }
Example #18
0
        public void WithInvalidFileTest()
        {
            var builder = EnvironmentManager.Create(x => x.WithXmlFile("xml1đđxx.xml"));
            var bundle  = builder.Xml("/xxx").Bundle();
            var value   = bundle.Build();

            Assert.Null(value);
        }
        public void WithInvalidPathTest()
        {
            var builder = EnvironmentManager.Create(x => x.WithJsonFile("json1.json").WithJsonFile("json2.json"));
            var bundle  = builder.Json("--qwertz").Bundle();
            var value   = bundle.Build <string>();

            Assert.Null(value);
        }
Example #20
0
        public void WithBundleDescriptionTest()
        {
            var d      = "some description";
            var env    = EnvironmentManager.Create();
            var bundle = env.WithDescription(d).Default("foo").Bundle();

            Assert.True(new[] { d }.SequenceEqual(env.Bundles.GetDescriptions()));
        }
        public void WithSingleFileSingleStringKeyTest()
        {
            var builder = EnvironmentManager.Create(x => x.WithJsonFile("json1.json"));
            var bundle  = builder.Json("$.foo").Bundle();
            var value   = bundle.Build <string>();

            Assert.Equal("bar", value);
        }
        public void WithMultipleFilesSingleStringKeyWithExtensionTest()
        {
            var builder = EnvironmentManager.Create(x => x.WithJsonFile("json1.json").WithJsonFile("json2.json"));
            var bundle  = builder.Json("$(json1.json).foo").Bundle();
            var value   = bundle.Build <string>();

            Assert.Equal("bar", value);
        }
        public void WithEagerLoadedJsonFileTest()
        {
            var builder = EnvironmentManager.Create(x => x.WithJsonFile("json1.json", true));
            var parser  = builder.Configuration.GetValue <JsonFileParser>(typeof(JsonFileParser).FullName);

            Assert.Contains("json1.json", parser.Files.Keys);
            Assert.NotNull(parser.Files.Values.ElementAt(0).ParsedFile);
        }
        public void EnvironmentVariableExtensions()
        {
            Environment.SetEnvironmentVariable("option", "bar");
            Environment.SetEnvironmentVariable("prefix_option", "foo");
            var env = EnvironmentManager.Create(config => config.WithEnvironmentVariablePrefix("prefix_"));

            Assert.Equal("foo", env.Env("option").Build());
            Assert.Equal("bar", env.Env("option", c => c.WithNoEnvironmentVariablePrefix()).Build());
        }
        public void PipeConfigurationReadme2()
        {
            Random rnd = new Random();

            var env   = EnvironmentManager.Create(x => x.WithJsonFile("json3.json"));
            var value = env.Json("$").Build <Foo>();

            Assert.True(value is Foo f && f.Bar == "some value" && f.Baz == 2);
        }
        public void WithBuilderTest()
        {
            var builder = EnvironmentManager.Create(x => x.SetValue(typeof(ArgumentParser).FullName,
                                                                    new ArgumentParser("--foo foo --bar bar --baz baz"
                                                                                       .Split(' ').ToArray())));
            var value = builder.Arg("foo").Build();

            Assert.Equal("foo", value);
        }
Example #27
0
        public void CreateBundleWithGenericValueAndBuildAlt1Test()
        {
            var builder = EnvironmentManager.Create()
                          .WithSource(cfg => cfg.GetFactoryValue <string>("foo"),
                                      cfg => cfg.SetFactoryValue("foo", () => "foo"))
                          .Build();

            Assert.Equal("foo", builder);
        }
Example #28
0
        public void WithBundleDescriptionOnMultiConfiguration2Test()
        {
            var d   = "some description";
            var env = EnvironmentManager.Create();

            env.WithDescription(d).Default("foo").Bundle();
            env.Default("foo").Bundle();

            Assert.True(new[] { d, null }.SequenceEqual(env.Bundles.GetDescriptions()));
        }
Example #29
0
        static void Main(string[] args)
        {
            var settings = new Settings();

            settings.FillSettingsFromConfig();
            var context            = new Context(settings);
            var environmentManager = new EnvironmentManager();

            environmentManager.Create(context);
        }
        public void LoggingExtensions()
        {
            var writer = new TestOutputHelperWriter(_outputHelper);
            var env    = EnvironmentManager.Create(config =>
                                                   config
                                                   .WithTextWriterLogger(writer)
                                                   .WithLogLevel(EnvironmentBuilder.Abstractions.LogLevel.Trace));

            writer.TextWritten += (s, e) => Assert.True(e.Text == "[TRACE] Foo");
            env.LogTrace("Foo");
        }