/// <summary>
        /// Display a LogMessage in the debug output window.
        /// </summary>
        /// <param name="logMessage">Message object.</param>
        public override void Process(LogMessage logMessage)
        {
            if (logMessage == null)
            {
                throw new ArgumentNullException("logMessage");
            }

            if ((logMessage.MessageType != LogMessageType.Debug) && !ShowEverything)
            {
                if (!ShowAllFailures)
                {
                    return;
                }
                
                if (logMessage.HasDecorator(LogDecorator.TestOutcome))
                {
                    TestOutcome outcome = (TestOutcome)logMessage[LogDecorator.TestOutcome];
                    if (outcome == TestOutcome.Passed)
                    {
                        return;
                    }
                }
            }

            // Skip Finishing messages, they're always duplicates
            if (logMessage.HasDecorator(LogDecorator.TestStage))
            {
                if ((TestStage)logMessage[LogDecorator.TestStage] == TestStage.Finishing)
                {
                    return;
                }
            }

            Debug.WriteLine(logMessage.ToString());
        }
 /// <summary>
 /// Process an Exception that was not the expected Exception type.
 /// </summary>
 /// <param name="l">The log message.</param>
 private void ProcessIncorrectException(LogMessage l)
 {
     _writer.AddPendingErrorMessage(l.ToString());
 }
Beispiel #3
0
        /// <summary>
        /// Process an event with granular properties.
        /// </summary>
        /// <param name="l">The log message object.</param>
        private void ProcessGranularEvent(LogMessage l)
        {
            TestGranularity granularity = (TestGranularity)l[LogDecorator.TestGranularity];
            HtmlDiv div = new HtmlDiv();
            div.InnerHtml = l.Message;
            div.Padding.All = 2;

            switch (granularity)
            {
                case TestGranularity.Harness:
                    div.BackgroundColor = Color.DarkGray;
                    div.ForegroundColor = Color.VeryLightGray;
                    break;

                case TestGranularity.TestScenario:
                case TestGranularity.Test:
                    break;

                case TestGranularity.TestGroup:
                    div.Font.Bold = true;
                    break;

                default:
                    div = null;
                    AppendFixedText(l.ToString());
                    break;
            }
            if (div != null)
            {
                _myLog.Controls.Add(div);
            }
        }
Beispiel #4
0
		private void ProcessMessage (LogMessage logMessage) {
			TestMethod m;
			TestOutcome outcome;
			TestGranularity granularity;
			TestStage stage;
			ScenarioResult result;

			if (filename == null)
				return;

			Debug.WriteLine (logMessage);

			try {
				switch (logMessage.MessageType) {
				case LogMessageType.Error:
					// Ignore this
					break;
				case LogMessageType.KnownIssue:
					known_issue = true;
					break;
				case LogMessageType.TestResult:
					result = (ScenarioResult) logMessage.Decorators [UnitTestLogDecorator.ScenarioResult];
					outcome = result.Result;

					if (known_issue) {
						writer.WriteAttributeString ("Result", "KnownIssue");
						totals [KnownIssueIndex]++;
					} else {
						writer.WriteAttributeString ("Result", outcome.ToString ());
						totals [(int) outcome]++;
					}
					known_issue = false;
					writer.WriteAttributeString ("StartTime", result.Started.ToUniversalTime ().ToString ("yyyy/MM/dd HH:mm:ss.fffffff"));
					writer.WriteAttributeString ("EndTime", result.Finished.ToUniversalTime ().ToString ("yyyy/MM/dd HH:mm:ss.fffffff"));
					if (result.Exception != null) {
						writer.WriteAttributeString ("Message", result.Exception.Message);
						writer.WriteStartElement ("Exception");
						writer.WriteAttributeString ("Type", result.Exception.GetType ().FullName);
						writer.WriteAttributeString ("Message", result.Exception.Message);
						writer.WriteElementString ("StackTrace", result.Exception.StackTrace);
						writer.WriteEndElement ();
					}
					break;
				case LogMessageType.TestExecution:
					known_issue = false;
					granularity = (TestGranularity) logMessage.Decorators [LogDecorator.TestGranularity];

					switch (granularity) {
					case TestGranularity.TestGroup:
						stage = (TestStage) logMessage.Decorators [LogDecorator.TestStage];
						switch (stage) {
						case TestStage.Starting:
							writer.WriteStartElement ("MoonLog");
							break;
						case TestStage.Finishing:
						case TestStage.Canceling:

							writer.WriteStartElement ("Totals");
							for (int i = 0; i < totals.Length; i++) {
								if (i == KnownIssueIndex) {
									writer.WriteAttributeString ("KnownIssue", totals [i].ToString ());
								} else {
									writer.WriteAttributeString (((TestOutcome) i).ToString (), totals [i].ToString ());
								}									
							}
							writer.WriteEndElement ();

							writer.WriteEndElement ();
							break;
						case TestStage.Running:
							break;
						}
						break;
					case TestGranularity.TestScenario:
						if (logMessage.Decorators.HasDecorator (UnitTestLogDecorator.IgnoreMessage) && (bool) logMessage.Decorators [UnitTestLogDecorator.IgnoreMessage]) {
							m = (TestMethod) logMessage.Decorators [UnitTestLogDecorator.TestMethodMetadata];
							writer.WriteStartElement ("Test");
							writer.WriteAttributeString ("Class", m.Method.DeclaringType.FullName);
							writer.WriteAttributeString ("Name", m.Method.Name);
							writer.WriteAttributeString ("FullName", m.Method.DeclaringType.FullName + "." + m.Method.Name);
							writer.WriteAttributeString ("Result", "NotExecuted");
							writer.WriteAttributeString ("Ignored", "True");
							writer.WriteEndElement ();
							totals [(int) TestOutcome.NotExecuted]++;
						} else {
							stage = (TestStage) logMessage.Decorators [LogDecorator.TestStage];
							switch (stage) {
							case TestStage.Starting:
								m = (TestMethod) logMessage.Decorators [UnitTestLogDecorator.TestMethodMetadata];
								writer.WriteStartElement ("Test");
								writer.WriteAttributeString ("Class", m.Method.DeclaringType.FullName);
								writer.WriteAttributeString ("Name", m.Method.Name);
								writer.WriteAttributeString ("FullName", m.Method.DeclaringType.FullName + "." + m.Method.Name);
								break;
							case TestStage.Finishing:
							case TestStage.Canceling:
								writer.WriteEndElement ();
								break;
							}
						}
						break;
					case TestGranularity.Test:
					case TestGranularity.Harness:
						break;
					default:
						writer.WriteComment (string.Format ("Unknown test execution granularity: {0}", granularity));
						break;
					}
					break;
				case LogMessageType.TestInfrastructure:
					break;
				default:
					Console.WriteLine (string.Format ("Unknown log type '{1}': {0}", logMessage.ToString (), logMessage.MessageType));
					break;
				}
			} catch (Exception ex) {
				writer.WriteComment (string.Format ("Exception while converting message to xml ({0})", ex.ToString ()));
			}
		}
Beispiel #5
0
 /// <summary>
 /// How to process any remaining messages.
 /// </summary>
 /// <param name="message">The log message.</param>
 protected override void ProcessRemainder(LogMessage message)
 {
     AppendFixedText(message.ToString());
 }