/// <summary>
        /// Creates a fallback markup document writer with the specified provider.
        /// </summary>
        /// <param name="primary">The markup document writer to call by default.</param>
        /// <param name="fallback">The markup document to call as a fallback.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="primary"/>
        /// or <paramref name="fallback"/> is null.</exception>
        public FallbackMarkupDocumentWriter(MarkupDocumentWriter primary, MarkupDocumentWriter fallback)
        {
            if (primary == null)
                throw new ArgumentNullException("primary");
            if (fallback == null)
                throw new ArgumentNullException("fallback");

            this.primary = primary;
            this.fallback = fallback;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a markup stream writer.
        /// </summary>
        /// <param name="container">The containing markup document writer.</param>
        /// <param name="streamName">The stream name.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="container"/>
        /// or <paramref name="streamName"/> is null.</exception>
        public MarkupStreamWriter(MarkupDocumentWriter container, string streamName)
        {
            if (container == null)
                throw new ArgumentNullException("container");
            if (streamName == null)
                throw new ArgumentNullException(@"streamName");

            this.container = container;
            this.streamName = streamName;

            NewLine = "\n";
        }
        /// <summary>
        /// Creates a fallback markup document writer with the specified provider.
        /// </summary>
        /// <param name="primary">The markup document writer to call by default.</param>
        /// <param name="fallback">The markup document to call as a fallback.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="primary"/>
        /// or <paramref name="fallback"/> is null.</exception>
        public FallbackMarkupDocumentWriter(MarkupDocumentWriter primary, MarkupDocumentWriter fallback)
        {
            if (primary == null)
            {
                throw new ArgumentNullException("primary");
            }
            if (fallback == null)
            {
                throw new ArgumentNullException("fallback");
            }

            this.primary  = primary;
            this.fallback = fallback;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a markup stream writer.
        /// </summary>
        /// <param name="container">The containing markup document writer.</param>
        /// <param name="streamName">The stream name.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="container"/>
        /// or <paramref name="streamName"/> is null.</exception>
        public MarkupStreamWriter(MarkupDocumentWriter container, string streamName)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }
            if (streamName == null)
            {
                throw new ArgumentNullException(@"streamName");
            }

            this.container  = container;
            this.streamName = streamName;

            NewLine = "\n";
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Writes the contents of the document to a markup document writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="writer"/> is null.</exception>
        public void WriteTo(MarkupDocumentWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            foreach (AttachmentData attachment in attachments)
            {
                writer.Attach(Attachment.FromAttachmentData(attachment));
            }

            foreach (StructuredStream stream in streams)
            {
                stream.WriteTo(writer[stream.Name]);
            }
        }
Ejemplo n.º 6
0
        private TestOutcome HandleAbort(MarkupDocumentWriter markupDocumentWriter, string actionDescription, ThreadAbortException ex)
        {
            TestOutcome outcome = abortOutcome.Value;
            if (ex == null && alreadyLoggedAbortOnce)
                return outcome;

            alreadyLoggedAbortOnce = true;
            LogMessage(markupDocumentWriter, actionDescription, outcome, abortMessage, null);
            return outcome;
        }
Ejemplo n.º 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));
            }
        }
Ejemplo n.º 8
0
 private static MarkupStreamWriter GetLogStreamWriterForOutcome(MarkupDocumentWriter markupDocumentWriter, TestOutcome outcome)
 {
     switch (outcome.Status)
     {
         case TestStatus.Passed:
             return markupDocumentWriter.Default;
         case TestStatus.Failed:
             return markupDocumentWriter.Failures;
         default:
             return markupDocumentWriter.Warnings;
     }
 }
Ejemplo n.º 9
0
        public TestOutcome Run(MarkupDocumentWriter markupDocumentWriter, Action action, string description)
        {
            // NOTE: This method has been optimized to minimize the total stack depth of the action
            //       by inlining blocks on the critical path that had previously been factored out.

            if (markupDocumentWriter == null)
                throw new ArgumentNullException("markupDocumentWriter");
            if (action == null)
                throw new ArgumentNullException("action");

            ThreadAbortScope scope = null;
            try
            {
                lock (syncRoot)
                {
                    ThrowIfDisposed();

                    if (!abortOutcome.HasValue)
                    {
                        if (scopesAndThreads == null)
                            scopesAndThreads = new List<Pair<ThreadAbortScope, Thread>>();

                        scope = new ThreadAbortScope();
                        scopesAndThreads.Add(new Pair<ThreadAbortScope, Thread>(scope, Thread.CurrentThread));
                    }
                }

                if (scope == null)
                    return HandleAbort(markupDocumentWriter, description, null);

                // Run the action within the scope we have acquired.
                try
                {
                    ThreadAbortException ex = scope.Run(action);
                    if (ex != null)
                        return HandleAbort(markupDocumentWriter, description, ex);

                    return TestOutcome.Passed;
                }
                catch (Exception ex)
                {
                    // If the test itself threw a thread abort, not because we aborted it
                    // ourselves but most likely due to a bug in the test subject, then we
                    // prevent the abort from bubbling up any further.
                    if (ex is ThreadAbortException &&
                        !AppDomain.CurrentDomain.IsFinalizingForUnload())
                        Thread.ResetAbort();

                    TestOutcome outcome;
                    TestException testException = ex as TestException;
                    if (testException != null)
                    {
                        outcome = testException.Outcome;

                        if (testException.ExcludeStackTrace)
                            LogMessage(markupDocumentWriter, description, outcome, testException.HasNonDefaultMessage ? testException.Message : null, null);
                        else
                            LogMessage(markupDocumentWriter, description, outcome, null, testException);
                    }
                    else
                    {
                        outcome = TestOutcome.Failed;
                        LogMessage(markupDocumentWriter, description, outcome, null, ex);
                    }

                    return outcome;
                }
            }
            finally
            {
                if (scope != null)
                {
                    lock (syncRoot)
                    {
                        if (scopesAndThreads != null)
                        {
                            for (int i = 0; i < scopesAndThreads.Count; i++)
                                if (scopesAndThreads[i].First == scope)
                                    scopesAndThreads.RemoveAt(i);
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Writes the contents of the document to a markup document writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="writer"/> is null.</exception>
        public void WriteTo(MarkupDocumentWriter writer)
        {
            if (writer == null)
                throw new ArgumentNullException("writer");

            foreach (AttachmentData attachment in attachments)
                writer.Attach(Attachment.FromAttachmentData(attachment));

            foreach (StructuredStream stream in streams)
                stream.WriteTo(writer[stream.Name]);
        }