public void ShouldFailIfFolderDoesNotExist() { try { var block = FilesEnumerator.GetFilesEnumeratorBlock(); block.Post(new FilesEnumerator.EnumerateFolderTask { Folder = "UnexistingFolder", SearchPattern = "*.txt" }); block.EnsureCompleted(); Assert.Fail(); } catch (AggregateException ex) { Assert.IsInstanceOfType(ex.GetBaseException(), typeof(DirectoryNotFoundException)); } }
public void ShouldEnumerateTextFilesInAllSubfolders() { var block = FilesEnumerator.GetFilesEnumeratorBlock(); block.Post(new FilesEnumerator.EnumerateFolderTask { Folder = "TestFolder", SearchPattern = "*.txt" }); block.Complete(); var files = Enumerable.Repeat(1, 3).Select(_ => block.Receive(TimeSpan.FromMilliseconds(100))).ToList(); block.EnsureCompleted(); Assert.IsTrue( files.OrderBy(f => f).SequenceEqual(new[] { @"TestFolder\Subfolder\TextFile2.txt", @"TestFolder\Subfolder\TextFile3.txt", @"TestFolder\TextFile1.txt" })); }
public async Task ParseFilesAsync(string folderPath, string searchPattern) { var repository = repositoryFactory(); await repository.TruncateDataAsync(); var filesEnumerator = FilesEnumerator.GetFilesEnumeratorBlock(); var fileCreator = FileCreator.GetFileCreatorBlock(); filesEnumerator.LinkToAndPropagateCompleted(fileCreator); var fileLinesEnumerator = FileLinesEnumerator.GetFileLinesEnumeratorBlock(); fileCreator.LinkToAndPropagateCompleted(fileLinesEnumerator); var lineSplitter = LineSplitter.GetLineSplitterBlock(); fileLinesEnumerator.LinkToAndPropagateCompleted(lineSplitter); var fileWordCreator = FileWordCreator.GetFileWordCreatorBlock(); lineSplitter.LinkToAndPropagateCompleted(fileWordCreator); var fileWordSaver = FileWordSaver.GetFileWordSaverBlock(repositoryFactory); fileWordCreator.LinkToAndPropagateCompleted(fileWordSaver); var nullTarget = DataflowBlock.NullTarget <FileWord>(); fileWordSaver.LinkTo(nullTarget); filesEnumerator.Post(new FilesEnumerator.EnumerateFolderTask { Folder = folderPath, SearchPattern = searchPattern }); filesEnumerator.Complete(); await fileWordSaver.Completion; }