static void AssertEqualForAllMethods(string?expected, string fileName, IReadOnlyList <string> searchPath)
 {
     Assert.Equal(expected, SearchPathSearcher.FindFile(fileName, false, null));
     Assert.Equal(expected, SearchPathSearcher.FindFile(fileName, true, null));
     Assert.Equal(expected, SearchPathSearcher.FindFile(fileName, false, searchPath));
     Assert.Equal(expected, SearchPathSearcher.FindFile(fileName, true, searchPath));
 }
        public void CanFindFile()
        {
            using var temp = new TemporaryDirectory();
            var searchPath = new string[] { temp.Location, Path.Join(temp.Location, "dir") };

            // temp / randomName
            // temp / dir / a
            // temp / dir / randomName
            // temp / dir2 / a (not included in the search path)
            // cwd / randomName
            var randomName = Path.GetRandomFileName();

            Directory.CreateDirectory(Path.Join(temp.Location, "dir"));
            Directory.CreateDirectory(Path.Join(temp.Location, "dir2"));
            CreateEmptyFile(Path.Join(temp.Location, randomName));
            CreateEmptyFile(Path.Join(temp.Location, "dir", "a"));
            CreateEmptyFile(Path.Join(temp.Location, "dir", randomName));
            CreateEmptyFile(Path.Join(temp.Location, "dir2", "a"));
            CreateEmptyFile(Path.Join(Environment.CurrentDirectory, randomName));

            // No path separator
            // Not found
            Assert.Null(
                SearchPathSearcher.FindFile(randomName, false, null));
            // Found from the search path
            Assert.Equal(
                Path.Join(temp.Location, randomName),
                SearchPathSearcher.FindFile(randomName, false, searchPath));
            // Found from the current directory
            Assert.Equal(
                Path.Join(Environment.CurrentDirectory, randomName),
                SearchPathSearcher.FindFile(randomName, true, null));
            Assert.Equal(
                Path.Join(Environment.CurrentDirectory, randomName),
                SearchPathSearcher.FindFile(randomName, true, searchPath));

            // Relative path
            Assert.Equal(
                Path.Join(Environment.CurrentDirectory, ".", randomName),
                SearchPathSearcher.FindFile(Path.Join(".", randomName), true, searchPath));
            Assert.Null(
                SearchPathSearcher.FindFile(Path.Join(".", randomName), false, searchPath));

            // Absolute path
            AssertEqualForAllMethods(
                Path.Join(temp.Location, randomName),
                Path.Join(temp.Location, randomName),
                searchPath);
            AssertEqualForAllMethods(
                Path.Join(temp.Location, "dir2", randomName),
                Path.Join(temp.Location, "dir2", randomName),
                searchPath);