Esempio n. 1
0
        public void ComplexCsvForceSpaceInHeaderTest()
        {
            // Arrange
            var headers = new List <string> {
                "H1", "H2", " H3 "
            };
            var rows = new List <List <string> >()
            {
                new List <string>
                {
                    string.Format("{0}{3}{1}{3}{2}", "A", "B", "C", NewLine.Get()),
                    string.Format("{0}{3}{1}{3}{2}", "D", "E", "F", NewLine.Get()),
                    string.Format("{0}{3}{1}{3}{2}", "G", "H", "I", NewLine.Get()),
                },
                new List <string>
                {
                    string.Format("{0}{3}{1}{3}{2}", "J", "K", "L", NewLine.Get()),
                    string.Format("{0}{3}{1}{3}{2}", "M", "N", "O", NewLine.Get()),
                    string.Format("{0}{3}{1}{3}{2}", "P", "Q", "R", NewLine.Get()),
                }
            };
            // Act
            var csv = new Csv(@"Data\ComplexForceSpaceInHeader.csv");

            // Assert
            CollectionAssert.AreEqual(headers, csv.Headers);
            Assert.AreEqual(rows.Count, csv.Rows.Count);
            var i = 0;

            foreach (var row in csv.Rows)
            {
                CollectionAssert.AreEqual(rows[i++], row);
            }
        }
Esempio n. 2
0
        public void ComplexCsvFromStreamTest()
        {
            // Arrange
            var headers = new List <string> {
                "H1", "H2", "H3"
            };
            var rows = new List <List <string> >()
            {
                new List <string>
                {
                    string.Format("{0}{3}{1}{3}{2}", "A", "B", "C", NewLine.Windows()),
                    string.Format("{0}{3}{1}{3}{2}", "D", "E", "F", NewLine.Windows()),
                    string.Format("{0}{3}{1}{3}{2}", "G", "H", "I", NewLine.Windows()),
                },
                new List <string>
                {
                    string.Format("{0}{3}{1}{3}{2}", "J", "K", "L", NewLine.Windows()),
                    string.Format("{0}{3}{1}{3}{2}", "M", "N", "O", NewLine.Windows()),
                    string.Format("{0}{3}{1}{3}{2}", "P", "Q", "R", NewLine.Windows()),
                }
            };
            // Act

            var csvAsString = "H1,H2,H3\r\n\"A\r\nB\r\nC\",\"D\r\nE\r\nF\",\"G\r\nH\r\nI\"\r\n\"J\r\nK\r\nL\",\"M\r\nN\r\nO\",\"P\r\nQ\r\nR\"\r\n";
            var csv         = new Csv(csvAsString.AsStream());

            // Assert
            CollectionAssert.AreEqual(headers, csv.Headers);
            Assert.AreEqual(rows.Count, csv.Rows.Count);
            var i = 0;

            foreach (var row in csv.Rows)
            {
                CollectionAssert.AreEqual(rows[i++], row);
            }
        }