public string Format(CsvTableStructure tableStructure, IEnumerable<string> input)
        {
            var result = new StringBuilder();
            var row = 0;

            foreach (var line in input)
            {
                var idx = 0;
                var col = 1;

                foreach (var fieldLength in tableStructure.RowFieldLength[row])
                {
                    result.Append(
                            line.Substring(idx, fieldLength)
                                    .PadRight(tableStructure[col], ' ') + "|");
                    idx += fieldLength + 1;
                    col++;
                }
                result.Append(Environment.NewLine);

                if (row == 0)
                    AppendHeaderSeparator(tableStructure, result);

                row++;
            }

            return result.ToString();
        }
        public void WhenEmptyInput()
        {
            ICsvLinesPreProcessor preProcessor = A.Fake<ICsvLinesPreProcessor>();
            ICsvLinesFormatter formatter = A.Fake<ICsvLinesFormatter>();
            CsvTableStructure tableStructure = new CsvTableStructure();
            var input = new List<string>
                            {
                                    string.Empty
                            };

            A.CallTo(() => preProcessor.GetPreProcessedCsvLines(input))
                    .Returns(tableStructure);

            var result = "theResult";
            A.CallTo(() => formatter.Format(tableStructure, input))
                    .Returns(result);

            var sut = new OutputsCsvAsTable(preProcessor, formatter);

            sut.GetOutput(input).ShouldBeEquivalentTo(result);

            A.CallTo(() => preProcessor.GetPreProcessedCsvLines(input))
                    .MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => formatter.Format(tableStructure, input))
                    .MustHaveHappened(Repeated.Exactly.Once);
        }
 private void AppendHeaderSeparator(CsvTableStructure tableStructure, StringBuilder result)
 {
     for (int i = 1; i <= tableStructure.ColumnCount; i++)
         result.Append(string.Empty.PadRight(tableStructure[i], '-') + "+");
     result.Append(Environment.NewLine);
 }