public void GetRows_WithDuplicateHeaderNames_ThrowsException()
        {
            var data = "HEADER1;HEADER1\r\nCELL1;CELL2";

            using (var reader = GetReader(data))
            {
                var parser = new CsvStreamLineReader(new TestCsvDefinition {
                    ElementProcessing = ElementProcessing.Loose
                }, HEADER1.Name, HEADER1.Name);
                var lines = parser.GetRows(reader).ToList();
            }
        }
        public void GetRows_StrictElementProcessingTooManyColumns_ThrowsException()
        {
            var data = "HEADER1;HEADER2\r\nCELL1;CELL2;CELL3";

            using (var reader = GetReader(data))
            {
                var parser = new CsvStreamLineReader(new TestCsvDefinition {
                    ElementProcessing = ElementProcessing.Strict
                }, HEADER1.Name, HEADER2.Name);
                Expect.Throws <InvalidOperationException>(() => parser.GetRows(reader).ToList())
                .Message.Contains("The line (2) contains more elements (3) than headers (2) available.");
            }
        }
        public void GetRows_LooseElementProcessingTooFewColumns_ReturnsStringEmpty()
        {
            var data = "HEADER1;HEADER2\r\nCELL1";

            using (var reader = GetReader(data))
            {
                var parser = new CsvStreamLineReader(new TestCsvDefinition {
                    ElementProcessing = ElementProcessing.Loose
                }, HEADER1.Name, HEADER2.Name);
                var lines = parser.GetRows(reader).ToList();

                Assert.AreEqual(string.Empty, lines[1][HEADER2]);
            }
        }
        public void GetRows_TooManyValidationElementProcessingTooFewColumns_Succeeds()
        {
            var data = "HEADER1;HEADER2\r\nCELL1";

            using (var reader = GetReader(data))
            {
                var parser = new CsvStreamLineReader(new TestCsvDefinition {
                    ElementProcessing = ElementProcessing.OnlyTooMany
                }, HEADER1.Name, HEADER2.Name);
                var lines = parser.GetRows(reader).ToList();

                Assert.AreEqual(2, lines.Count());
            }
        }
        public void GetRows_StrictElementProcessingNormalData_ReturnsElements()
        {
            var data = "HEADER1;HEADER2\r\nCELL1;CELL2";

            using (var reader = GetReader(data))
            {
                var parser = new CsvStreamLineReader(new TestCsvDefinition {
                    ElementProcessing = ElementProcessing.Strict
                }, HEADER1.Name, HEADER2.Name);
                var lines = parser.GetRows(reader).ToList();

                Assert.AreEqual(HEADER1.Name, lines[0][HEADER1]);
                Assert.AreEqual(HEADER2.Name, lines[0][HEADER2]);
                Assert.AreEqual(CELL1.Name, lines[1][HEADER1]);
                Assert.AreEqual(CELL2.Name, lines[1][HEADER2]);
            }
        }
        public void GetRows_LooseElementProcessingTooManyColumns_IgnoresExcess()
        {
            var data = "HEADER1;HEADER2\r\nCELL1;CELL2;CELL3";

            using (var reader = GetReader(data))
            {
                var parser = new CsvStreamLineReader(new TestCsvDefinition {
                    ElementProcessing = ElementProcessing.Loose
                }, HEADER1.Name, HEADER2.Name);
                var lines = parser.GetRows(reader).ToList();

                Assert.AreEqual(HEADER1.Name, lines[0][HEADER1]);
                Assert.AreEqual(HEADER2.Name, lines[0][HEADER2]);
                Assert.AreEqual(CELL1.Name, lines[1][HEADER1]);
                Assert.AreEqual(CELL2.Name, lines[1][HEADER2]);
            }
        }