public void RemoveLastNewLine()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("Something awesome!");
            sb.AppendLine();

            string expected = "Something awesome!";

            sb.RemoveLastNewLine();

            Assert.AreEqual(expected, sb.ToString());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Dumps an enumerable type
        /// </summary>
        /// <returns>
        /// The enumerable values as a string
        /// </returns>
        /// <param name="list">
        /// The enumerable instance
        /// </param>
        /// <param name="indendation">
        /// The indendation level
        /// </param>
        /// <param name="prefix">
        /// Text to output before the value
        /// </param>
        private string DumpEnumerable(IEnumerable list, int indendation, string prefix)
        {
            StringBuilder sb = new StringBuilder();

            string countField = "Count";

            // for enumerable-types that are properties,
            // the prefix will be "wrong"
            if (prefix.EndsWith(" = "))
            {
                prefix = prefix.Remove(prefix.Length-3);
                countField = ".Count";
            }

            int index = 0;

            foreach (object cur in list)
            {
                sb.Append(this.Dump(cur, indendation, "{0}[{1}] = ", prefix, index));
                sb.AppendLine();
                index++;
            }

            sb.RemoveLastNewLine();

            string count = String.Format("{0}{1}{2} = {3}", this.MakeIndentation(indendation), prefix, countField, index);

            // if the enuerable is empty, we do
            // not need to do anything else than
            // return the count - especially since
            // we never want to return with a newline
            // at the end
            if (index == 0)
            {
                return count;
            }

            return String.Format("{0}{1}{2}", count, System.Environment.NewLine, sb.ToString());
        }