public void ReferenceTest() { var config = new CsvConfiguration(CultureInfo.InvariantCulture) { HeaderValidated = null, MissingFieldFound = null, }; using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) using (var writer = new StreamWriter(stream)) using (var csv = new CsvReader(reader, config)) { writer.WriteLine("Id,Name"); writer.WriteLine("1,one"); writer.WriteLine("2,two"); writer.Flush(); stream.Position = 0; var record = new HasReferences { Id = -1, Reference = new Reference { Name = "one" } }; var count = 1; foreach (var r in csv.EnumerateRecords(record)) { if (count == 1) { Assert.Equal(1, r.Id); Assert.Equal("one", r.Reference.Name); } else if (count == 2) { Assert.Equal(2, r.Id); Assert.Equal("two", r.Reference.Name); } count++; } } }
public void ReferenceTest() { using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) using (var writer = new StreamWriter(stream)) using (var csv = new CsvReader(reader)) { csv.Configuration.Delimiter = ","; writer.WriteLine("Id,Name"); writer.WriteLine("1,one"); writer.WriteLine("2,two"); writer.Flush(); stream.Position = 0; csv.Configuration.HeaderValidated = null; csv.Configuration.MissingFieldFound = null; var record = new HasReferences { Id = -1, Reference = new Reference { Name = "one" } }; var count = 1; foreach (var r in csv.EnumerateRecords(record)) { if (count == 1) { Assert.AreEqual(1, r.Id); Assert.AreEqual("one", r.Reference.Name); } else if (count == 2) { Assert.AreEqual(2, r.Id); Assert.AreEqual("two", r.Reference.Name); } count++; } } }