public void ShouldReturnWordsSeparatedByNonwhiteSpaceCharacters() { var block = LineSplitter.GetLineSplitterBlock(); block.Post(new FileLinesEnumerator.FileLine(new File(), 1, "TEST1NAME")); var words = Enumerable.Repeat(1, 2).Select(_ => block.ReceiveWithTimeout()).ToList(); block.Complete(); block.EnsureCompleted(); Assert.IsTrue(words.Select(w => w.Word).SequenceEqual(new[] { "TEST", "NAME" })); }
public void ShouldReturnWordsInUppercase() { var block = LineSplitter.GetLineSplitterBlock(); block.Post(new FileLinesEnumerator.FileLine(new File(), 1, "Word")); var lineWord = block.ReceiveWithTimeout(); block.Complete(); block.EnsureCompleted(); Assert.AreEqual("WORD", lineWord.Word); }
public void ShouldReturnAllWordsWithPositionsFromInputString() { var block = LineSplitter.GetLineSplitterBlock(); block.Post(new FileLinesEnumerator.FileLine(new File(), 1, "МАМА МЫЛА РАМУ")); var words = Enumerable.Repeat(1, 3).Select(_ => block.ReceiveWithTimeout()).ToList(); block.Complete(); block.EnsureCompleted(); Assert.IsTrue(words.Select(w => w.Col).SequenceEqual(new[] { 1, 6, 11 })); Assert.IsTrue(words.Select(w => w.Word).SequenceEqual(new[] { "МАМА", "МЫЛА", "РАМУ" })); }
public void ShouldReturnWordAndItsPositionIfStringContainsSingleWordAndWhiteSpace() { var block = LineSplitter.GetLineSplitterBlock(); var file = new File(); block.Post(new FileLinesEnumerator.FileLine(file, 2, " WORD ")); var lineWord = block.ReceiveWithTimeout(); block.Complete(); block.EnsureCompleted(); Assert.AreSame(file, lineWord.File); Assert.AreEqual(2, lineWord.Row); Assert.AreEqual(4, lineWord.Col); Assert.AreEqual("WORD", lineWord.Word); }
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; }