Exemplo n.º 1
0
    /// <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>
 /// Determines whether a log message meets a specific condition or set 
 /// of conditions.
 /// </summary>
 /// <param name="message">The log message object.</param>
 /// <returns>Returns true if the condition is met.</returns>
 public static bool HasUnitTestOutcome(LogMessage message)
 {
   if (!IsUnitTestMessage(message))
   {
     return false;
   }
   return message.HasDecorator(LogDecorator.TestOutcome);
 }
 /// <summary>
 /// Process a UTF result message.
 /// </summary>
 /// <param name="logMessage">The log message object.</param>
 private void ProcessResult(LogMessage logMessage)
 {
   if (logMessage.HasDecorator(UnitTestLogDecorator.TestMethodMetadata))
   {
     ScenarioResult sr = (ScenarioResult)logMessage[UnitTestLogDecorator.ScenarioResult];
     if (sr.Result != TestOutcome.Passed)
     {
       _failures.Add(sr);
     }
   }
 }
 /// <summary>
 /// Determines whether a log message meets a specific condition or set 
 /// of conditions.
 /// </summary>
 /// <param name="message">The log message object.</param>
 /// <returns>Returns true if the condition is met.</returns>
 public static bool IsUnitTestEndMessage(LogMessage message)
 {
   if (!IsUnitTestMessage(message))
   {
     return false;
   }
   if (message.HasDecorator(LogDecorator.TestStage))
   {
     TestStage ts = (TestStage)message[LogDecorator.TestStage];
     return ts == TestStage.Finishing;
   }
   else
   {
     return false;
   }
 }
