Пример #1
0
        public string ToMarkdownTable <T>
            (bool smallerFontSize, NullHandlingStrategies strategy, List <T> rows)
        {
            if (strategy != NullHandlingStrategies.ThrowException &&
                strategy != NullHandlingStrategies.RemoveNullItems &&
                strategy != NullHandlingStrategies.ReplaceNullsWithNullMarkdownLines)
            {
                throw new ArgumentException(MessageCollection.ProvidedNullHandlingStrategyNotValid.Invoke(strategy));
            }
            if (rows == null)
            {
                throw new ArgumentNullException(nameof(rows));
            }
            if (rows.Count == 0)
            {
                throw new ArgumentException(MessageCollection.CantHaveZeroItems.Invoke(nameof(rows)));
            }

            if (strategy == NullHandlingStrategies.RemoveNullItems)
            {
                rows = rows.Where(row => row != null).ToList();
            }

            string str = ToMarkdownHeader(smallerFontSize, rows[0]); // Whatever object in the list is fine

            if (rows.Count > 1)
            {
                str += ProcessRows(smallerFontSize, strategy, rows);
            }

            return(str);
        }
        public void ToMarkdownTableList_ShouldReturnExpectedString_WhenProperArguments <T>
            (bool smallerFontSize, NullHandlingStrategies strategy, List <T> rows, string expected)
        {
            // Arrange
            // Act
            string actual = new MarkdownTabulizer().ToMarkdownTable(smallerFontSize, strategy, rows);

            // Assert
            Assert.AreEqual(expected, actual);
        }
Пример #3
0
        private string ProcessRows <T>
            (bool smallerFontSize, NullHandlingStrategies strategy, List <T> rows)
        {
            string str = Environment.NewLine;

            for (int i = 0; i < rows.Count; i++)
            {
                str += ProcessRow(smallerFontSize, strategy, rows[i]);

                if (i != (rows.Count - 1))
                {
                    str += Environment.NewLine;
                }
            }

            return(str);
        }
Пример #4
0
        private string ProcessRow <T>
            (bool smallerFontSize, NullHandlingStrategies strategy, T row)
        {
            string str = string.Empty;

            if (row == null &&
                strategy == NullHandlingStrategies.ReplaceNullsWithNullMarkdownLines)
            {
                str += CreateMarkdownRow("null", GetPropertyCount(typeof(T)), smallerFontSize);
            }
            else
            {
                str += ToMarkdownRow(smallerFontSize, row);
            }

            return(str);
        }