BuildMessage() 공개 정적인 메소드

Builds up a message, using the Message field of the specified exception as well as any InnerExceptions.
public static BuildMessage ( Exception exception ) : string
exception System.Exception The exception.
리턴 string
예제 #1
0
        /// <summary>
        /// RecordTearDownException appends the message and stacktrace
        /// from an exception arising during teardown of the test
        /// to any previously recorded information, so that any
        /// earlier failure information is not lost. Note that
        /// calling Assert.Ignore, Assert.Inconclusive, etc. during
        /// teardown is treated as an error. If the current result
        /// represents a suite, it may show a teardown error even
        /// though all contained tests passed.
        /// </summary>
        /// <param name="ex">The Exception to be recorded</param>
        public void RecordTearDownException(Exception ex)
        {
            if (ex is NUnitException)
            {
                ex = ex.InnerException;
            }

            ResultState resultState = ResultState == ResultState.Cancelled
                ? ResultState.Cancelled
                : ResultState.Error;

            if (Test.IsSuite)
            {
                resultState = resultState.WithSite(FailureSite.TearDown);
            }

            string message = "TearDown : " + ExceptionHelper.BuildMessage(ex);

            if (Message != null)
            {
                message = Message + NUnit.Env.NewLine + message;
            }

            string stackTrace = "--TearDown" + NUnit.Env.NewLine + ExceptionHelper.BuildStackTrace(ex);

            if (StackTrace != null)
            {
                stackTrace = StackTrace + NUnit.Env.NewLine + stackTrace;
            }

            SetResult(resultState, message, stackTrace);
        }
예제 #2
0
            public ExceptionResult(Exception ex, FailureSite site)
            {
                ex = ValidateAndUnwrap(ex);

                if (ex is ResultStateException)
                {
                    ResultState = ((ResultStateException)ex).ResultState.WithSite(site);
                    Message     = ex.Message;
                    StackTrace  = StackFilter.DefaultFilter.Filter(ex.StackTrace);
                }
#if !NETSTANDARD1_6
                else if (ex is ThreadAbortException)
                {
                    ResultState = ResultState.Cancelled.WithSite(site);
                    Message     = "Test cancelled by user";
                    StackTrace  = ex.StackTrace;
                }
#endif
                else
                {
                    ResultState = ResultState.Error.WithSite(site);
                    Message     = ExceptionHelper.BuildMessage(ex);
                    StackTrace  = ExceptionHelper.BuildStackTrace(ex);
                }
            }
예제 #3
0
            public ExceptionResult(Exception ex, FailureSite site)
            {
                ex = ValidateAndUnwrap(ex);

                if (ex is ResultStateException)
                {
                    ResultState = ((ResultStateException)ex).ResultState.WithSite(site);
                    Message     = ex.GetMessageWithoutThrowing();
                    StackTrace  = StackFilter.DefaultFilter.Filter(ex.GetStackTraceWithoutThrowing());
                }
#if THREAD_ABORT
                else if (ex is ThreadAbortException)
                {
                    ResultState = ResultState.Cancelled.WithSite(site);
                    Message     = "Test cancelled by user";
                    StackTrace  = ex.GetStackTraceWithoutThrowing();
                }
#endif
                else
                {
                    ResultState = ResultState.Error.WithSite(site);
                    Message     = ExceptionHelper.BuildMessage(ex);
                    StackTrace  = ExceptionHelper.BuildStackTrace(ex);
                }
            }
예제 #4
0
        /// <summary>
        /// Set the test result based on the type of exception thrown
        /// </summary>
        /// <param name="ex">The exception that was thrown</param>
        /// <param name="site">THe FailureSite to use in the result</param>
        public void RecordException(Exception ex, FailureSite site)
        {
            if (ex is NUnitException)
            {
                ex = ex.InnerException;
            }

            if (ex is ResultStateException)
            {
                SetResult(((ResultStateException)ex).ResultState.WithSite(site),
                          ex.Message,
                          StackFilter.Filter(ex.StackTrace));
            }
#if !PORTABLE
            else if (ex is System.Threading.ThreadAbortException)
            {
                SetResult(ResultState.Cancelled.WithSite(site),
                          "Test cancelled by user",
                          ex.StackTrace);
            }
#endif
            else
            {
                SetResult(ResultState.Error.WithSite(site),
                          ExceptionHelper.BuildMessage(ex),
                          ExceptionHelper.BuildStackTrace(ex));
            }
        }
