예제 #1
0
 public void SpecifyingEncodingWithAStringBuilderThrowsException()
 {
     Assert.Throws <ArgumentException>(delegate
     {
         CsvWriter.Builder(new StringWriter(new StringBuilder("A;;A;T;;\r\nGreat"))).Encoding(Encoding.UTF8)
         .Build();
     });
 }
예제 #2
0
        public void PassingStringBuilderDoesntCloseItOnDispose()
        {
            var b = new StringBuilder("A;;A;T;;\r\nGreat");
            var w = CsvWriter.Builder(b).Build();

            w.Dispose();
            b.Append("Should not throw exception");
        }
예제 #3
0
        public void PassingTextWriterDoesntCloseItOnDispose()
        {
            var b = new StringWriter(new StringBuilder("A;;A;T;;\r\nGreat"));
            var w = CsvWriter.Builder((TextWriter)b).Build();

            w.Dispose();
            b.Write("Should not throw exception");
            b.Flush();
            b.Close();
        }
예제 #4
0
        public void AppendingNullWithWriteStringTest()
        {
            using (csvWriter = CsvWriter.Builder(stringWriter).ColumnSeparator(';').RowSeparator("\r\n")
                               .FieldDelimiter('\"').ChunkSize(10).QuotingBehavior(QuotingBehavior.ALL).Build())
            {
                Assert.IsNotNull(csvWriter);
                csvWriter.Write("").Write().Write("3").WriteLine().Write("1").Write((string)null).Write("3");
            }

            Assert.AreEqual("\"\";\"\";\"3\"\r\n\"1\";\"\";\"3\"", stringWriter.ToString());
        }
예제 #5
0
        public void BuildingMethodsMaximalQuotingTest()
        {
            using (csvWriter = CsvWriter.Builder(stringWriter).ColumnSeparator(';').RowSeparator("\r\n")
                               .FieldDelimiter('\"').ChunkSize(10).QuotingBehavior(QuotingBehavior.ALL).Build())
            {
                Assert.IsNotNull(csvWriter);
                csvWriter.Write("Great").Write("Totally").Write("This is a\r\nbreak").WriteLine("").Write()
                .Write("Gr;eat").WriteLine("Totally").Write("Great").Write("���\"�").Write().Write("Totally");
            }

            Assert.AreEqual("\"Great\";\"Totally\";\"This is a\r\nbreak" +
                            "\";\"\"\r\n\"\";\"Gr;eat\";\"Totally\"\r\n\"" + "Great\";\"���\"\"�\";\"\";\"Totally\"",
                            stringWriter.ToString());
        }
예제 #6
0
        public void AppendingNullWithWriteTest()
        {
            var csv = new List <List <string> >();

            var row = new List <string> {
                "", "", "3"
            };

            csv.Add(row);
            row = new List <string> {
                "1", null, "3"
            };
            csv.Add(row);

            using (csvWriter = CsvWriter.Builder(stringWriter).ColumnSeparator(';').RowSeparator("\r\n")
                               .FieldDelimiter('\"').ChunkSize(200).QuotingBehavior(QuotingBehavior.ALL).Build())
            {
                Assert.IsNotNull(csvWriter);
                csvWriter.Write(csv);
            }

            Assert.AreEqual("\"\";\"\";\"3\"\r\n\"1\";\"\";\"3\"", stringWriter.ToString());
        }
예제 #7
0
 public void Setup()
 {
     stringWriter = new StringWriter();
     csvWriter    = CsvWriter.Builder(stringWriter).ColumnSeparator(';').RowSeparator(NEW_LINE).FieldDelimiter('\"')
                    .Build();
 }