public void JustMessage()
        {
            string myMessage = "Four score and seven years ago ...";
            MultiLineException exception = new MultiLineException(myMessage);

            Assert.IsNull(exception.InnerException);
            Assert.AreEqual(myMessage, exception.Message);
            Assert.AreEqual(1, exception.MultiLineMessage.Count);
            Assert.AreEqual(myMessage, exception.MultiLineMessage[0]);
        }
        public void JustMessage_MultiLine()
        {
            string[] lines = new string[]{ "Roses are red",
                                           "Violets are blue" };
            MultiLineText message = new MultiLineText(lines);
            MultiLineException exception = new MultiLineException(message);

            Assert.IsNull(exception.InnerException);
            Assert.AreEqual(message.ToString(), exception.Message);
            Assert.AreEqual(lines.Length, exception.MultiLineMessage.Count);
            for (int i = 0; i < lines.Length; i++)
                Assert.AreEqual(lines[i], exception.MultiLineMessage[i]);
        }
 public void NullMessageWithInnerMessage()
 {
     MultiLineException exception = new MultiLineException(null, "");
 }
 public void NullMessageAndInnerException()
 {
     System.Exception nullException = null;
     MultiLineException exception = new MultiLineException(null, nullException);
 }
 public void NullMessage()
 {
     MultiLineException exception = new MultiLineException(null);
 }
        //---------------------------------------------------------------------

        private void Inner_MultiLineMessage()
        {
            string innerInnerMessage = "Damn it, Jim, I'm a doctor, not a bricklayer!";
            System.ApplicationException innerInner = new System.ApplicationException(innerInnerMessage);

            string innerMessage = "The quick brown fox";
            MultiLineException inner = new MultiLineException(innerMessage,
                                                              innerInner);

            string myMessage = "Four score and seven years ago ...";
            MultiLineException exception = new MultiLineException(myMessage,
                                                                  inner);

            Assert.AreEqual(inner, exception.InnerException);
            Assert.AreEqual(3, exception.MultiLineMessage.Count);
            Assert.AreEqual(myMessage + ":", exception.MultiLineMessage[0]);
            Assert.AreEqual(MultiLineException.Indent + innerMessage + ":",
                            exception.MultiLineMessage[1]);
            Assert.AreEqual(MultiLineException.Indent +
                            MultiLineException.Indent + innerInnerMessage,
                            exception.MultiLineMessage[2]);
        }
        //---------------------------------------------------------------------

        private void Inner_NoMultiLineMessage()
        {
            string innerMessage = "The quick brown fox";
            System.ApplicationException inner = new System.ApplicationException(innerMessage);

            string myMessage = "Four score and seven years ago ...";
            MultiLineException exception = new MultiLineException(myMessage,
                                                                  inner);

            Assert.AreEqual(inner, exception.InnerException);
            Assert.AreEqual(2, exception.MultiLineMessage.Count);
            Assert.AreEqual(myMessage + ":", exception.MultiLineMessage[0]);
            Assert.AreEqual(MultiLineException.Indent + innerMessage,
                            exception.MultiLineMessage[1]);
        }
        public void MessageAndInner()
        {
            string myMessage = "Four score and seven years ago ...";
            string innerMessage = "The quick brown fox";
            MultiLineException exception = new MultiLineException(myMessage,
                                                                  innerMessage);

            Assert.IsNull(exception.InnerException);
            Assert.AreEqual(2, exception.MultiLineMessage.Count);
            Assert.AreEqual(myMessage + ":", exception.MultiLineMessage[0]);
            Assert.AreEqual(MultiLineException.Indent + innerMessage,
                            exception.MultiLineMessage[1]);
        }
        //---------------------------------------------------------------------
        public LineReaderException ExtraTextException(string message,
            string text)
        {
            //  For readability, trim the text down to first 60 characters
            bool trimmed = false;
            const int displayLength = 60;
            if (text.Length > displayLength) {
                text = text.Substring(0, displayLength);
                trimmed = true;
            }

            //  Also for readability, trim off from 1st newline or return char.
            int index = text.IndexOfAny(new char[]{'\n', '\r'});
            if (index >= 0) {
                text = text.Substring(0, index);
                trimmed = true;
            }

            StringBuilder extraText = new StringBuilder();
            extraText.AppendFormat("\"{0}\"", text);
            if (trimmed)
                extraText.Append("...");

            MultiLineException innerException = new MultiLineException(message,
                                                                       extraText.ToString());
            return new LineReaderException(reader, innerException);
        }