示例#1
0
        public void Check_For_Nullable()
        {
            var dict = new Dictionary <string, string>
            {
                { "Test", "20" },
                { "TestBool", "true" }
            };

            EnvironmentVariableSource.SetEnvironment(dict);
            EnvironmentVariableRepository.SetConfigurationType(ConfigurationTypeEnum.PreferEnvironment);
            var output = ConfigurationParser.Parse <NullableClass>(EnvironmentVariableRepository);

            Assert.Equal(20, output.Test);
            Assert.True(output.TestBool);
            Assert.Null(output.NotRequired);
        }
示例#2
0
        public void Environment_Only()
        {
            var values = new[]
            {
                "Test=fromFile",
            };

            var dict = new Dictionary <string, string>
            {
                { "Test", "fromEnv" }
            };

            EnvironmentVariableSource.SetEnvironment(dict);
            FileSource.SetEnvironment(values);
            EnvironmentVariableRepository.SetConfigurationType(ConfigurationTypeEnum.EnvironmentOnly);
            var output = ConfigurationParser.Parse <ConfigurationClass>(EnvironmentVariableRepository);

            Assert.Equal("fromEnv", output.Test);
        }
示例#3
0
        public void Can_Write_To_File()
        {
            var dict = new Dictionary <string, string>
            {
                { "Test", "20" },
                { "TestBool", "true" }
            };

            EnvironmentVariableSource.SetEnvironment(dict);
            EnvironmentVariableRepository.SetConfigurationType(ConfigurationTypeEnum.PreferEnvironment);
            var output = ConfigurationParser.Parse <NullableClass>(EnvironmentVariableRepository);

            ConfigurationWriter.WriteToFile(output, "cwtf.txt", true);

            // Read in that file.
            var parsedConfig = ConfigurationParser.Parse <NullableClass>("cwtf.txt");

            Assert.Equal(20, parsedConfig.Test);
            Assert.True(parsedConfig.TestBool);
        }
示例#4
0
        public void Prefer_File_Over_Environment()
        {
            var values = new[]
            {
                "Test=fromFile",
                "test=fromFile"
            };

            var dict = new Dictionary <string, string>
            {
                { "Test", "fromEnv" },
            };

            EnvironmentVariableSource.SetEnvironment(dict);
            FileSource.SetEnvironment(values);
            EnvironmentVariableRepository.SetConfigurationType(ConfigurationTypeEnum.PreferFile);
            var output = ConfigurationParser.Parse <PreferClass>(EnvironmentVariableRepository);

            Assert.Equal("fromFile", output.Test);
            Assert.Equal("fromFile", output.test);
        }