Exemplo n.º 1
0
 public static void TestDeserializeNotExpectedCSV()
 {
     using (StreamReader stream = new StreamReader($"{_baseDirectory}/resources/random-example.csv"))
     {
         CsvReader      reader = new CsvReader(stream, CultureInfo.InvariantCulture);
         DateDTO.CSVMap map    = new DateDTO.CSVMap("dob");
         reader.Configuration.RegisterClassMap(map);
         Assert.Throws <CsvHelper.HeaderValidationException>(() => reader.GetRecords <DateDTO>().ToList());
     }
 }
Exemplo n.º 2
0
        public static void TestDeserializeCSV()
        {
            using (StreamReader stream = new StreamReader($"{_baseDirectory}/resources/data-example.csv"))
            {
                CsvReader      reader = new CsvReader(stream, CultureInfo.InvariantCulture);
                DateDTO.CSVMap map    = new DateDTO.CSVMap("dob");
                reader.Configuration.RegisterClassMap(map);
                List <DateDTO> dtoList      = reader.GetRecords <DateDTO>().ToList();
                DateTime       expectedDate = new DateTime(1968, 1, 24, 18, 3, 23, DateTimeKind.Utc);

                Assert.Single(dtoList);
                Assert.Equal(expectedDate, dtoList[0].Date);
                Assert.Equal(50, dtoList[0].Age);
            }
        }