コード例 #1
0
        public void ThrowErrorIfUsingQuoteAsColumnsDelimiterInRfc4810ButWorksIfDisableIt()
        {
            const string input = "Header1\"Header2\r\nValue1\"Value2\r\nValue3\"Value4";

            Action action = () => Read.Csv.FromString(input)
                            .With.ColumnsDelimiter("\"")
                            .ThatReturns.ArrayOf <TestResultWithMultiline>()
                            .Put.Column("Header1").Into(a => a.Firstname)
                            .Put.Column("Header2").Into(a => a.Lastname)
                            .GetAll();

            action.Should().Throw <BadDelimiterException>();

            var result = Read.Csv.FromString(input)
                         .With.ColumnsDelimiter("\"").And.SimpleParsingMode()
                         .ThatReturns.ArrayOf <TestResultWithMultiline>()
                         .Put.Column("Header1").Into(a => a.Firstname)
                         .Put.Column("Header2").Into(a => a.Lastname)
                         .GetAll().ResultSet;

            result.Should().HaveCount(2);
            result.ShouldContainEquivalentTo(
                TestResultWithMultiline.Create("Value1", "Value2"),
                TestResultWithMultiline.Create("Value3", "Value4"));
        }
コード例 #2
0
        public void ReadCsvWithColumnThatContainsNewLine()
        {
            const string input = "\"FirstName\r\nLastName\";\"Home\r\nAddress\"\r\nMARTIN;\"12\r\nRue test\"";

            var resultSet = Read.Csv.FromString(input)
                            .ThatReturns.ArrayOf <TestResultWithMultiline>()
                            .Put.Column("FirstName\r\nLastName").Into(a => a.Firstname)
                            .Put.Column("Home\r\nAddress").Into(a => a.Address)
                            .GetAll().ResultSet;

            resultSet.ShouldContainEquivalentTo(TestResultWithMultiline.Create("MARTIN", address: "12\r\nRue test"));
        }
コード例 #3
0
        public void ReadColumnWithMultilineAndColumnSeparator()
        {
            const string input = "Firstname;Lastname;Address\r\nAurelien;BOUDOUX;\"9\r\nrue du test; impasse\r\n75001\r\nParis\"";

            var resultSet = Read.Csv.FromString(input)
                            .ThatReturns.ArrayOf <TestResultWithMultiline>()
                            .Put.Column("Firstname").Into(a => a.Firstname)
                            .Put.Column("Lastname").Into(a => a.Lastname)
                            .Put.Column("Address").Into(a => a.Address)
                            .GetAll().ResultSet;

            resultSet.ShouldContainEquivalentTo(TestResultWithMultiline.Create("Aurelien", "BOUDOUX", "9\r\nrue du test; impasse\r\n75001\r\nParis"));
        }
コード例 #4
0
        public void DontUseRfc4180ForParsing()
        {
            const string input = "Firstname;Lastname\r\n\"M. B\"OK;Benoit";

            var resultSet = Read.Csv.FromString(input)
                            .With.SimpleParsingMode()
                            .ThatReturns.ArrayOf <TestResultWithMultiline>()
                            .Put.Column("Firstname").Into(a => a.Firstname)
                            .Put.Column("Lastname").Into(a => a.Lastname)
                            .GetAll().ResultSet;

            resultSet.ShouldContainEquivalentTo(TestResultWithMultiline.Create("\"M. B\"OK", "Benoit"));
        }
コード例 #5
0
        public void AllowWhiteSpaceInColumnsLineDelimiter()
        {
            const string input = "Header1 Header2\r\nValue1 Value2\r\nValue3 Value4";

            var result = Read.Csv.FromString(input)
                         .With.ColumnsDelimiter(" ")
                         .ThatReturns.ArrayOf <TestResultWithMultiline>()
                         .Put.Column("Header1").Into(a => a.Firstname)
                         .Put.Column("Header2").Into(a => a.Lastname)
                         .GetAll().ResultSet;

            result.Should().HaveCount(2);
            result.ShouldContainEquivalentTo(
                TestResultWithMultiline.Create("Value1", "Value2"),
                TestResultWithMultiline.Create("Value3", "Value4"));
        }