コード例 #1
0
        /// <summary>
        /// Creates a logger for the markup stream writer.
        /// </summary>
        /// <param name="writer">The markup stream writer.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="writer"/> is null.</exception>
        public MarkupStreamLogger(MarkupStreamWriter writer)
        {
            if (writer == null)
                throw new ArgumentNullException("writer");

            this.writer = writer;
        }
コード例 #2
0
        private void WritePreambleTo(MarkupStreamWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            foreach (Attachment attachment in attachments)
            {
                writer.Container.Attach(attachment);
            }
        }
コード例 #3
0
        /// <summary>
        /// Writes the contents of the stream to a markup stream writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="writer"/> is null.</exception>
        public void WriteTo(MarkupStreamWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            if (body != null)
            {
                body.WriteTo(writer);
            }
        }
コード例 #4
0
        /// <summary>
        /// Writes the structured text to a markup stream writer and truncates its text
        /// to a particular maximum length, omitting all subsequent contents.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="maxLength">The maximum length of text to write.</param>
        /// <returns>True if truncation occurred.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="writer"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="maxLength"/> is negative.</exception>
        public bool TruncatedWriteTo(MarkupStreamWriter writer, int maxLength)
        {
            if (maxLength < 0)
            {
                throw new ArgumentOutOfRangeException("maxLength", "Max length must not be negative.");
            }
            WritePreambleTo(writer);

            TruncateTextVisitor visitor = new TruncateTextVisitor(writer, maxLength);

            bodyTag.Accept(visitor);
            return(visitor.Truncating);
        }
コード例 #5
0
ファイル: DiffSet.cs プロジェクト: dougrathbone/mbunit-v3
 private static void WriteContext(MarkupStreamWriter writer, Substring context, int maxContextLength)
 {
     if (context.Length < maxContextLength)
     {
         writer.Write(context.ToString());
     }
     else
     {
         int split = maxContextLength / 2;
         if (split > 0)
         {
             writer.Write(context.Extract(0, split).ToString());
             writer.WriteEllipsis();
             writer.Write(context.Extract(context.Length - split));
         }
     }
 }
コード例 #6
0
ファイル: DiffSet.cs プロジェクト: dougrathbone/mbunit-v3
 /// <summary>
 /// Writes the diffs using the specified
 /// presentation style and no limits on the context length.
 /// </summary>
 /// <remarks>
 /// <para>
 /// Changes are annotated by markers: <see cref="Marker.DiffAddition" />, <see cref="Marker.DiffDeletion" />
 /// and <see cref="Marker.DiffChange" />.
 /// </para>
 /// <para>
 /// If the style is <see cref="DiffStyle.Interleaved" /> then the left document
 /// is considered the original and the right document is the considered to be the
 /// one that was modified so deletions appear within the left and additions within the right.
 /// </para>
 /// <para>
 /// If the style is <see cref="DiffStyle.LeftOnly" /> or <see cref="DiffStyle.RightOnly" />
 /// then only the deletion and changed markers are used.
 /// </para>
 /// </remarks>
 /// <param name="writer">The test log stream writer to receive the highlighted document.</param>
 /// <param name="style">The presentation style.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref nameref="writer" /> if null.</exception>
 public void WriteTo(MarkupStreamWriter writer, DiffStyle style)
 {
     WriteTo(writer, style, int.MaxValue);
 }
