public void TestEmptyQuotedCell()
        {
            var result = FastCsvReader.ReadAs <BuaData>(emptyQuotedCell).ToArray();

            Assert.That(result[0].Code, Is.EqualTo(string.Empty));
            Assert.That(result[0].Name, Is.EqualTo("Value"));
        }
        public void TestBadDataWithCustomParser()
        {
            var converter = new DefaultConverterSpec();

            converter.SetConverter <int?>(s =>
            {
                if (string.IsNullOrWhiteSpace(s))
                {
                    return(null);
                }
                if (!int.TryParse(s, out int value))
                {
                    return(null);
                }
                return(value);
            });
            var result = FastCsvReader.ReadAs <DefaultData2>(testData3, '¬', converter).ToArray();

            Assert.That(result.Length, Is.EqualTo(4));
            Assert.That(result[0].Area, Is.EqualTo(1));
            Assert.That(result[0].QuotaValuesAndResults, Is.EqualTo("Full Time, Part-Time and Zero-hour"));
            Assert.That(result[0].Remarks, Is.Empty);
            Assert.That(result[0].Notes, Is.Empty);
            Assert.That(result[1].QuotaValuesAndResults, Is.EqualTo("Part-Time"));
            Assert.That(result[1].Notes, Is.Empty);
            Assert.That(result[2].Area, Is.Null);
            Assert.That(result[2].QuotaValuesAndResults, Is.Not.Null.Or.Empty);
            Assert.That(result[3].Area, Is.Null);
        }
        public void TestSingleQuotes()
        {
            var result = FastCsvReader.ReadAs <BuaData>(singleQuotes).ToArray();

            Assert.That(result.Length, Is.EqualTo(1));
            Assert.That(result[0].Name, Is.EqualTo("Hart's Lane, nr Langham (Colchester) BUA"));
        }
        public void TestMultiAttribute()
        {
            var result = FastCsvReader.ReadAs <MultiAttr>(testData4).ToArray();

            Assert.That(result.Length, Is.EqualTo(1));
            Assert.That(result[0].Code, Is.EqualTo("AAA"));
            Assert.That(result[0].Name, Is.EqualTo("BBB"));
            Assert.That(result[0].Notes, Is.EqualTo("CCC"));
        }
        public void TestReadWithTrimmingConverter()
        {
            var result = FastCsvReader.ReadAs <DefaultData>(testData1, converter: ConverterSpecs.StringTrim).ToArray();

            Assert.That(result.Length, Is.EqualTo(2));
            Assert.That(result[0].Area, Is.EqualTo(1));
            Assert.That(result[0].Quota, Is.EqualTo("Full Time"));
            Assert.That(result[0].Remarks, Is.Empty);
            Assert.That(result[0].Notes, Is.Empty);
            Assert.That(result[1].Quota, Is.EqualTo("Part-Time"));
            Assert.That(result[1].Notes, Is.EqualTo("This is a note"));
        }
        public void TestReadWithCommasAllFieldsPresent()
        {
            var result = FastCsvReader.ReadAs <DefaultData>(testData1).ToArray();

            Assert.That(result.Length, Is.EqualTo(2));
            Assert.That(result[0].Area, Is.EqualTo(1));
            Assert.That(result[0].Quota, Is.EqualTo(" Full Time"));
            Assert.That(result[0].Remarks, Is.Empty);
            Assert.That(result[0].Notes, Is.Empty);
            Assert.That(result[1].Quota, Is.EqualTo(" Part-Time"));
            Assert.That(result[1].Notes, Is.EqualTo("This is a note"));
        }
        public void TestAdditionalColumns()
        {
            var result = FastCsvReader.ReadAs <AdditionalColumnsData>(testData4).ToArray();

            Assert.That(result.Length, Is.EqualTo(1));
            Assert.That(result[0].Code, Is.EqualTo("AAA"));
            Assert.That(result[0].Columns.Keys.Count, Is.EqualTo(2));
            Assert.That(result[0].Columns.ContainsKey("Name1"), Is.EqualTo(true));
            Assert.That(result[0].Columns.ContainsKey("Notes"), Is.EqualTo(true));
            Assert.That(result[0].Columns["Name1"], Is.EqualTo("BBB"));
            Assert.That(result[0].Columns["Notes"], Is.EqualTo("CCC"));
        }
        public void TestWithContainedQuotedCommasAndTrimming()
        {
            var result = FastCsvReader.ReadAs <DefaultData2>(testData2, converter: ConverterSpecs.StringTrim).ToArray();

            Assert.That(result.Length, Is.EqualTo(2));
            Assert.That(result[0].Area, Is.EqualTo(1));
            Assert.That(result[0].QuotaValuesAndResults, Is.EqualTo("Full Time, Part-Time and Zero-hour"));
            Assert.That(result[0].Remarks, Is.Empty);
            Assert.That(result[0].Notes, Is.Empty);
            Assert.That(result[1].QuotaValuesAndResults, Is.EqualTo("Part-Time"));
            Assert.That(result[1].Notes, Is.EqualTo("This is a note"));
        }
        public void TestBackslashEscapedQuotes()
        {
            var result = FastCsvReader.ReadAs <BuaData>(backslashEscapedQuotes).ToArray();

            Assert.That(result[0].Name, Is.EqualTo("My heart says \"I am a heart!\""));
        }
        public void TestUnquotedDoubleEscapedQuotes()
        {
            var result = FastCsvReader.ReadAs <BuaData>(unquotedEscapedDoubleQuotes).ToArray();

            Assert.That(result[0].Name, Is.EqualTo("My heart says \"\" \"I am a heart!\""));
        }
 public void TestMixedQuotesDoesntThrow()
 {
     Assert.That(() => FastCsvReader.ReadAs <BuaData>(escapedDoubleQuotes).ToArray(), Throws.Nothing);
 }
 public void TestWithDifferentDelimiterMissingValuesAndQuotedCommasAndBadData()
 {
     Assert.That(() => FastCsvReader.ReadAs <DefaultData2>(testData3, '¬', ConverterSpecs.StringTrim).ToArray(), Throws.Exception);
 }