Exemplo n.º 1
0
        public async Task ReadAllAsync_WithoutHeaders_ReturnRecords()
        {
            const string input = "1;2;3\r\n4;5;6";

            var transformer = new NullTransformerForAdapterTesting
                              (
                expectedAliases: null,
                expectedResults: new[]
            {
                new[] { "1", "2", "3" },
                new[] { "4", "5", "6" }
            }
                              );

            using (var dialect = new Dialect
            {
                DoubleQuote = true,
                Delimiter = ';',
                Quote = '"',
                Escape = '\\',
                SkipInitialSpace = true,
                LineTerminator = "\n\r",
                Quoting = QuoteStyle.QuoteNone,
                Strict = true,
                HasHeader = false
            })
            {
                using (var adapter = new CSVAdapter(dialect, new StringReader(input)))
                {
                    await adapter.ReadAllAsync(transformer);
                }
            }
        }
Exemplo n.º 2
0
        public async Task ReadAllAsync_ExistingFileName_ReturnsRecords()
        {
            var filename = Path.Combine(TestContext.CurrentContext.TestDirectory, "test.csv");

            var transformer = new NullTransformerForAdapterTesting
                              (
                new[] { "Header#1", "Header#2", "Header#3" },
                new[]
            {
                new [] { "1", "2", "3" },
                new [] { "4", "5", "6" }
            }
                              );

            using (var dialect = new Dialect
            {
                DoubleQuote = true,
                Delimiter = ';',
                Quote = '"',
                Escape = '\\',
                SkipInitialSpace = true,
                LineTerminator = "\n\r",
                Quoting = QuoteStyle.QuoteNone,
                Strict = true,
                HasHeader = true
            })
            {
                using (var adapter = new CSVAdapter(dialect, filename, "utf-8"))
                {
                    await adapter.ReadAllAsync(transformer);
                }
            }
        }
Exemplo n.º 3
0
        public async Task ReadAllAsync_ExistingStream_ReturnsRecords()
        {
            const string input = "Header#1;Header#2;Header#3\r\n1;2;3\r\n4;5;6";

            var transformer = new NullTransformerForAdapterTesting
                              (
                new[] { "Header#1", "Header#2", "Header#3" },
                new[]
            {
                new[] { "1", "2", "3" },
                new[] { "4", "5", "6" }
            }
                              );

            using (var dialect = new Dialect
            {
                DoubleQuote = true,
                Delimiter = ';',
                Quote = '"',
                Escape = '\\',
                SkipInitialSpace = true,
                LineTerminator = "\n\r",
                Quoting = QuoteStyle.QuoteNone,
                Strict = true,
                HasHeader = true
            })
            {
                using (var adapter = new CSVAdapter(dialect, new StringReader(input)))
                {
                    await adapter.ReadAllAsync(transformer);
                }
            }
        }