<commit_before>using System;
using EasyConfig.Attributes;
using EasyConfig.Exceptions;
using NUnit.Framework;
#pragma warning disable 649

namespace EasyConfig.UnitTests
{
    [TestFixture]
    public class ConfigTests
    {
        private const string EnvironmentVariableTestKey = "EasyConfig_this_environment_variable_should_only_exist_during_these_tests";

        [SetUp]
        public void SetUp()
        {
            Environment.SetEnvironmentVariable(EnvironmentVariableTestKey, Guid.NewGuid().ToString());
        }

        [TearDown]
        public void TearDown()
        {
            Environment.SetEnvironmentVariable(EnvironmentVariableTestKey, null);
        }

        [Test]
        public void Populate_Object_GivenValidArgs_DoesntThrow()
        {
            Assert.DoesNotThrow(() => Config.Populate<object>());
        }

        [Test]
        public void Populate_UriRequired_GivenDgApiEndpoint_DoesntThrow()
        {
            Assert.DoesNotThrow(() => Config.Populate<UriRequired>("endpoint=http://www.google.com"));
        }

        [Test]
        public void Populate_UriRequired_GivenDgApiEndpoint_SetsApiEndpoint()
        {
            var parameters = Config.Populate<UriRequired>("endpoint=http://www.google.com");

            Assert.That(parameters.Test, Is.Not.Null);
        }

        [Test]
        public void Populate_UriRequired_GivenAUri_SetsUriCorrectly()
        {
            var endpoint = new Uri("http://www.google.com");
            var parameters = Config.Populate<UriRequired>($"endpoint={endpoint}");

            Assert.That(parameters.Test, Is.EqualTo(endpoint));
        }

        [Test]
        public void Populate_UriRequired_GivenNotAUri_Throws()
        {
            Assert.Throws<ConfigurationTypeException>(() => Config.Populate<UriRequired>("endpoint=notanendpoint"));
        }

        [Test]
        public void Populate_UriRequired_NotGivenRequiredParameter_Throws()
        {
            Assert.Throws<ConfigurationMissingException>(() => Config.Populate<UriRequired>());
        }

        [Test]
        public void Populate_InEnvironmentVariabless_RequiredParamInEnvironment_DoesntThrow()
        {
            Assert.DoesNotThrow(() => Config.Populate<InEnvironmentVariables>());
        }

        [Test]
        public void Populate_NotInEnvironmentVariables_RequiredParamNotInEnvironment_Throws()
        {
            Assert.Throws<ConfigurationMissingException>(() => Config.Populate<NotInEnvironmentVariables>());
        }

        [Test]
        public void Populate_NotInEnvironmentVariables_RequiredParamNotInEnvironmentButInArgs_Throws()
        {
            Assert.Throws<ConfigurationMissingException>(() => Config.Populate<NotInEnvironmentVariables>("defninitely_not_in_environment_variables=shouldstillthrow"));
        }

        [Test]
        public void Populate_NotRequired_ParamNotInEnvironmentButInArgs_DoesNotThrow()
        {
            Assert.DoesNotThrow(() => Config.Populate<NotRequired>());
        }

        [Test]
        public void Populate_HasDefault_UsesDefault()
        {
            var config = Config.Populate<HasDefault>();

            Assert.That(config.Test, Is.EqualTo("defaulttest"));
        }

        [Test]
        public void Populate_IntRequired_DoesNotThrow()
        {
            Assert.DoesNotThrow(() => Config.Populate<IntRequired>("number=1"));
        }

        [Test]
        public void Populate_IntRequired_ExtraParameters_DoesNotThrow()
        {
            Assert.DoesNotThrow(() => Config.Populate<IntRequired>("number=1", "unexpected-positional-argument"));
        }

        [Test]
        public void Populate_IntRequired_SetsNumber()
        {
            var num = new Random().Next();
            var config = Config.Populate<IntRequired>("number=" + num);

            Assert.That(config.Test, Is.EqualTo(num));
        }

        [Test]
        public void Populate_IntRequired_GivenNotAnInt_Throws()
        {
            Assert.Throws<ConfigurationTypeException>(() => Config.Populate<IntRequired>("number=notaninteger"));
        }

        [Test]
        public void Populate_AliasDefined_GivenValid_Sets()
        {
            var config = Config.Populate<AliasDefined>("a=aliased");

            Assert.That(config.Test, Is.EqualTo("aliased"));
        }

        private class UriRequired
        {
            [EnvironmentOrCommandLine("endpoint"), Required]
            public Uri Test;
        }

        private class IntRequired
        {
            [EnvironmentOrCommandLine("number"), Required]
            public int Test;
        }

        private class InEnvironmentVariables
        {
            [Environment(EnvironmentVariableTestKey), Required]
            public string Test;
        }

        private class NotInEnvironmentVariables
        {
            [Environment("shouldnt_be_in_environment_variables"), Required]
            public string Test;
        }

        private class NotRequired
        {
            [Environment("shouldnt_be_in_environment_variables")]
            public string Test;
        }

        private class HasDefault
        {
            [Environment("shouldnt_be_in_environment_variables"), Default("defaulttest")]
            public string Test;
        }

        private class AliasDefined
        {
            [CommandLine("unaliased", "a")]
            public string Test;
        }
    }
}<commit_msg>start adding support for properties<commit_after>using System;
using EasyConfig.Attributes;
using EasyConfig.Exceptions;
using NUnit.Framework;
#pragma warning disable 649

namespace EasyConfig.UnitTests
{
    [TestFixture]
    public class ConfigTests
    {
        private const string EnvironmentVariableTestKey = "EasyConfig_this_environment_variable_should_only_exist_during_these_tests";