예제 #5
0
 public TestParameters(Exception exception)
     : this(RunState.NotRunnable, NoArguments)
 {
     Properties = new PropertyBag();
     Properties.Set(PropertyNames.SkipReason, ExceptionHelper.BuildMessage(exception));
     Properties.Set(PropertyNames.ProviderStackTrace, ExceptionHelper.BuildStackTrace(exception));
 }
예제 #6
0
        public void RecordTearDownException(Exception ex)
        {
            ex = ValidateAndUnwrap(ex);

            ResultState resultState = ResultState == ResultState.Cancelled
                ? ResultState.Cancelled
                : ResultState.Error;

            if (Test.IsSuite)
            {
                resultState = resultState.WithSite(FailureSite.TearDown);
            }

            string message = "TearDown : " + ExceptionHelper.BuildMessage(ex);

            if (Message != null)
            {
                message = Message + Environment.NewLine + message;
            }

            string stackTrace = "--TearDown" + Environment.NewLine + ExceptionHelper.BuildStackTrace(ex);

            if (StackTrace != null)
            {
                stackTrace = StackTrace + Environment.NewLine + stackTrace;
            }

            SetResult(resultState, message, stackTrace);
        }
예제 #7
0
        /// <summary>
        /// Set the test result based on the type of exception thrown
        /// </summary>
        /// <param name="ex">The exception that was thrown</param>
        public void RecordException(Exception ex)
        {
            if (ex is NUnitException)
            {
                ex = ex.InnerException;
            }

            if (ex is System.Threading.ThreadAbortException)
            {
                SetResult(ResultState.Cancelled, "Test cancelled by user", ex.StackTrace);
            }
            else if (ex is AssertionException)
            {
                SetResult(ResultState.Failure, ex.Message, StackFilter.Filter(ex.StackTrace));
            }
            else if (ex is IgnoreException)
            {
                SetResult(ResultState.Ignored, ex.Message, StackFilter.Filter(ex.StackTrace));
            }
            else if (ex is InconclusiveException)
            {
                SetResult(ResultState.Inconclusive, ex.Message, StackFilter.Filter(ex.StackTrace));
            }
            else if (ex is SuccessException)
            {
                SetResult(ResultState.Success, ex.Message, StackFilter.Filter(ex.StackTrace));
            }
            else
            {
                SetResult(ResultState.Error,
                          ExceptionHelper.BuildMessage(ex),
                          ExceptionHelper.BuildStackTrace(ex));
            }
        }
예제 #8
0
파일: TestResult.cs 프로젝트: Corniel/nunit
        /// <summary>
        /// Set the test result based on the type of exception thrown
        /// </summary>
        /// <param name="ex">The exception that was thrown</param>
        public void RecordException(Exception ex)
        {
            if (ex is NUnitException)
            {
                ex = ex.InnerException;
            }

            if (ex is ResultStateException)
            {
                string message    = ex.Message;
                string stackTrace = StackFilter.Filter(ex.StackTrace);

                RecordAssertion(AssertionStatus.Failed, message, stackTrace);
                SetResult(((ResultStateException)ex).ResultState, message, stackTrace);
            }
#if !PORTABLE
            else if (ex is System.Threading.ThreadAbortException)
            {
                SetResult(ResultState.Cancelled,
                          "Test cancelled by user",
                          ex.StackTrace);
            }
#endif
            else
            {
                SetResult(ResultState.Error,
                          ExceptionHelper.BuildMessage(ex),
                          ExceptionHelper.BuildStackTrace(ex));
            }
        }