Exemplo n.º 5
0
    /// <summary>
    /// Perform any needed operations to log the message.
    /// </summary>
    /// <param name="logMessage">Instance of LogMessage type.</param>
    public virtual void Process(LogMessage logMessage)
    {
      // 1st: The more advanced conditionals.
      foreach (KeyValuePair<Func<LogMessage, bool>, Action<LogMessage>> pair in _conditionalHandlers)
      {
        if (pair.Value != null && pair.Key(logMessage))
        {
          pair.Value(logMessage);
          return;
        }
      }

      // 2nd: The LogMessageType handlers.
      LogMessageType type = logMessage.MessageType;
      Action<LogMessage> action = null;
      if (_definedHandlers.TryGetValue(type, out action) && action != null)
      {
        action(logMessage);
        return;
      }

      // 3rd: Do nothing with the message, unless overloaded
      ProcessRemainder(logMessage);
    }
 /// <summary>
 /// Process an Exception that is logged or stored.
 /// </summary>
 /// <param name="l">The log message object.</param>
 private void ProcessException(LogMessage l)
 {
   Exception e = (Exception)l[UnitTestLogDecorator.ActualException];
   _writer.AddPendingException(e);
 }
    /// <summary>
    /// Process a UTF result message.
    /// </summary>
    /// <param name="logMessage">The log message object.</param>
    private void ProcessResult(LogMessage logMessage)
    {
      if (logMessage.HasDecorator(UnitTestLogDecorator.TestMethodMetadata))
      {
        TestOutcome result = (TestOutcome)logMessage[LogDecorator.TestOutcome];
        ITestMethod method = (ITestMethod)logMessage[UnitTestLogDecorator.TestMethodMetadata];
        ITestClass test = (ITestClass)logMessage[UnitTestLogDecorator.TestClassMetadata];
        ScenarioResult sr = (ScenarioResult)logMessage[UnitTestLogDecorator.ScenarioResult];

        string storage = CurrentAssemblyName;
        string codeBase = CurrentAssemblyName;
        string adapterTypeName = TestAdapterTypeName;
        string className = test.Name;
        string testListName = TestListName;
        string computerName = ComputerName;
        DateTime startTime = sr.Started;
        DateTime endTime = sr.Finished;
        _writer.AddTestMethodResult(method, storage, codeBase, adapterTypeName, className, testListName, computerName, startTime, endTime, result);
        _writer.IncrementResults(result);
      }
    }
    /// <summary>
    /// Assembly start code.
    /// </summary>
    /// <param name="l">The log message.</param>
    private void TestAssemblyStart(LogMessage l)
    {
      IAssembly assembly = (IAssembly)l[UnitTestLogDecorator.TestAssemblyMetadata];
      _writer.Started = DateTime.Now;
      CurrentAssemblyName = assembly.Name;

      // For now, we assume the log works best with a single test 
      // assembly and with undefined behavior when there are more.
      SetTestRunConfiguration(assembly);
    }
 /// <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());
 }
 /// <summary>
 /// Determines whether a log message has an attached TestRunFilter.
 /// </summary>
 /// <param name="message">The log message object.</param>
 /// <returns>Returns a value indicating whether the condition is met.</returns>
 public static bool IsTestRunFilterMessage(LogMessage message)
 {
   return message.HasDecorator(UnitTestLogDecorator.TestRunFilter);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Method that processes any messages not handled any other way.
 /// </summary>
 /// <param name="message">The log message.</param>
 protected virtual void ProcessRemainder(LogMessage message)
 {
 }
Exemplo n.º 12
0
 /// <summary>
 /// Decorate the log message object with a name.
 /// </summary>
 /// <param name="message">The log message object.</param>
 /// <param name="name">Name property value.</param>
 protected static void DecorateNameProperty(LogMessage message, string name)
 {
   Decorate(message, LogDecorator.NameProperty, name);
 }
Exemplo n.º 13
0
 /// <summary>
 /// Decorate a log message with a value.
 /// </summary>
 /// <param name="message">The log message to decorate.</param>
 /// <param name="key">The key for this decoration.</param>
 /// <param name="value">The value of this decoration.</param>
 protected static void Decorate(LogMessage message, object key, object value)
 {
   message.Decorators[key] = value;
 }
 /// <summary>
 /// Logs a new message.
 /// </summary>
 /// <param name="message">Message object.</param>
 protected void LogMessage(LogMessage message)
 {
   LogWriter.Enqueue(message);
 }
 /// <summary>
 /// Returns a value indicating whether the message is marked as a unit
 /// test system message.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <returns>Returns true if the message is a unit test system-marked 
 /// message.</returns>
 private static bool IsUnitTestMessage(LogMessage message)
 {
   return message.HasDecorator(UnitTestLogDecorator.IsUnitTestMessage);
 }
 /// <summary>
 /// Determines whether a log message meets a specific condition or set 
 /// of conditions.
 /// </summary>
 /// <param name="message">The log message object.</param>
 /// <returns>Returns true if the condition is met.</returns>
 public static bool IsKnownBug(LogMessage message)
 {
   return (message.MessageType == LogMessageType.KnownIssue);
 }
 /// <summary>
 /// Determines whether a log message meets a specific condition or set 
 /// of conditions.
 /// </summary>
 /// <param name="message">The log message object.</param>
 /// <returns>Returns true if the condition is met.</returns>
 public static bool IsIncorrectExceptionLogMessage(LogMessage message)
 {
   if (!IsUnitTestMessage(message))
   {
     return false;
   }
   return message.HasDecorator(UnitTestLogDecorator.IncorrectExceptionMessage);
 }
 /// <summary>
 /// Determines whether a log message meets a specific condition or set 
 /// of conditions.
 /// </summary>
 /// <param name="message">The log message object.</param>
 /// <returns>Returns true if the condition is met.</returns>
 public static bool IsExceptionLogMessage(LogMessage message)
 {
   if (!IsUnitTestMessage(message))
   {
     return false;
   }
   return message.HasDecorator(UnitTestLogDecorator.ActualException);
 }
 /// <summary>
 /// Process [Bug(...)].
 /// </summary>
 /// <param name="l">A KnownBugLogMessage object.</param>
 private void ProcessBug(LogMessage l)
 {
   _writer.AddPendingWriteLine(l.Message);
 }
Exemplo n.º 20
0
 /// <summary>
 /// Decorate the log message object with a test outcome object.
 /// </summary>
 /// <param name="message">The log message object.</param>
 /// <param name="outcome">Test outcome object.</param>
 protected static void DecorateTestOutcome(LogMessage message, TestOutcome outcome)
 {
   Decorate(message, LogDecorator.TestOutcome, outcome);
 }
 /// <summary>
 /// The run filter has been selected.
 /// </summary>
 /// <param name="logMessage">The log message object.</param>
 private void TestRunFilterSelected(LogMessage logMessage)
 {
   TestRunFilter filter = (TestRunFilter)logMessage[UnitTestLogDecorator.TestRunFilter];
   TestListName = filter.TestRunName;
 }
Exemplo n.º 22
0
 /// <summary>
 /// Sets the type of the log message.
 /// </summary>
 /// <param name="message">The log message object.</param>
 /// <param name="type">The new value to set the message type to.</param>
 protected static void SetType(LogMessage message, LogMessageType type)
 {
   message.MessageType = type;
 }
Exemplo n.º 23
0
 /// <summary>
 /// Decorate the log message object with an Exception object.
 /// </summary>
 /// <param name="message">The log message object.</param>
 /// <param name="exception">The Exception.</param>
 protected static void DecorateException(LogMessage message, Exception exception)
 {
   Decorate(message, LogDecorator.ExceptionObject, exception);
 }
 /// <summary>
 /// Determines whether a log message meets a specific condition or set 
 /// of conditions.
 /// </summary>
 /// <param name="message">The log message object.</param>
 /// <returns>Returns true if the condition is met.</returns>
 public static bool IsIgnoreMessage(LogMessage message)
 {
   return message.HasDecorator(UnitTestLogDecorator.IgnoreMessage);
 }
Exemplo n.º 25
0
 /// <summary>
 /// Decorate the log message object with a test stage value.
 /// </summary>
 /// <param name="message">The log message object.</param>
 /// <param name="stage">Test stage value.</param>
 protected static void DecorateTestStage(LogMessage message, TestStage stage)
 {
   Decorate(message, LogDecorator.TestStage, stage);
 }
Exemplo n.º 26
0
 /// <summary>
 /// Enqueue a log message object for processing by the log providers.
 /// </summary>
 /// <param name="message">The log message object.</param>
 public void QueueLogMessage(LogMessage message)
 {
   _queuedLogMessages.Enqueue(message);
 }
Exemplo n.º 27
0
 /// <summary>
 /// Decorate the log message object with a test granularity object.
 /// </summary>
 /// <param name="message">The log message object.</param>
 /// <param name="granularity">Test granularity object.</param>
 protected static void DecorateTestGranularity(LogMessage message, TestGranularity granularity)
 {
   Decorate(message, LogDecorator.TestGranularity, granularity);
 }
Exemplo n.º 28
0
 /// <summary>
 /// Immediately sets the overall status using a log message and
 /// processes the message queue.
 /// </summary>
 /// <param name="message">The message to set.</param>
 private void SetOverallStatus(string message)
 {
   LogMessage lm = new LogMessage(LogMessageType.TestInfrastructure);
   lm.Message = message;
   lm.Decorators["UpdateOverallStatus"] = true;
   LogWriter.Enqueue(lm);
   ProcessLogMessages();
 }
Exemplo n.º 29
0
 /// <summary>
 /// Posts a log message to the test harness queue for processing.
 /// </summary>
 /// <param name="message">The log message object.</param>
 public void Enqueue(LogMessage message)
 {
   _testHarness.QueueLogMessage(message);
 }
 /// <summary>
 /// Marks a message as a unit test system-specific message.
 /// </summary>
 /// <param name="message">The log message object.</param>
 private static void MarkUnitTestMessage(LogMessage message)
 {
   message[UnitTestLogDecorator.IsUnitTestMessage] = true;
 }