public void FromTest() { var record = CsvRecord.From(new { Name = "Violet", Age = 16 }); Assert.AreEqual(CsvHeader.FromValues("Name", "Age"), record.Header); Assert.AreEqual("Violet,16", record.ToString()); }
public void WithFormatTest() { var header = CsvHeader.FromValues("name", "age"); var copy = header.WithFormat(new CsvFormat(';', '|')); Assert.AreEqual(new CsvFormat(';', '|'), copy.Format); }
public void WithStyleTest() { var header = CsvHeader.FromValues("name", "age"); var copy = header.WithStyle(QuoteStyle.Always); Assert.AreEqual(CsvFormat.Default.WithStyle(QuoteStyle.Always), copy.Format); }
public void WithQuoteTest() { var header = CsvHeader.FromValues("name", "age"); var copy = header.WithQuote('|'); Assert.AreEqual(CsvFormat.Default.WithQuote('|'), copy.Format); }
public void CsvDocumentTest() { var document = new CsvDocument <Person>(); Assert.AreEqual(0, document.Count); Assert.IsTrue(document.IsEmpty); Assert.AreEqual(CsvHeader.FromValues("Name", "Age"), document.Header); Assert.AreEqual(CsvFormat.Default, document.Format); }
public void CsvDocumentTest2() { var document = new CsvDocument(new string[] { "name", "age" }, flexible: true); Assert.AreEqual(CsvHeader.FromValues("name", "age"), document.Header); Assert.IsTrue(document.IsFlexible); Assert.IsTrue(document.IsEmpty); Assert.AreEqual(0, document.Count); }
public void CsvDocumentTest1() { var format = new CsvFormat(';', '\"'); var document = new CsvDocument <Person>(format); Assert.AreEqual(0, document.Count); Assert.IsTrue(document.IsEmpty); Assert.AreEqual(CsvHeader.FromValues(format, "Name", "Age"), document.Header); Assert.AreEqual(new CsvFormat(';', '\"'), document.Format); }
public void CsvDocumentTest() { var document = new CsvDocument(new string[] { "name", "age" }); Assert.AreEqual(CsvHeader.FromValues("name", "age"), document.Header); Assert.AreEqual(CsvFormat.Default, document.Format); Assert.IsFalse(document.IsFlexible); Assert.IsTrue(document.IsEmpty); Assert.AreEqual(0, document.Count); }
public void FromCsvTest1() { var csv = "Name,Age\r\n" + "Kara,20\r\n" + "Markus,25,RK-200\r\n"; var document = CsvDocument.FromCsv(csv, flexible: true); Assert.AreEqual(2, document.Count); Assert.AreEqual(CsvHeader.FromValues("Name", "Age"), document.Header); Assert.AreEqual(new CsvRecord(document.Header, new string[] { "Kara", "20" }), document[0]); Assert.AreEqual(new CsvRecord(document.Header, new string[] { "Markus", "25", "RK-200" }), document[1]); }
public void CsvRecordTest1() { var header = CsvHeader.FromValues("name", "age"); var record = new CsvRecord(header, new string[] { "Violet", "16" }); Assert.AreEqual(2, record.Length); Assert.AreEqual(CsvFormat.Default, record.Format); Assert.AreEqual(CsvHeader.FromValues("name", "age"), header); Assert.AreEqual("Violet", record[0]); Assert.AreEqual("16", record[1]); Assert.AreEqual("Violet", record["name"]); Assert.AreEqual("16", record["age"]); }
public void CsvHeaderFromTest() { var header = CsvHeader.FromValues("id", "name", "age"); Assert.AreEqual(3, header.Length); Assert.AreEqual(CsvFormat.Default, header.Format); Assert.AreEqual("id", header[0]); Assert.AreEqual("name", header[1]); Assert.AreEqual("age", header[2]); Assert.Throws <ArgumentOutOfRangeException>(() => { var _ = header[3]; }); }
public void CsvDocumentTest2() { var persons = new List <Person> { new Person { Name = "Akari", Age = 20 }, new Person { Name = "Kyoko", Age = 21 } }; var document = new CsvDocument <Person>(persons); Assert.AreEqual(2, document.Count); Assert.IsFalse(document.IsEmpty); Assert.AreEqual(CsvHeader.FromValues("Name", "Age"), document.Header); Assert.AreEqual(CsvFormat.Default, document.Format); }
public void WriteFileTest() { var header = CsvHeader.FromValues("Name", "Age"); var records = new CsvRecord[] { new CsvRecord(header, new string[] { "Karl", "26" }), new CsvRecord(header, new string[] { "Elena", "17" }) }; using (var tempFile = new TempFile()) { CsvWriter.WriteFile(header, records, tempFile.FullName); using (var reader = new StreamReader(tempFile.FullName)) { string data = reader.ReadToEnd(); Assert.AreEqual( "Name,Age\r\n" + "Karl,26\r\n" + "Elena,17\r\n", data); } } }
public void FromTypeWithAliasTest() { var header = CsvHeader.FromType <Person2>(); Assert.AreEqual(CsvHeader.FromValues("first_name", "age"), header); }
public void FromTypeTest() { var header = CsvHeader.FromType <Person1>(); Assert.AreEqual(CsvHeader.FromValues("Name", "Age"), header); }
public void EqualsTest() { var header = new CsvHeader(new string[] { "id", "name", "age" }); Assert.AreEqual(CsvHeader.FromValues("id", "name", "age"), header); }