예제 #9
0
 /// <summary>
 /// Construct a non-runnable ParameterSet, specifying
 /// the provider exception that made it invalid.
 /// </summary>
 public ParameterSet(Exception exception)
 {
     this.RunState   = RunState.NotRunnable;
     this.Properties = new PropertyBag();
     this.Properties.Set(PropertyNames.SkipReason, ExceptionHelper.BuildMessage(exception));
     this.Properties.Set(PropertyNames.ProviderStackTrace, ExceptionHelper.BuildStackTrace(exception));
 }
예제 #10
0
        /// <summary>
        /// RecordTearDownException appends the message and stacktrace
        /// from an exception arising during teardown of the test
        /// to any previously recorded information, so that any
        /// earlier failure information is not lost. Note that
        /// calling Assert.Ignore, Assert.Inconclusive, etc. during
        /// teardown is treated as an error. If the current result
        /// represents a suite, it may show a teardown error even
        /// though all contained tests passed.
        /// </summary>
        /// <param name="ex">The Exception to be recorded</param>
        public void RecordTearDownException(Exception ex)
        {
            if (ex is NUnitException)
            {
                ex = ex.InnerException;
            }

            ResultState resultState = this.ResultState == ResultState.Cancelled
                ? ResultState.Cancelled
                : ResultState.Error;

            string message = "TearDown : " + ExceptionHelper.BuildMessage(ex);

            if (this.Message != null)
            {
                message = this.Message + NUnit.Env.NewLine + message;
            }

            string stackTrace = "--TearDown" + NUnit.Env.NewLine + ExceptionHelper.BuildStackTrace(ex);

            if (this.StackTrace != null)
            {
                stackTrace = this.StackTrace + NUnit.Env.NewLine + stackTrace;
            }

            SetResult(resultState, message, stackTrace);
        }
        public static void SkipsDataSectionOnEmptyData()
        {
            var exception = new Exception("blah");

            var message = ExceptionHelper.BuildMessage(exception);

            Assert.That(message, Contains.Substring("blah"));
            Assert.That(message, !Contains.Substring("Data"));
        }
        public static void NoTrailingNewline()
        {
            var exception = new Exception("blah")
            {
                Data = { ["Foo"] = "Bar" }
            };

            var message = ExceptionHelper.BuildMessage(exception);

            Assert.That(message, Does.Not.EndWith("\n"));
        }
        public static void IncludesNullProperties()
        {
            var exception = new Exception("blah");

            exception.Data["data-prop"] = null;

            var message = ExceptionHelper.BuildMessage(exception);

            Assert.That(message, Contains.Substring("blah"));
            Assert.That(message, Contains.Substring("data-prop"));
            Assert.That(message, Contains.Substring("<null>"));
        }
        public static void AppendsDataItemsToExceptionMessage()
        {
            var exception = new Exception("blah");

            exception.Data["data-prop"] = "data-value";

            var message = ExceptionHelper.BuildMessage(exception);

            Assert.That(message, Contains.Substring("blah"));
            Assert.That(message, Contains.Substring("data-prop"));
            Assert.That(message, Contains.Substring("data-value"));
        }
예제 #15
0
        /// <summary>
        /// Set the test result based on the type of exception thrown
        /// </summary>
        /// <param name="ex">The exception that was thrown</param>
        public void RecordException(Exception ex)
        {
            if (ex is NUnitException)
            {
                ex = ex.InnerException;
            }

            if (ex is ResultStateException)
            {
                string message    = ex.Message;
                string stackTrace = StackFilter.DefaultFilter.Filter(ex.StackTrace);

                SetResult(((ResultStateException)ex).ResultState, message, stackTrace);
            }
#if !PORTABLE
            else if (ex is System.Threading.ThreadAbortException)
            {
                SetResult(ResultState.Cancelled,
                          "Test cancelled by user",
                          ex.StackTrace);
            }
#endif
            else
            {
                string message    = ExceptionHelper.BuildMessage(ex);
                string stackTrace = ExceptionHelper.BuildStackTrace(ex);
                SetResult(ResultState.Error, message, stackTrace);

                if (AssertionResults.Count > 0)
                {
                    // Add pending failures to the legacy result message
                    var writer = new StringWriter();

                    writer.WriteLine("\n  Multiple Assert block had {0} failure(s).", AssertionResults.Count);

                    int counter = 0;
                    foreach (var assertion in AssertionResults)
                    {
                        writer.WriteLine(string.Format("  {0}) {1}", ++counter, assertion.Message));
                    }

                    Message += writer.ToString();

                    // Add to the list of assertion errors, so that newer runners will see it
                    AssertionResults.Add(new AssertionResult(AssertionStatus.Error, message, stackTrace));
                }
            }
        }
