diff options
Diffstat (limited to 'ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Reading/BadDataTests.cs')
-rw-r--r-- | ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Reading/BadDataTests.cs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Reading/BadDataTests.cs b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Reading/BadDataTests.cs new file mode 100644 index 0000000..b127478 --- /dev/null +++ b/ThirdParty/CsvHelper-master/tests/CsvHelper.Tests/Reading/BadDataTests.cs @@ -0,0 +1,64 @@ +using CsvHelper.Configuration; +using CsvHelper.Configuration.Attributes; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace CsvHelper.Tests.Reading +{ + public class BadDataTests + { + [Fact] + public void GetRecord_BadDataCountNotDuplicted() + { + var errorCount = 0; + var csvConfiguration = new CsvConfiguration(CultureInfo.InvariantCulture) + { + ReadingExceptionOccurred = args => false, + BadDataFound = args => + { + ++errorCount; + }, + Delimiter = ";", + }; + var csv = "SKU;Min quantity;List price;Sale price\r\nTestSku1;2;10.99;9.99\r\nTestSku2;2;10.99;9\r\nXXX;\"9;10.9;9"; + var stream = new MemoryStream(); + using (var writer = new StreamWriter(stream, leaveOpen: true)) + { + writer.Write(csv); + writer.Flush(); + stream.Position = 0; + } + var textReader = new StreamReader(stream, leaveOpen: true); + + var csvReader = new CsvReader(textReader, csvConfiguration); + + while (csvReader.Read()) + { + csvReader.GetRecord<CsvPrice>(); + } + + Assert.Equal(1, errorCount); + } + + public sealed class CsvPrice + { + [Name("SKU")] + public string Sku { get; set; } + + [Name("Min quantity")] + public int MinQuantity { get; set; } + + [Name("List price")] + public decimal ListPrice { get; set; } + + [Name("Sale price")] + public decimal? SalePrice { get; set; } + } + } +} |