        [SetUp]
        public void SetUp()
        {
            Environment.SetEnvironmentVariable(EnvironmentVariableTestKey, Guid.NewGuid().ToString());
        }

        [TearDown]
        public void TearDown()
        {
            Environment.SetEnvironmentVariable(EnvironmentVariableTestKey, null);
        }

        [Test]
        public void Populate_Object_GivenValidArgs_DoesntThrow()
        {
            Assert.DoesNotThrow(() => Config.Populate<object>());
        }

        [Test]
        public void Populate_UriRequired_GivenDgApiEndpoint_DoesntThrow()
        {
            Assert.DoesNotThrow(() => Config.Populate<UriRequired>("endpoint=http://www.google.com"));
        }

        [Test]
        public void Populate_UriRequired_GivenDgApiEndpoint_SetsApiEndpoint()
        {
            var parameters = Config.Populate<UriRequired>("endpoint=http://www.google.com");

            Assert.That(parameters.Test, Is.Not.Null);
        }

        [Test]
        public void Populate_UriRequired_GivenAUri_SetsUriCorrectly()
        {
            var endpoint = new Uri("http://www.google.com");
            var parameters = Config.Populate<UriRequired>($"endpoint={endpoint}");

            Assert.That(parameters.Test, Is.EqualTo(endpoint));
        }

        [Test]
        public void Populate_UriRequired_GivenNotAUri_Throws()
        {
            Assert.Throws<ConfigurationTypeException>(() => Config.Populate<UriRequired>("endpoint=notanendpoint"));
        }

        [Test]
        public void Populate_UriRequired_NotGivenRequiredParameter_Throws()
        {
            Assert.Throws<ConfigurationMissingException>(() => Config.Populate<UriRequired>());
        }

        [Test]
        public void Populate_InEnvironmentVariabless_RequiredParamInEnvironment_DoesntThrow()
        {
            Assert.DoesNotThrow(() => Config.Populate<InEnvironmentVariables>());
        }

        [Test]
        public void Populate_NotInEnvironmentVariables_RequiredParamNotInEnvironment_Throws()
        {
            Assert.Throws<ConfigurationMissingException>(() => Config.Populate<NotInEnvironmentVariables>());
        }

        [Test]
        public void Populate_NotInEnvironmentVariables_RequiredParamNotInEnvironmentButInArgs_Throws()
        {
            Assert.Throws<ConfigurationMissingException>(() => Config.Populate<NotInEnvironmentVariables>("defninitely_not_in_environment_variables=shouldstillthrow"));
        }

        [Test]
        public void Populate_NotRequired_ParamNotInEnvironmentButInArgs_DoesNotThrow()
        {
            Assert.DoesNotThrow(() => Config.Populate<NotRequired>());
        }

        [Test]
        public void Populate_HasDefault_UsesDefault()
        {
            var config = Config.Populate<HasDefault>();

            Assert.That(config.Test, Is.EqualTo("defaulttest"));
        }

        [Test]
        public void Populate_IntRequired_DoesNotThrow()
        {
            Assert.DoesNotThrow(() => Config.Populate<IntRequired>("number=1"));
        }

        [Test]
        public void Populate_IntRequired_ExtraParameters_DoesNotThrow()
        {
            Assert.DoesNotThrow(() => Config.Populate<IntRequired>("number=1", "unexpected-positional-argument"));
        }

        [Test]
        public void Populate_IntRequired_SetsNumber()
        {
            var num = new Random().Next();
            var config = Config.Populate<IntRequired>("number=" + num);

            Assert.That(config.Test, Is.EqualTo(num));
        }

        [Test]
        public void Populate_IntRequired_GivenNotAnInt_Throws()
        {
            Assert.Throws<ConfigurationTypeException>(() => Config.Populate<IntRequired>("number=notaninteger"));
        }

        [Test]
        public void Populate_AliasDefined_GivenValid_Sets()
        {
            var config = Config.Populate<AliasDefined>("a=aliased");

            Assert.That(config.Test, Is.EqualTo("aliased"));
        }

        [Test]
        public void Populate_Property_GivenValid_Sets()
        {
            var config = Config.Populate<PublicGetterSetter>("property=value");

            Assert.That(config.Test, Is.EqualTo("value"));
        }

        private class UriRequired
        {
            [EnvironmentOrCommandLine("endpoint"), Required]
            public Uri Test;
        }

        private class IntRequired
        {
            [EnvironmentOrCommandLine("number"), Required]
            public int Test;
        }

        private class InEnvironmentVariables
        {
            [Environment(EnvironmentVariableTestKey), Required]
            public string Test;
        }

        private class NotInEnvironmentVariables
        {
            [Environment("shouldnt_be_in_environment_variables"), Required]
            public string Test;
        }

        private class NotRequired
        {
            [Environment("shouldnt_be_in_environment_variables")]
            public string Test;
        }

        private class HasDefault
        {
            [Environment("shouldnt_be_in_environment_variables"), Default("defaulttest")]
            public string Test;
        }

        private class AliasDefined
        {
            [CommandLine("unaliased", "a")]
            public string Test;
        }

        private class PublicGetterSetter
        {
            [CommandLine("property")]
            public string Test { get; set; }
        }
    }
}
{'fraction_non_alphanumeric': 0.09612141652613827, 'fraction_numerical': 0.0008875477056891808, 'mean_word_length': 2.3386666666666667, 'pattern_counts': {'":': 0, '<': 46, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '346685', 'n_tokens_mistral': 2908, 'n_tokens_neox': 2832, 'n_words': 444}