Beispiel #1
0
    public void PassesPathToFileExists()
    {
        const string expectedPath = "foo_path";

        string pathValue = null;

        bool fileExists(string path) => (pathValue = path) != pathValue;

        EnvironmentProperties.Map(expectedPath, fileExists, null, null, null);
        pathValue.Should().Be(expectedPath);
    }
Beispiel #2
0
        public void DoesNotCallReadAllText()
        {
            string pathValue = null;

            bool fileExists(string path) => false;
            string readAllText(string path) => "all_text";

            EnvironmentProperties.Map(
                "foo_path", fileExists, readAllText, null, null);
            pathValue.Should().BeNull();
        }
Beispiel #3
0
            public void GetEnvironmentPropertiesIsNotCalled()
            {
                string rawValue = null;

                bool fileExists(string path) => true;
                string readAllText(string path) => throw new Exception();
                IEnumerable <(string, string)> getEnvironmentProperties(string raw) =>
                (rawValue = raw) == rawValue?Enumerable.Empty <(string, string)>() : null;

                EnvironmentProperties.Map(
                    "foo_path", fileExists, readAllText, getEnvironmentProperties, null);
                rawValue.Should().BeNull();
            }
Beispiel #4
0
        public void PassesAllTextToGetEnvironmentProperties()
        {
            const string allText = "all_text";

            string rawValue = null;

            bool fileExists(string path) => true;
            string readAllText(string path) => allText;
            IEnumerable <(string, string)> getEnvironmentProperties(string raw) =>
            (rawValue = raw) == rawValue?Enumerable.Empty <(string, string)>() : null;

            EnvironmentProperties.Map(
                "foo_path", fileExists, readAllText, getEnvironmentProperties, null);
            rawValue.Should().Be(allText);
        }
Beispiel #5
0
        public void PassesPathToReadAllText()
        {
            const string expectedPath = "foo_path";

            string pathValue = null;

            bool fileExists(string path) => true;
            string readAllText(string path) => pathValue = path;
            IEnumerable <(string, string)> getEnvironmentProperties(string raw) =>
            Enumerable.Empty <(string, string)>();

            EnvironmentProperties.Map(
                expectedPath, fileExists, readAllText, getEnvironmentProperties, null);
            pathValue.Should().Be(expectedPath);
        }
Beispiel #6
0
        public void DoesNotCallSetEnvironmentVariable()
        {
            var expectedEnvironmentProperties = new List <(string, string)>
            {
                ("foo", "bar"),
                ("baz", "qux")
            };
            var actualEnvironmentProperties = new List <(string, string)>();

            bool fileExists(string path) => false;
            string readAllText(string path) => "all_text";
            IEnumerable <(string, string)> getEnvironmentProperties(string raw) => expectedEnvironmentProperties;
            void setEnvironmentVariable(string variable, string value) =>
            actualEnvironmentProperties.Add((variable, value));

            EnvironmentProperties.Map(
                "foo_path", fileExists, readAllText, getEnvironmentProperties, setEnvironmentVariable);
            actualEnvironmentProperties.Should().BeEmpty();
        }