コード例 #7
0
ファイル: DiffSet.cs プロジェクト: dougrathbone/mbunit-v3
        /// <summary>
        /// Writes the diffs using the specified presentation style and max context length.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Changes are annotated by markers: <see cref="Marker.DiffAddition" />, <see cref="Marker.DiffDeletion" />
        /// and <see cref="Marker.DiffChange" />.
        /// </para>
        /// <para>
        /// If the style is <see cref="DiffStyle.Interleaved" /> then the left document
        /// is considered the original and the right document is the considered to be the
        /// one that was modified so deletions appear within the left and additions within the right.
        /// </para>
        /// <para>
        /// If the style is <see cref="DiffStyle.LeftOnly" /> or <see cref="DiffStyle.RightOnly" />
        /// then only the deletion and changed markers are used.
        /// </para>
        /// </remarks>
        /// <param name="writer">The test log stream writer to receive the highlighted document.</param>
        /// <param name="style">The presentation style.</param>
        /// <param name="maxContextLength">The maximum number of characters of unchanged regions
        /// to display for context, or <see cref="int.MaxValue" /> for no limit.  Extraneous context
        /// is split in two with an ellipsis inserted in between both halves.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref nameref="writer" /> if null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="maxContextLength"/>
        /// is negative.</exception>
        public void WriteTo(MarkupStreamWriter writer, DiffStyle style, int maxContextLength)
        {
            if (writer == null)
                throw new ArgumentNullException("writer");
            if (maxContextLength < 0)
                throw new ArgumentOutOfRangeException("maxContextLength");

            foreach (Diff diff in diffs)
            {
                if (diff.Kind == DiffKind.NoChange)
                {
                    WriteContext(writer, new Substring(leftDocument, diff.LeftRange), maxContextLength);
                }
                else
                {
                    if (diff.LeftRange.Length != 0)
                    {
                        switch (style)
                        {
                            case DiffStyle.Interleaved:
                                using (writer.BeginMarker(Marker.DiffDeletion))
                                    writer.Write(diff.LeftRange.SubstringOf(leftDocument));
                                break;

                            case DiffStyle.LeftOnly:
                                using (writer.BeginMarker(diff.RightRange.Length == 0 ? Marker.DiffDeletion : Marker.DiffChange))
                                    writer.Write(diff.LeftRange.SubstringOf(leftDocument));
                                break;
                        }
                    }

                    if (diff.RightRange.Length != 0)
                    {
                        switch (style)
                        {
                            case DiffStyle.Interleaved:
                                using (writer.BeginMarker(Marker.DiffAddition))
                                    writer.Write(diff.RightRange.SubstringOf(rightDocument));
                                break;

                            case DiffStyle.RightOnly:
                                using (writer.BeginMarker(diff.LeftRange.Length == 0 ? Marker.DiffDeletion : Marker.DiffChange))
                                    writer.Write(diff.RightRange.SubstringOf(rightDocument));
                                break;
                        }
                    }
                }
            }
        }
コード例 #8
0
 public TruncateTextVisitor(MarkupStreamWriter writer, int maxLength)
 {
     this.writer    = writer;
     this.maxLength = maxLength;
 }
コード例 #9
0
ファイル: DiffSet.cs プロジェクト: dougrathbone/mbunit-v3
 /// <summary>
 /// Writes the diffs using the <see cref="DiffStyle.Interleaved" />
 /// presentation style and no limits on the context length.
 /// </summary>
 /// <remarks>
 /// <para>
 /// For the purposes of determining additions and deletions, the left document
 /// is considered the original and the right document is the considered to be the
 /// one that was modified.  Changes are annotated by markers:
 /// by <see cref="Marker.DiffAddition" />, <see cref="Marker.DiffDeletion" />
 /// and <see cref="Marker.DiffChange" />.
 /// </para>
 /// </remarks>
 /// <param name="writer">The test log stream writer to receive the highlighted document.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref nameref="writer" /> if null.</exception>
 public void WriteTo(MarkupStreamWriter writer)
 {
     WriteTo(writer, DiffStyle.Interleaved, int.MaxValue);
 }
コード例 #10
0
 /// <inheritdoc />
 public void WriteTo(MarkupStreamWriter writer)
 {
     ToStructuredText().WriteTo(writer);
 }
コード例 #11
0
        /// <summary>
        /// Writes the assertion failure to a test log stream.
        /// </summary>
        /// <param name="writer">The test log stream.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="writer"/> is null.</exception>
        public virtual void WriteTo(MarkupStreamWriter writer)
        {
            if (writer == null)
                throw new ArgumentNullException("writer");

            using (writer.BeginMarker(Marker.AssertionFailure))
            {
                using (writer.BeginSection(description))
                {
                    WriteDetails(writer);

                    foreach (AssertionFailure innerFailure in innerFailures)
                        innerFailure.WriteTo(writer);
                }
            }
        }
