Beispiel #1
0
 public void ShouldFailForUnreadableStream()
 {
     using (var stream = new TweakableStream(Stream.Null))
     {
         stream.SetCanRead(false);
         Assert.Throws <ArgumentException>("csvStream", () => CsvAsyncInput.ForStream(stream));
     }
 }
Beispiel #2
0
        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));
        }
Beispiel #3
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);
        }
Beispiel #4
0
        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));
        }
Beispiel #5
0
        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));
                }
            }
        }