示例#1
0
        /// <summary>
        /// Writes the exception in a structured format with markers to distinguish its component elements.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The exception will not be terminated by a new line.
        /// </para>
        /// </remarks>
        /// <param name="writer">The log stream writer.</param>
        /// <param name="useStandardFormatting">If true, strictly follows the standard .Net
        /// exception formatting by excluding the display of exception properties.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="writer"/> is null.</exception>
        public void WriteTo(MarkupStreamWriter writer, bool useStandardFormatting)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            using (writer.BeginMarker(Marker.Exception))
            {
                using (writer.BeginMarker(Marker.ExceptionType))
                    writer.Write(type);

                if (message.Length != 0)
                {
                    writer.Write(@": ");
                    using (writer.BeginMarker(Marker.ExceptionMessage))
                        writer.Write(message);
                }

                if (innerException != null)
                {
                    writer.Write(@" ---> ");
                    innerException.WriteTo(writer);
                    writer.Write(Environment.NewLine);
                    writer.Write(@"   --- ");
                    writer.Write("End of inner exception stack trace"); // todo localize me
                    writer.Write(@" ---");
                }

                if (!useStandardFormatting)
                {
                    foreach (KeyValuePair <string, string> property in properties)
                    {
                        writer.WriteLine();
                        using (writer.BeginMarker(Marker.ExceptionPropertyName))
                            writer.Write(property.Key);
                        writer.Write(@": ");
                        using (writer.BeginMarker(Marker.ExceptionPropertyValue))
                            writer.Write(property.Value);
                    }
                }

                if (!stackTrace.IsEmpty)
                {
                    writer.WriteLine();
                    stackTrace.WriteTo(writer);
                }
            }
        }
示例#2
0
        public static void Snapshot(IE ie, string caption, MarkupStreamWriter logStreamWriter)
        {
            using (logStreamWriter.BeginSection(caption))
            {
                logStreamWriter.Write("Url: ");
                using (logStreamWriter.BeginMarker(Marker.Link(ie.Url)))
                    logStreamWriter.Write(ie.Url);
                logStreamWriter.WriteLine();

                logStreamWriter.EmbedImage(caption + ".png", new CaptureWebPage(ie).CaptureWebPageImage(false, false, 100));
            }
        }
示例#3
0
        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();
            };
        }
示例#4
0
        /// <excludedoc />
        protected override void LogImpl(LogSeverity severity, string message, ExceptionData exceptionData)
        {
            message = String.Format("[{0}] {1}", severity.ToString().ToLowerInvariant(), message);

            if (exceptionData != null)
            {
                writer.WriteException(exceptionData, message);
            }
            else
            {
                writer.WriteLine(message);
            }
        }
            void ITestListener.OnTestFailed(object sender, TestResultEventArgs args)
            {
                TestFinished(TestOutcome.Failed, args.ClassName, args.MethodName, args.AssertCount, args.Duration, args.Reason,
                             delegate(ITestContext context)
                {
                    if (args.Failure != null)
                    {
                        MarkupStreamWriter log = context.LogWriter.Failures;

                        using (log.BeginSection(Resources.CSUnitTestController_ResultMessageSectionName))
                        {
                            if (!String.IsNullOrEmpty(args.Failure.Expected))
                            {
                                log.WriteLine(args.Failure.Expected);
                            }
                            if (!String.IsNullOrEmpty(args.Failure.Actual))
                            {
                                log.WriteLine(args.Failure.Actual);
                            }
                            if (!String.IsNullOrEmpty(args.Failure.Message))
                            {
                                log.WriteLine(args.Failure.Message);
                            }
                        }

                        using (log.BeginSection(Resources.CSUnitTestController_ResultStackTraceSectionName))
                        {
                            using (log.BeginMarker(Marker.StackTrace))
                            {
                                log.Write(args.Failure.StackTrace);
                            }
                        }
                    }
                });
                Interlocked.Increment(ref fixtureFailureCount);
            }
示例#6
0
        private void Launch(bool doNoRun)
        {
            MarkupStreamWriter logStreamWriter = TestLog.Default;

            var launcher = new TestLauncher();

            launcher.TestProject.TestPackage = testPackage;
            launcher.Logger = new MarkupStreamLogger(logStreamWriter);
            launcher.TestExecutionOptions.FilterSet    = new FilterSet <ITestDescriptor>(new OrFilter <ITestDescriptor>(filters));
            launcher.TestProject.TestRunnerFactoryName = TestRunnerFactoryName;

            string reportDirectory = SpecialPathPolicy.For <SampleRunner>().GetTempDirectory().FullName;

            launcher.TestProject.ReportDirectory  = reportDirectory;
            launcher.TestProject.ReportNameFormat = "SampleRunnerReport";
            launcher.ReportFormatterOptions.AddProperty(@"SaveAttachmentContents", @"false");
            launcher.AddReportFormat(@"Text");
            // Disabled because the Xml can get really big and causes problems if the sample runner is used frequently.
            //launcher.AddReportFormat("Xml");

            launcher.DoNotRun = doNoRun;

            GenericCollectionUtils.ForEach(testRunnerOptions.Properties, x => launcher.TestRunnerOptions.AddProperty(x.Key, x.Value));

            using (logStreamWriter.BeginSection("Log Output"))
                result = launcher.Run();

            using (logStreamWriter.BeginSection("Text Report"))
            {
                foreach (string reportPath in result.ReportDocumentPaths)
                {
                    string extension = Path.GetExtension(reportPath);
                    if (extension == ".txt")
                    {
                        logStreamWriter.WriteLine(File.ReadAllText(reportPath));
                    }
                    else if (extension == ".xml")
                    {
                        logStreamWriter.Container.AttachXml(null, File.ReadAllText(reportPath));
                    }

                    File.Delete(reportPath);
                }
            }
        }
示例#7
0
        private static void LogMessage(MarkupDocumentWriter markupDocumentWriter, string actionDescription, TestOutcome outcome, string message, Exception ex)
        {
            if (string.IsNullOrEmpty(message) && ex == null)
            {
                return;
            }

            MarkupStreamWriter stream = GetLogStreamWriterForOutcome(markupDocumentWriter, outcome);

            using (actionDescription != null ? stream.BeginSection(actionDescription) : null)
            {
                if (!string.IsNullOrEmpty(message))
                {
                    stream.WriteLine(message);
                }

                if (ex != null)
                {
                    stream.WriteException(StackTraceFilter.FilterException(ex));
                }
            }
        }
示例#8
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();
            }
        }