public async Task ReadSourceFileOperation() { var inputFilePath = await TestsHelper.CreateFile($"{Guid.NewGuid().ToString()}.txt", DataStorage.ExpectedData1); var channel = Channel.CreateUnbounded <string>(); var fileOperation = new ReadSourceFileOperation(inputFilePath, TestsHelper.GetSettings(), channel.Writer); fileOperation.ExecuteAsync(); var items = await channel.Reader.ReadAllAsync().ToListAsync(); var data = items.Select(x => x).ToList(); CollectionAssert.AreEqual(new List <string>() { "1. Apple", "415. Apple", "2. Banana is yellow", "2. Banana is yellow", "32. Cherry is the best", "30432. Something something something", "0. Windows", }, data); }
public async Task <IOperation> GetOperationAsync() { IOperation operation = null; if (_operationCounter == 0) { operation = new ReadSourceFileOperation(_pathsHelper.SourceFile.FullName, _settings, _sourceFileChannel.Writer); } else if (_operationCounter <= _operationsCount) { operation = new CreateChunkFilesOperation(_sourceFileChannel.Reader, _chunksChannel.Writer, _pathsHelper, _settings); } else if (await _chunksChannel.Reader.WaitToReadAsync().ConfigureAwait(false)) { try { var file1 = await _chunksChannel.Reader.ReadAsync().ConfigureAwait(false); var file2 = await _chunksChannel.Reader.ReadAsync().ConfigureAwait(false); operation = new MergeChunksOperation(_chunksChannel, file1, file2, _pathsHelper); } catch (ChannelClosedException) { } } _operationCounter++; return(operation); }
public async Task ReadSourceFileOperation_2() { var fileName = $"{Guid.NewGuid().ToString()}.txt"; var inputFilePath = await TestsHelper.CreateFile(fileName, "1. Apple\r\n"); var channel = Channel.CreateUnbounded <string>(); var fileOperation = new ReadSourceFileOperation(inputFilePath, TestsHelper.GetSettings(), channel.Writer); fileOperation.ExecuteAsync(); var items = await channel.Reader.ReadAllAsync().ToListAsync(); var data = items.Select(x => x).ToList(); CollectionAssert.AreEqual(new List <string>() { "1. Apple" }, data); }