コード例 #12
0
ファイル: Tasks.cs プロジェクト: dougrathbone/mbunit-v3
        private static void ConfigureProcessTaskForLogging(ProcessTask task, MarkupStreamWriter writer)
        {
            task.Started += delegate
            {
                writer.BeginSection(String.Format("Run Process: {0} {1}", task.ExecutablePath, task.Arguments));
                writer.WriteLine("Working Directory: {0}", task.WorkingDirectory);
                writer.BeginMarker(Marker.Monospace);
            };

            task.ConsoleOutputDataReceived += delegate(object sender, DataReceivedEventArgs e)
            {
                if (e.Data != null)
                    writer.WriteLine(e.Data);
            };

            task.ConsoleErrorDataReceived += delegate(object sender, DataReceivedEventArgs e)
            {
                if (e.Data != null)
                    writer.WriteLine(e.Data);
            };

            task.Aborted += delegate
            {
                if (task.IsRunning)
                    writer.BeginSection("Abort requested.  Killing the process!").Dispose();
            };

            task.Terminated += delegate
            {
                writer.End();
                writer.WriteLine("Exit Code: {0}", task.ExitCode);
                writer.End();
            };
        }
コード例 #13
0
 public RegionCookie(MarkupStreamWriter writer)
 {
     this.writer = writer;
 }
コード例 #14
0
        /// <summary>
        /// Writes the details about the assertion failure to the structured text writer.
        /// </summary>
        /// <param name="writer">The structured text writer, not null.</param>
        protected virtual void WriteDetails(MarkupStreamWriter writer)
        {
            if (!string.IsNullOrEmpty(message))
                writer.WriteLine(message);

            if (labeledValues.Count != 0)
            {
                writer.WriteLine();

                using (writer.BeginMarker(Marker.Monospace))
                {
                    int paddedLength = ComputePaddedLabelLength();
                    foreach (LabeledValue labeledValue in labeledValues)
                    {
                        WriteLabel(writer, labeledValue.Label, paddedLength);
                        WriteFormattedValue(writer, labeledValue.FormattedValue);
                        writer.WriteLine();
                    }
                }
            }

            if (exceptions.Count != 0)
            {
                foreach (ExceptionData exception in exceptions)
                {
                    writer.WriteLine();
                    writer.WriteException(exception);
                    writer.WriteLine();
                }
            }

            if (stackTrace != null && !stackTrace.IsEmpty)
            {
                writer.WriteLine();
                stackTrace.WriteTo(writer);
                writer.WriteLine();
            }
        }
コード例 #15
0
 public override void WriteTo(MarkupStreamWriter writer)
 {
     wasWriteToCalled = true;
     base.WriteTo(writer);
 }
コード例 #16
0
 private static void WriteTruncated(MarkupStreamWriter writer, StructuredText text, int maxLength)
 {
     if (text.TruncatedWriteTo(writer, maxLength))
         writer.WriteEllipsis();
 }
コード例 #17
0
 private static void WriteLabel(MarkupStreamWriter writer, string label, int paddedLength)
 {
     using (writer.BeginMarker(Marker.Label))
     {
         WriteTruncated(writer, new StructuredText(label), MaxLabelLengthBeforeTruncation);
         WritePaddingSpaces(writer, paddedLength - label.Length);
         writer.Write(@" : ");
     }
 }
コード例 #18
0
 private static void WriteFormattedValue(MarkupStreamWriter writer, StructuredText formattedValue)
 {
     WriteTruncated(writer, formattedValue, MaxFormattedValueLength);
 }
コード例 #19
0
 /// <inheritdoc />
 public void WriteTo(MarkupStreamWriter writer)
 {
     ToStructuredText().WriteTo(writer);
 }
コード例 #20
0
        /// <summary>
        /// Writes the structured text to a markup stream writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="writer"/> is null.</exception>
        public void WriteTo(MarkupStreamWriter writer)
        {
            WritePreambleTo(writer);

            bodyTag.WriteTo(writer);
        }
コード例 #21
0
 public RegionCookie(MarkupStreamWriter writer)
 {
     this.writer = writer;
 }
コード例 #22
0
        /// <summary>
        /// Writes the contents of the stream to a markup stream writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="writer"/> is null.</exception>
        public void WriteTo(MarkupStreamWriter writer)
        {
            if (writer == null)
                throw new ArgumentNullException("writer");

            if (body != null)
                body.WriteTo(writer);
        }