public void VersionHeaderAndData() { var sb = new StringBuilder(); sb.AppendLine("Ver=1"); sb.AppendLine("Name,Id,Growth"); sb.AppendLine("Joe,1,170.5"); sb.AppendLine("Tom,2,180.5"); DataObject expected = new DataObject { VersionId = "Ver=1", Items = new List<DataItem> { new DataItem {Name = "Joe", Id = 1, Growth = 170.5}, new DataItem {Name = "Tom", Id = 2, Growth = 180.5} } }; using (NCsvFileReader csvFile = new NCsvFileReader(new StringReader(sb.ToString()))) { DataObject actualContent = csvFile.Read<DataObject>(); Assert.That(actualContent, Is.EqualTo(expected)); } }
public void DataObjectWithDataItems() { DataObject dataObject = new DataObject { VersionId = "Ver=1", Items = new List<DataItem> { new DataItem {Name = "Joe", Id = 1, Growth = 170.5}, new DataItem {Name = "Tom", Id = 2, Growth = 180.5} } }; var sb = new StringBuilder(); using (NCsvFileWriter csvFileWriter = new NCsvFileWriter(new StringWriter(sb))) { csvFileWriter.Write(dataObject); } Assert.That(sb.ToString(), Is.EqualTo(new StringBuilder() .AppendLine("Ver=1") .AppendLine("Name,Id,Growth") .AppendLine("Joe,1,170.5") .AppendLine("Tom,2,180.5") .ToString())); }
public void DataObjectWithEmptyList() { DataObject dataObject = new DataObject {VersionId = "Ver=1"}; var sb = new StringBuilder(); using (NCsvFileWriter csvFileWriter = new NCsvFileWriter(new StringWriter(sb))) { csvFileWriter.Write(dataObject); } Assert.That(sb.ToString(), Is.EqualTo(new StringBuilder() .AppendLine("Ver=1") .AppendLine("Name,Id,Growth") .ToString())); }
protected bool Equals(DataObject other) { return string.Equals(VersionId, other.VersionId) && Equals(Items, other.Items); }