예제 #16
0
        /// <summary>
        /// Set the test result based on the type of exception thrown
        /// </summary>
        /// <param name="ex">The exception that was thrown</param>
        public void RecordException(Exception ex)
        {
            if (ex is NUnitException)
            {
                ex = ex.InnerException;
            }

#if MONO
            exceptionType = ex?.GetType().ToString();
#endif

            if (ex is System.Threading.ThreadAbortException)
            {
                SetResult(ResultState.Cancelled, "Test cancelled by user", ex.StackTrace);
            }
            else if (ex is AssertionException)
            {
                SetResult(ResultState.Failure, ex.Message, StackFilter.Filter(ex.StackTrace));
            }
            else if (ex is IgnoreException)
            {
                SetResult(ResultState.Ignored, ex.Message, StackFilter.Filter(ex.StackTrace));
            }
            else if (ex is InconclusiveException)
            {
                SetResult(ResultState.Inconclusive, ex.Message, StackFilter.Filter(ex.StackTrace));
            }
            else if (ex is SuccessException)
            {
                SetResult(ResultState.Success, ex.Message, StackFilter.Filter(ex.StackTrace));
            }
            else
            {
                MethodInfo write = null;
                if (Environment.GetEnvironmentVariable("MONO_TEST_TELEMETRY") != null)
                {
                    write = Type.GetType("Mono.Runtime", false).GetMethod("WriteStateToDisk", BindingFlags.NonPublic | BindingFlags.Static);
                }
                if (write != null)
                {
                    write.Invoke(null, new object [] { ex });
                }

                SetResult(ResultState.Error,
                          ExceptionHelper.BuildMessage(ex),
                          ExceptionHelper.BuildStackTrace(ex));
            }
        }
예제 #17
0
        /// <summary>
        /// Set the test result based on the type of exception thrown
        /// </summary>
        /// <param name="ex">The exception that was thrown</param>
        public void RecordException(Exception ex)
        {
            if (ex is NUnitException || ex is TargetInvocationException)
            {
                ex = ex.InnerException;
            }

            if (ex is AssertionException)
            {
                AssertionResults.Add(new AssertionResult(AssertionStatus.Failed, ex.Message, StackFilter.DefaultFilter.Filter(ex.StackTrace)));
            }

            if (ex is ResultStateException)
            {
                string message = ex is MultipleAssertException
                    ? CreateLegacyFailureMessage()
                    : ex.Message;

                string stackTrace = StackFilter.DefaultFilter.Filter(ex.StackTrace);

                SetResult(((ResultStateException)ex).ResultState, message, stackTrace);
            }
#if !NETSTANDARD1_3 && !NETSTANDARD1_6
            else if (ex is System.Threading.ThreadAbortException)
            {
                SetResult(ResultState.Cancelled,
                          "Test cancelled by user",
                          ex.StackTrace);
            }
#endif
            else
            {
                string message    = ExceptionHelper.BuildMessage(ex);
                string stackTrace = ExceptionHelper.BuildStackTrace(ex);
                SetResult(ResultState.Error, message, stackTrace);

                if (AssertionResults.Count > 0)
                {
                    // Add pending failures to the legacy result message
                    Message += CreateLegacyFailureMessage();

                    // Add to the list of assertion errors, so that newer runners will see it
                    AssertionResults.Add(new AssertionResult(AssertionStatus.Error, message, stackTrace));
                }
            }
        }
예제 #18
0
 public static void BuildMessageThrowsForNullException()
 {
     Assert.That(() => ExceptionHelper.BuildMessage(null), Throws.ArgumentNullException.With.Property("ParamName").EqualTo("exception"));
 }