public void When_cells_are_empty_they_must_be_exposed_as_empty()
        {
            // Arrange
            string emptyCellValue = string.Empty;

            using DelimitedValuesReader reader = new DelimitedValuesReaderBuilder()
                                                 .WithColumnHeaders("A", "B", "C")
                                                 .WithoutRows()
                                                 .WithRow(new[]
            {
                emptyCellValue,
                emptyCellValue,
                emptyCellValue
            })
                                                 .Build();

            // Act
            IDelimitedValuesReaderRow row = reader.Single();
            string cell1 = row.GetCell("A");
            string cell2 = row.GetCell("B");
            string cell3 = row.GetCell("C");

            // Assert
            cell1.Should().Be(emptyCellValue);
            cell2.Should().Be(emptyCellValue);
            cell3.Should().Be(emptyCellValue);
        }
        public void When_quoted_cell_contains_like_breaks_they_must_be_preserved()
        {
            // Arrange
            const string cellValue = "a\rb\nc\r\nd";

            using DelimitedValuesReader reader = new DelimitedValuesReaderBuilder()
                                                 .WithSingleColumnHeader("C")
                                                 .WithoutRows()
                                                 .WithDataLine(DefaultTextQualifier + cellValue + DefaultTextQualifier)
                                                 .Build();

            // Act
            IDelimitedValuesReaderRow row = reader.Single();
            string cell = row.GetCell("C");

            // Assert
            cell.Should().Be(cellValue);
        }
        public void When_no_field_separator_is_specified_it_must_give_semicolon_precedence_over_comma_during_auto_detection()
        {
            // Arrange
            using DelimitedValuesReader reader = new DelimitedValuesReaderBuilder()
                                                 .WithSettings(new DelimitedValuesReaderSettingsBuilder()
                                                               .WithFieldSeparator(null))
                                                 .WithHeaderLine("A;B;C,D,E")
                                                 .WithoutRows()
                                                 .WithDataLine("1;2;345")
                                                 .Build();

            // Act
            IDelimitedValuesReaderRow row = reader.Single();

            // Assert
            reader.ColumnNames.Should().HaveCount(3);
            row.GetCell("A").Should().Be("1");
        }
        public void When_quoted_cell_contains_leading_and_trailing_whitespace_it_must_be_preserved()
        {
            // Arrange
            const string columnHeaderName = "C";

            using DelimitedValuesReader reader = new DelimitedValuesReaderBuilder()
                                                 .WithSingleColumnHeader(columnHeaderName)
                                                 .WithoutRows()
                                                 .WithRow(new[]
            {
                " \"  A \"  "
            })
                                                 .Build();

            // Act
            IDelimitedValuesReaderRow row = reader.Single();

            // Assert
            row.GetCell(columnHeaderName).Should().Be("  A ");
        }
        public void When_quoted_cell_surrounds_text_qualifiers_they_must_be_unescaped()
        {
            // Arrange
            const string cellValue = "\"A nice day...\"";

            string escaped = DefaultTextQualifier +
                             cellValue.Replace(DefaultTextQualifier, DefaultTextQualifier + DefaultTextQualifier, StringComparison.Ordinal) + DefaultTextQualifier;

            using DelimitedValuesReader reader = new DelimitedValuesReaderBuilder()
                                                 .WithSingleColumnHeader("C")
                                                 .WithoutRows()
                                                 .WithDataLine(escaped)
                                                 .Build();

            // Act
            IDelimitedValuesReaderRow row = reader.Single();
            string cell = row.GetCell("C");

            // Assert
            cell.Should().Be(cellValue);
        }
        public void When_quoted_cell_contains_field_separators_they_must_be_preserved()
        {
            // Arrange
            const char   separator = ':';
            const string cellValue = "x:y:z";

            using DelimitedValuesReader reader = new DelimitedValuesReaderBuilder()
                                                 .WithSettings(new DelimitedValuesReaderSettingsBuilder()
                                                               .WithFieldSeparator(separator))
                                                 .WithHeaderLine("A" + separator + "B")
                                                 .WithoutRows()
                                                 .WithDataLine(DefaultTextQualifier + cellValue + DefaultTextQualifier + separator)
                                                 .Build();

            // Act
            IDelimitedValuesReaderRow row = reader.Single();
            string cell = row.GetCell("A");

            // Assert
            cell.Should().Be(cellValue);
        }
        public void When_quoted_cell_contains_leading_and_trailing_whitespace_it_must_be_preserved()
        {
            // Arrange
            const string columnHeaderName = "C";
            DelimitedValuesReader reader = new DelimitedValuesReaderBuilder()
                .WithSingleColumnHeader(columnHeaderName)
                .WithoutRows()
                .WithRow(new[] { " \"  A \"  " })
                .Build();

            // Act
            IDelimitedValuesReaderRow row = reader.Single();

            // Assert
            row.GetCell(columnHeaderName).Should().Be("  A ");
        }
        public void When_cells_are_empty_they_must_be_exposed_as_empty()
        {
            // Arrange
            string emptyCellValue = string.Empty;
            DelimitedValuesReader reader = new DelimitedValuesReaderBuilder()
                .WithColumnHeaders("A", "B", "C")
                .WithoutRows()
                .WithRow(new[] { emptyCellValue, emptyCellValue, emptyCellValue })
                .Build();

            // Act
            IDelimitedValuesReaderRow row = reader.Single();
            string cell1 = row.GetCell("A");
            string cell2 = row.GetCell("B");
            string cell3 = row.GetCell("C");

            // Assert
            cell1.Should().Be(emptyCellValue);
            cell2.Should().Be(emptyCellValue);
            cell3.Should().Be(emptyCellValue);
        }
        public void When_quoted_cell_surrounds_text_qualifiers_they_must_be_unescaped()
        {
            // Arrange
            const string cellValue = "\"A nice day...\"";
            string escaped = DefaultTextQualifier +
                cellValue.Replace(DefaultTextQualifier, DefaultTextQualifier + DefaultTextQualifier) +
                DefaultTextQualifier;
            DelimitedValuesReader reader = new DelimitedValuesReaderBuilder()
                .WithSingleColumnHeader("C")
                .WithoutRows()
                .WithDataLine(escaped)
                .Build();

            // Act
            IDelimitedValuesReaderRow row = reader.Single();
            string cell = row.GetCell("C");

            // Assert
            cell.Should().Be(cellValue);
        }
        public void When_quoted_cell_contains_field_separators_they_must_be_preserved()
        {
            // Arrange
            const char separator = ':';
            const string cellValue = "x:y:z";
            DelimitedValuesReader reader = new DelimitedValuesReaderBuilder()
                .WithSettings(new DelimitedValuesReaderSettingsBuilder()
                    .WithFieldSeparator(separator))
                .WithHeaderLine("A" + separator + "B")
                .WithoutRows()
                .WithDataLine(DefaultTextQualifier + cellValue + DefaultTextQualifier + separator)
                .Build();

            // Act
            IDelimitedValuesReaderRow row = reader.Single();
            string cell = row.GetCell("A");

            // Assert
            cell.Should().Be(cellValue);
        }
        public void When_quoted_cell_contains_like_breaks_they_must_be_preserved()
        {
            // Arrange
            const string cellValue = "a\rb\nc\r\nd";
            DelimitedValuesReader reader = new DelimitedValuesReaderBuilder()
                .WithSingleColumnHeader("C")
                .WithoutRows()
                .WithDataLine(DefaultTextQualifier + cellValue + DefaultTextQualifier)
                .Build();

            // Act
            IDelimitedValuesReaderRow row = reader.Single();
            string cell = row.GetCell("C");

            // Assert
            cell.Should().Be(cellValue);
        }
            When_no_field_separator_is_specified_it_must_give_semicolon_precedence_over_comma_during_autodetection()
        {
            // Arrange
            DelimitedValuesReader reader = new DelimitedValuesReaderBuilder()
                .WithSettings(new DelimitedValuesReaderSettingsBuilder()
                    .WithFieldSeparator(null))
                .WithHeaderLine("A;B;C,D,E")
                .WithoutRows()
                .WithDataLine("1;2;345")
                .Build();

            // Act
            IDelimitedValuesReaderRow row = reader.Single();

            // Assert
            reader.ColumnNames.Should().HaveCount(3);
            row.GetCell("A").Should().Be("1");
        }