public FileSystemVisitorTest() { _rootDirectoryPath = @"C:\"; _filesAndDirectories = new List <VisitedFileSystemEntity> { new VisitedFileSystemEntity { EntityType = VisitedFileSystemEntityType.Directory, EntityPath = @"D:\TestFolder" }, new VisitedFileSystemEntity { EntityType = VisitedFileSystemEntityType.File, EntityPath = @"D:\TestFolder\TestFile1.txt" }, new VisitedFileSystemEntity { EntityType = VisitedFileSystemEntityType.File, EntityPath = @"D:\TestFolder\TestFile2.jpg" }, new VisitedFileSystemEntity { EntityType = VisitedFileSystemEntityType.Directory, EntityPath = @"D:\TestFolder\TestSubfolder" }, new VisitedFileSystemEntity { EntityType = VisitedFileSystemEntityType.Directory, EntityPath = @"D:\TestFolder\TestSubfolder\TestsubSubfolder" }, new VisitedFileSystemEntity { EntityType = VisitedFileSystemEntityType.File, EntityPath = @"D:\TestFolder\TestSubfolder\TestFile1.txt" }, new VisitedFileSystemEntity { EntityType = VisitedFileSystemEntityType.File, EntityPath = @"D:\TestFolder\TestSubfolder\TestFile2.jpg" } }; _fileSystemEntitiesProvider = A.Fake <IFileSystemEntitiesProvider>(); A.CallTo(() => _fileSystemEntitiesProvider.GetFileSystemEntities(A <string> ._)).Returns(_filesAndDirectories); }
public IEnumerable <VisitedFileSystemEntity> GetResultOfBypassingDirectories(string rootDirectoryPath) { if (string.IsNullOrEmpty(rootDirectoryPath) || rootDirectoryPath.IndexOfAny(Path.GetInvalidPathChars()) >= 0 || !Directory.Exists(rootDirectoryPath)) { throw new ArgumentException($"Passed rootDirectoryPath {rootDirectoryPath} is not valid."); } OnStartBypassing(); foreach (var visitedEntity in _fileSystemEntitiesProvider.GetFileSystemEntities(rootDirectoryPath)) { var args = new FileSystemVisitorEventArgs(); OnEntityFound(visitedEntity, args); if (_bypassingFilter(visitedEntity)) { OnFilteredEntityFound(visitedEntity, args); if (args.ShouldStopSearch) { break; } if (args.ShouldExcludeResult) { continue; } yield return(visitedEntity); } } OnFinishBypassing(); }