Example #1
0
        public void write_csv_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, items.WriteCsv(writer));
                Assert.Equal(2, items.WriteCsv(writer, false));
            }
        }
Example #2
0
        public void write_csv_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"
                        }
                    };

                    items.WriteCsv(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);
                }
        }
Example #3
0
        public void write_csv_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"
                        }
                    };

                    items.WriteCsv(writer, true, new string[] { "Property2" });
                    Assert.Equal("Property2<EOL>2<EOL>5<EOL>", stringWriter.ToString());
                }
        }
        public void write_csv_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"
                    }
                };

                items.WriteCsv(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);
            }
        }
        public void write_csv_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, items.WriteCsv(writer));
                Assert.Equal(2, items.WriteCsv(writer, false));
            }
        }
        public void write_csv_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"
                    }
                };

                items.WriteCsv(writer, true, new string[] { "Property2" });
                Assert.Equal("Property2<EOL>2<EOL>5<EOL>", stringWriter.ToString());
            }
        }