Example #1
0
        public void TestWrapParagraphAsList(string textToWrap, int wrapWidth, int spaceIndentCount, int expectedLineCount, int expectedCharacterCount)
        {
            if (spaceIndentCount > 0)
            {
                // Indent all of the wrapped lines by the given amount
                textToWrap = new string(' ', spaceIndentCount) + textToWrap;
            }

            var wrappedText = ConsoleMsgUtils.WrapParagraphAsList(textToWrap, wrapWidth);
            var charCount   = 0;

            foreach (var textLine in wrappedText)
            {
                Console.WriteLine(textLine);
                charCount += textLine.Length;
            }

            Console.WriteLine();
            Console.WriteLine("Wrapping to {0} characters per line gives {1} lines of wrapped text and {2} total characters", wrapWidth, wrappedText.Count, charCount);
            if (spaceIndentCount > 0)
            {
                Console.WriteLine("Indented text by {0} characters", spaceIndentCount);
            }

            if (expectedLineCount > 0)
            {
                Assert.AreEqual(expectedLineCount, wrappedText.Count,
                                "Text wrapped to {0} lines instead of {1} lines", wrappedText.Count, expectedLineCount);
            }
            else
            {
                Console.WriteLine("Skipped line count validation");
            }

            if (expectedCharacterCount > 0)
            {
                Assert.AreEqual(expectedCharacterCount, charCount,
                                "Wrapped text has {0} characters instead of {1} characters", charCount, expectedCharacterCount);
            }
            else
            {
                Console.WriteLine("Skipped character count validation");
            }
        }