コード例 #1
0
        public void FluentConfigurationShouldValidateInputs()
        {
            var sut = CsvAsyncInput.ForPipeReader(null);

            Assert.Throws <ArgumentException>("delimiter", () => sut.WithDelimiter((byte)'"'));
            Assert.Throws <ArgumentException>("delimiter", () => sut.WithDelimiter((byte)'\r'));
            Assert.Throws <ArgumentException>("delimiter", () => sut.WithDelimiter((byte)'\n'));
        }
コード例 #2
0
 public void ShouldFailForUnreadableStream()
 {
     using (var stream = new TweakableStream(Stream.Null))
     {
         stream.SetCanRead(false);
         Assert.Throws <ArgumentException>("csvStream", () => CsvAsyncInput.ForStream(stream));
     }
 }
コード例 #3
0
        public async Task FluentConfigurationShouldFailAfterProcessing()
        {
            var sut = CsvAsyncInput.ForPipeReader(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));
        }
コード例 #4
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));
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: JavierCanon/Dalayer.net
        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);
        }
コード例 #6
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));
                }
            }
        }
コード例 #7
0
        public async Task IgnoreUTF8BOM(string filePath, int chunkLength)
        {
            // arrange
            filePath = Path.Combine(TestCsvFilesFolderPath, filePath);

            if (new FileInfo(filePath).Length == 0)
            {
                // Pipelines.Sockets.Unofficial seems to fail here.
                return;
            }

            // act, assert
            await RunTestAsync(CreateSut, filePath, true).ConfigureAwait(true);

            CsvAsyncInputBase CreateSut()
            {
                var pipeReader = MemoryMappedPipeReader.Create(filePath, chunkLength);

                return(CsvAsyncInput.ForPipeReader(pipeReader)
                       .WithIgnoreUTF8ByteOrderMark(true));
            }
        }