public void GetEnvironmentValidPaths()
        {
            string pathVariable = string.Join(_separator, GetValidPaths().Concat(GetInvalidPaths()));

            _environment.GetEnvironmentVariable("PATH").Returns(pathVariable);

            var validPaths = _provider.GetEnvironmentValidPaths();

            CollectionAssert.AreEqual(GetValidPaths().ToArray(), validPaths.ToArray());
        }
Ejemplo n.º 2
0
        public static bool TryFindFullPath([NotNull] string fileName, out string fullPath)
        {
            try
            {
                if (File.Exists(fileName))
                {
                    fullPath = Path.GetFullPath(fileName);
                    return(true);
                }

                foreach (var path in EnvironmentPathsProvider.GetEnvironmentValidPaths())
                {
                    fullPath = Path.Combine(path, fileName);
                    if (File.Exists(fullPath))
                    {
                        return(true);
                    }
                }
            }
            catch
            {
                // do nothing
            }

            fullPath = null;
            return(false);
        }
Ejemplo n.º 3
0
        public static bool TryFindFullPath(string fileName, [NotNullWhen(returnValue: true)] out string?fullPath)
        {
            try
            {
                if (File.Exists(fileName))
                {
                    fullPath = Path.GetFullPath(fileName);
                    return(true);
                }

                foreach (var path in EnvironmentPathsProvider.GetEnvironmentValidPaths())
                {
                    fullPath = Combine(path, fileName);
                    if (File.Exists(fullPath))
                    {
                        // TODO remove suppression when targeting .NET 5
#pragma warning disable CS8762 // Parameter must have a non-null value when exiting in some condition.
                        return(true);

#pragma warning restore CS8762 // Parameter must have a non-null value when exiting in some condition.
                    }
                }
            }
            catch
            {
                // do nothing
            }

            fullPath = null;
            return(false);
        }