public async Task write_csv_async_returns_number_of_items_written() { using (var writer = new CsvWriter(new StringWriter())) { writer.WriteRecord("some", "record"); var items = new TestType1[] { new TestType1 { Property1 = "1", Property2 = "2", Property3 = "3" }, new TestType1 { Property1 = "4", Property2 = "5", Property3 = "6" } }; Assert.Equal(2, await items.WriteCsvAsync(writer)); Assert.Equal(2, await items.WriteCsvAsync(writer, false)); } }
public async Task write_csv_async_writes_only_requested_properties_if_specified() { using (var stringWriter = new StringWriter()) using (var writer = new CsvWriter(stringWriter)) { writer.NewLine = "<EOL>"; var items = new TestType1[] { new TestType1 { Property1 = "1", Property2 = "2", Property3 = "3" }, new TestType1 { Property1 = "4", Property2 = "5", Property3 = "6" } }; await items.WriteCsvAsync(writer, true, new string[] { "Property2" }); Assert.Equal("Property2<EOL>2<EOL>5<EOL>", stringWriter.ToString()); } }
public async Task write_csv_async_writes_all_public_properties_by_default() { using (var stringWriter = new StringWriter()) using (var writer = new CsvWriter(stringWriter)) { writer.NewLine = "<EOL>"; var items = new TestType1[] { new TestType1 { Property1 = "1", Property2 = "2", Property3 = "3" }, new TestType1 { Property1 = "4", Property2 = "5", Property3 = "6" } }; await items.WriteCsvAsync(writer); var result = stringWriter.ToString(); // can't assert exact contents because order of properties is undefined (and changes) Assert.Contains("Property1", result); Assert.Contains("Property2", result); Assert.Contains("1", result); Assert.Contains("2", result); Assert.Contains("4", result); Assert.Contains("5", result); } }