Exemple #1
0
        public void Should_Find_Source_File_Names()
        {
            FileCrawler fileCrawler = CreateFileCrawler();
            string      directory   = "TestData";

            _subDirectoryReader.GetFiles("TestData", "*.cs").Returns(new string[] { @"TestData\TestData.cs" });
            _subDirectoryReader.GetDirectories("TestData").Returns(new string[] { @"TestData\TestDataSubDirectory" });
            _subDirectoryReader.GetFiles(@"TestData\TestDataSubDirectory", "*.cs").Returns(new string[] { @"TestData\TestDataSubDirectory\SubTestData.cs" });
            _subDirectoryReader.GetDirectories(@"TestData\TestDataSubDirectory").Returns(Array.Empty <string>());
            var expectedResult = new List <string>()
            {
                @"TestData\TestData.cs",
                @"TestData\TestDataSubDirectory\SubTestData.cs"
            };

            IEnumerable <string> result = fileCrawler.FindSourceFileNames(
                directory);

            result.Should().BeEquivalentTo(expectedResult);
        }
Exemple #2
0
 public IEnumerable <string> FindSourceFileNames(string directory)
 {
     foreach (string filePath in _directoryReader.GetFiles(directory, "*.cs"))
     {
         yield return(filePath);
     }
     foreach (string directoryPath in _directoryReader.GetDirectories(directory))
     {
         foreach (string filePath in FindSourceFileNames(directoryPath))
         {
             yield return(filePath);
         }
     }
 }
        /// <summary>
        /// Looks for new subdirectories that are not included in those searched.
        /// </summary>
        /// <remarks>
        /// TODO: Should not be using ExcludedFileNames to check whether the directory should be added.
        /// </remarks>
        List <WixPackageFilesDiffResult> GetNewDirectories()
        {
            List <WixPackageFilesDiffResult> results = new List <WixPackageFilesDiffResult>();

            string[] directories = new string[searchedDirectories.Count];
            searchedDirectories.CopyTo(directories);
            foreach (string directory in directories)
            {
                foreach (string subDirectory in directoryReader.GetDirectories(directory))
                {
                    DirectoryInfo dirInfo = new DirectoryInfo(subDirectory);
                    if (!excludedFileNames.IsExcluded(dirInfo.Name))
                    {
                        if (!HasDirectoryBeenSearched(subDirectory))
                        {
                            results.Add(new WixPackageFilesDiffResult(subDirectory, WixPackageFilesDiffResultType.NewDirectory));
                        }
                    }
                }
            }
            return(results);
        }
        private IEnumerable <string> VisitDirectory(string path, VisitState visitState)
        {
            var visitArgs = new VisitArgs(path);

            OnDirectoryFound(visitArgs);
            if (visitArgs.StopSearch)
            {
                visitState.SearchFinished = true;
            }

            if (!IsFiltered(path))
            {
                yield break;
            }

            OnFilteredDirectoryFound(visitArgs);
            if (visitArgs.StopSearch)
            {
                visitState.SearchFinished = true;
            }

            yield return(path);

            foreach (var visitPath in _directoryReader.GetDirectories(path).SelectMany(p => VisitDirectory(p, visitState)))
            {
                yield return(visitPath);
            }

            foreach (var filePath in _directoryReader.GetFiles(path))
            {
                if (VisitFile(filePath, visitState) == filePath)
                {
                    yield return(filePath);
                }
            }
        }