public void ShouldFailForUnreadableStream() { using (var stream = new TweakableStream(Stream.Null)) { stream.SetCanRead(false); Assert.Throws <ArgumentException>("csvStream", () => CsvAsyncInput.ForStream(stream)); } }
public void FluentConfigurationShouldValidateInputs() { var sut = CsvAsyncInput.ForStream(null); Assert.Throws <ArgumentException>("delimiter", () => sut.WithDelimiter((byte)'"')); Assert.Throws <ArgumentException>("delimiter", () => sut.WithDelimiter((byte)'\r')); Assert.Throws <ArgumentException>("delimiter", () => sut.WithDelimiter((byte)'\n')); Assert.Throws <ArgumentOutOfRangeException>("minReadBufferByteCount", () => sut.WithMinReadBufferByteCount(-1)); Assert.Throws <ArgumentOutOfRangeException>("minReadBufferByteCount", () => sut.WithMinReadBufferByteCount(0)); }
public async Task <long> CountRowsUsingCursivelyAsyncFileStreamInput(CsvFile csvFile) { var visitor = new RowCountingVisitor(); using (var stream = new FileStream(csvFile.FullPath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.Asynchronous | FileOptions.SequentialScan)) { await CsvAsyncInput.ForStream(stream).ProcessAsync(visitor); } return(visitor.RowCount); }
public async Task FluentConfigurationShouldFailAfterProcessing() { var sut = CsvAsyncInput.ForStream(null); await sut.ProcessAsync(null).ConfigureAwait(true); // shouldn't be able to further configure a Stream input after processing starts... Assert.Throws <InvalidOperationException>(() => sut.WithDelimiter((byte)'\t')); Assert.Throws <InvalidOperationException>(() => sut.WithIgnoreUTF8ByteOrderMark(false)); Assert.Throws <InvalidOperationException>(() => sut.WithMinReadBufferByteCount(5)); Assert.Throws <InvalidOperationException>(() => sut.WithReadBufferPool(null)); }
public async Task IgnoreUTF8BOM(string filePath, int chunkLength) { // arrange filePath = Path.Combine(TestCsvFilesFolderPath, filePath); using (var stream = File.OpenRead(filePath)) { // act, assert await RunTestAsync(CreateSut, filePath, true).ConfigureAwait(true); CsvAsyncInputBase CreateSut() { stream.Position = 0; return(CsvAsyncInput.ForStream(stream) .WithMinReadBufferByteCount(chunkLength) .WithIgnoreUTF8ByteOrderMark(true)); } } }