public void TestFailed(string testName, ExceptionInfo exceptionInfo)
		{
			if (String.IsNullOrEmpty(testName))
			{
				return;
			}

			StringBuilder message = new StringBuilder();
			message.AppendFormat(CultureInfo.InvariantCulture,
			                     "##teamcity[testFailed name='{0}'",
			                     Formatter.FormatValue(testName));

			if (exceptionInfo != null)
			{
				StringBuilder formattedException = new StringBuilder();
				Formatter.FormatException(exceptionInfo, formattedException);
				Formatter.FormatValue(formattedException);

				message.AppendFormat(CultureInfo.InvariantCulture,
				                     " message='{0}' details='{1}' type='{2}'",
				                     Formatter.FormatValue(exceptionInfo.Message),
				                     formattedException,
				                     Formatter.FormatValue(exceptionInfo.Type));
			}

			message.Append("]");

			_writer.WriteLine(message.ToString());
		}
Example #2
0
		internal static void FormatException(ExceptionInfo exceptionInfo, StringBuilder builder)
		{
			if (exceptionInfo == null)
			{
				return;
			}

			if (builder.Length > 0)
			{
				builder.AppendLine("--------------------------------");
			}

			builder.AppendFormat("{0}: {1}", FormatValue(exceptionInfo.GetType().ToString()), FormatValue(exceptionInfo.Message));
			builder.AppendLine();

			if (!String.IsNullOrEmpty(exceptionInfo.Source))
			{
				builder.AppendFormat(" Source: {0}", FormatValue(exceptionInfo.Source));
				builder.AppendLine();
			}

			if (!String.IsNullOrEmpty(exceptionInfo.StackTrace))
			{
				builder.AppendFormat(" Stack: {0}", FormatValue(exceptionInfo.StackTrace));
				builder.AppendLine();
			}

			if (exceptionInfo.InnerException != null)
			{
				FormatException(exceptionInfo.InnerException, builder);
			}
		}
		static ExceptionInfo GetExceptionInfo(ReportException reportException)
		{
			if (reportException == null)
			{
				return null;
			}

			ExceptionInfo exceptionInfo = new ExceptionInfo();
			exceptionInfo.Type = reportException.Type;
			exceptionInfo.Message = reportException.Message;
			exceptionInfo.Source = reportException.Source;
			exceptionInfo.StackTrace = reportException.StackTrace;

			if (reportException.Exception != null)
			{
				exceptionInfo.InnerException = GetExceptionInfo(reportException.Exception);
			}

			return exceptionInfo;
		}
		public static ExceptionInfo FromException(Exception exception)
		{
			if (exception == null)
			{
				return null;
			}

			ExceptionInfo result = new ExceptionInfo
			                       {
			                       	Type = exception.GetType().FullName,
			                       	Message = exception.Message,
			                       	Source = exception.Source,
			                       	StackTrace = exception.StackTrace
			                       };

			if (exception.InnerException != null)
			{
				result.InnerException = FromException(exception.InnerException);
			}

			return result;
		}
 public void TestFailed(string testName, Exception exception)
 {
     TestFailed(testName, ExceptionInfo.FromException(exception));
 }