Example #1
0
        /// <summary>
        /// Check a string text specified format
        /// </summary>
        /// <param name="format">format</param>
        /// <param name="lines">array of strings</param>
        public void CheckStringTextByFormat(DrCmdTextBuilderFormat format, string[] lines)
        {
            int lineCount = 0;

            foreach (var line in lines)
            {
                lineCount++;
                if ((format.Justify) && (lineCount != lines.Length)) // exclude the last line
                {
                    Assert.IsTrue(line.Length == format.Width,
                                  "Enabled aligned left and right, the string width must be equals format width.");
                }
                else
                {
                    Assert.IsTrue(line.Length <= format.Width,
                                  "The string width must be less or equals format width.");
                }
                if (format.MarginLeftChars != 0)
                {
                    Assert.IsTrue(line.StartsWith(format.SpaceLeft),
                                  String.Format("Each line must begin with '{0}' gaps.",
                                                format.MarginLeftChars.ToString()));
                }
                Assert.IsFalse(line[format.MarginLeftChars] == ' ',
                               "Each line should not start with a space include left margin.");
            }
        }
Example #2
0
        public void ValidateFormatedText(DrCmdTextBuilderFormat format, string original, string formated)
        {
            var lines = formated.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            CheckStringTextByFormat(format, lines);
            IntegrityTextCheck(original, formated);
        }
Example #3
0
        public static void TestGetElementCountForNewLine(string[] words, DrCmdTextBuilderFormat format,
                                                         int startIndex)
        {
            var actual   = DrCmdTextBuilder.GetElementCountForNewLine(startIndex, format, words);
            var length   = 0;
            int expected = startIndex;

            while (expected < words.Length)
            {
                length += words[expected].Length + 1;
                expected++;
                if ((expected < words.Length) && (length + words[expected].Length > format.Length))
                {
                    break;
                }
            }
            expected = expected - startIndex;
            Assert.AreEqual(expected, actual,
                            string.Format("Actual element count'{0}' not equals expected '{1}'.", actual, expected));
            var lineLenght = String.Join(" ", words, startIndex, actual);

            Assert.IsTrue(lineLenght.Length <= format.Length,
                          string.Format("Actual text '{0}' not equals format.lenght '{1}'.", lineLenght,
                                        format.Length));
            // The next element can be joined to line.
            if (expected + startIndex + 1 < words.Length)
            {
                Assert.IsFalse(
                    ((lineLenght.Length + 1 + words[startIndex + expected + 1].Length) <= format.Length),
                    "The next element can be joined to line.");
            }
        }
Example #4
0
        public void TestBuildTextJustifyTrue()
        {
            var marginLeft = 10;
            var textWidth  = 80;
            var justify    = true;

            var drTextFormat     = new DrCmdTextBuilderFormat(marginLeft, textWidth, justify, false);
            var drCmdTextBuilder = new DrCmdTextBuilder(drTextFormat);
            var result           = drCmdTextBuilder.BuildText(textSample1);

            ValidateFormatedText(drTextFormat, textSample1, result);
        }