public bool CanTranslate(LogMessage message)
 {
     if (message.MessageType == LogMessageType.TestResult)
     {
         if (message.Is(TestGranularity.TestScenario)
             && message.DecoratorMatches(LogDecorator.TestOutcome, v =>
                                                                       {
                                                                           switch ((TestOutcome)v)
                                                                           {
                                                                               case TestOutcome.Failed:
                                                                               case TestOutcome.Timeout:
                                                                               case TestOutcome.Inconclusive:
                                                                                   //TODO: reproduce case TestOutcome.Error:
                                                                                   return true;
                                                                               default:
                                                                                   return false;
                                                                           }
                                                                       })
             && message.DecoratorMatches(UnitTestLogDecorator.ScenarioResult, v => ((ScenarioResult)v).Exception != null)
             )
         {
             return true;
         }
     }
     return false;
 }
        protected override void ProcessRemainder(LogMessage message)
        {
            //DEBUG
            //var msg = TraceLogMessage(message);
            //Console.WriteLine(msg.Message);

            try
            {
                ClientEvent clientEvent;
                if (TryTranslateIntoClientEvent(message, out clientEvent))
                {
                    if (clientEvent != null)
                        Server.PostMessage(clientEvent);
                }
                else
                {
                    var traceClientEvent = TraceLogMessage(message);
                    Server.PostMessage(traceClientEvent);
                }
            }
            catch (Exception ex)
            {
                var messageObject = new UnhandledExceptionClientEvent
                                        {
                                            Exception = ex,
                                        };
                Server.PostMessage(messageObject);
            }
        }
        /// <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());
        }
 public override void Process(LogMessage logMessage) {
     if(isFirstMessage) {
         isFirstMessage = false;
         ProcessStartMessage();
     } else
         if(logMessage.HasDecorator(LogDecorator.TestOutcome))
             ProcessResultMessage(logMessage);
 }
 /// <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>
 /// 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);
 }
 public ClientEvent Translate(LogMessage message)
 {
     var testClass = (ITestClass)message.Decorators[UnitTestLogDecorator.TestClassMetadata];
     var clientEventX = new TestExecutionClassBeginClientEvent
                            {
                                ClassName = testClass.Type.ClassNameIncludingParentsIfNested(),
                                NamespaceName = testClass.Type.Namespace,
                            };
     return clientEventX;
 }
 public ClientEvent Translate(LogMessage message)
 {
     var testMethod = (ITestMethod)message.Decorators[UnitTestLogDecorator.TestMethodMetadata];
     var clientEventX = new TestExecutionMethodBeginClientEvent
                            {
                                Started = DateTime.Now,
                            };
     clientEventX.AssignTestExecutionMethodInfo(testMethod);
     return clientEventX;
 }
 /// <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);
         }
     }
 }
 public bool CanTranslate(LogMessage message)
 {
     if (message.MessageType == LogMessageType.TestInfrastructure)
     {
         if (message.Message.Equals("Initialization of UnitTestHarness", StringComparison.InvariantCultureIgnoreCase))
         {
             return true;
         }
     }
     return false;
 }
 public bool CanTranslate(LogMessage message)
 {
     if (message.MessageType == LogMessageType.TestResult)
     {
         if (message.Is(TestGranularity.TestScenario)
             && message.DecoratorMatches(LogDecorator.TestOutcome, v => (TestOutcome)v == TestOutcome.Passed)
             )
         {
             return true;
         }
     }
     return false;
 }
        public ClientEvent Translate(LogMessage message)
        {
            var scenarioResult = (ScenarioResult)message.Decorators[UnitTestLogDecorator.ScenarioResult];
            var testMethod = (ITestMethod)message.Decorators[UnitTestLogDecorator.TestMethodMetadata];

            var clientEventX = new TestExecutionMethodPassedClientEvent
                                   {
                                       Finished = scenarioResult.Finished,
                                       Started = scenarioResult.Started,
                                   };
            clientEventX.AssignTestExecutionMethodInfo(testMethod);
            return clientEventX;
        }
 public bool CanTranslate(LogMessage message)
 {
     if (message.MessageType == LogMessageType.TestExecution)
     {
         if (message.Is(TestGranularity.TestScenario)
             && message.DecoratorMatches(UnitTestLogDecorator.IgnoreMessage, v => (bool)v)
             )
         {
             return true;
         }
     }
     return false;
 }
 public static TraceClientEvent TraceLogMessage(LogMessage message)
 {
     const string newLine = "\n";
     string msg = "";
     msg += "MessageType={0}".FormatWith(message.MessageType);
     msg += newLine;
     msg += "Message={0}".FormatWith(message.Message);
     msg += newLine;
     msg += "Decorators:";
     msg += newLine;
     msg += GetDecorators(message.Decorators);
     msg += newLine;
     return new TraceClientEvent { Message = msg };
 }
        public ClientEvent Translate(LogMessage message)
        {
            var testName = (string)message.Decorators[LogDecorator.NameProperty];
            var clientEventX = new TestExecutionMethodIgnoredClientEvent
                                   {
                                       ClassName = null,
                                       NamespaceName = null,
                                       MethodName = testName,
                                       Message = testName,
                                       Started = DateTime.Now,
                                   };

            return clientEventX;
        }
 public bool CanTranslate(LogMessage message)
 {
     if (message.MessageType == LogMessageType.TestExecution)
     {
         if (message.Is(TestStage.Finishing)
             && message.Is(TestGranularity.Test)
             && message.DecoratorMatches(UnitTestLogDecorator.TestClassMetadata, v => v is ITestClass)
             )
         {
             return true;
         }
     }
     return false;
 }
 public bool CanTranslate(LogMessage message)
 {
     if (message.MessageType == LogMessageType.TestExecution)
     {
         if (message.Is(TestStage.Starting)
             && message.Is(TestGranularity.TestScenario)
             && message.DecoratorMatches(UnitTestLogDecorator.TestMethodMetadata, v => v is ITestMethod)
             )
         {
             return true;
         }
     }
     return false;
 }
        public ClientEvent Translate(LogMessage message)
        {
            var scenarioResult = (ScenarioResult)message.Decorators[UnitTestLogDecorator.ScenarioResult];
            var testMethod = (ITestMethod)message.Decorators[UnitTestLogDecorator.TestMethodMetadata];
            var clientEventX = new TestExecutionMethodFailedClientEvent
                                   {
                                       ExceptionInfo = new ExceptionInfo(new Exception("An expected exception was not thrown.")),
                                       Finished = scenarioResult.Finished,
                                       Started = scenarioResult.Started,
                                   };
            clientEventX.AssignMetadata(testMethod.Method);
            clientEventX.AssignTestExecutionMethodInfo(testMethod);

            return clientEventX;
        }
Beispiel #20
0
            public override void Process(LogMessage logMessage)
            {
                if (logMessage.HasDecorator(UnitTestLogDecorator.ScenarioResult))
                {
                    var result = (ScenarioResult)logMessage[UnitTestLogDecorator.ScenarioResult];

                    InvokeDomMethod("scenarioResult",
                                           result.Started.Ticks,
                                           result.Finished.Ticks,
                                           (result.TestClass != null) ? result.TestClass.Type.FullName : null,
                                           (result.TestMethod != null) ? result.TestMethod.Name : null,
                                           result.Result.ToString(),
                                           (result.Exception != null) ? result.Exception.ToString() : null);
                }
            }
        public ClientEvent Translate(LogMessage message)
        {
            var scenarioResult = (ScenarioResult)message.Decorators[UnitTestLogDecorator.ScenarioResult];
            var exception = scenarioResult.Exception;
            var testMethod = (ITestMethod)message.Decorators[UnitTestLogDecorator.TestMethodMetadata];
            var clientEventX = new TestExecutionMethodFailedClientEvent
                                   {
                                       ExceptionInfo = exception,
                                       Finished = scenarioResult.Finished,
                                       Started = scenarioResult.Started,
                                       Description = GetDescriptionInfo(testMethod.Method)
                                   };
            clientEventX.AssignTestExecutionMethodInfo(testMethod);

            return clientEventX;
        }
Beispiel #22
0
 /// <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;
     }
 }
 void ProcessResultMessage(LogMessage logMessage) {
     totalCount++;
     string testClassName = ((BaseTestClass)logMessage.Decorators[UnitTestLogDecorator.TestClassMetadata]).Type.ToString();
     string testMethodName = (string)logMessage.Decorators[LogDecorator.NameProperty];
     switch((TestOutcome)logMessage.Decorators[LogDecorator.TestOutcome]) {
         case TestOutcome.Passed:
             InvokeMethod("TestResult", testClassName, testMethodName, "");
             passedCount++;
             break;
         case TestOutcome.Failed:
             string exceptionString = FormatException(((ScenarioResult)logMessage.Decorators[UnitTestLogDecorator.ScenarioResult]).Exception);
             InvokeMethod("TestResult", testClassName, testMethodName, exceptionString);
             break;
         default:
             break;
     }
 }
        private void AppendToFile(LogMessage logMessage)
        {
            UTF8Encoding encoding = new UTF8Encoding();
            var carriageReturnBytes = encoding.GetBytes(new[] { '\r', '\n' });

            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!store.DirectoryExists("TestResults"))
                {
                    store.CreateDirectory("TestResults");
                }
                using (IsolatedStorageFileStream isoStream =
                    store.OpenFile(TESTRESULTFILENAME, FileMode.Append))
                {
                    var byteArray = encoding.GetBytes(logMessage.Message);
                    isoStream.Write(byteArray, 0, byteArray.Length);
                    isoStream.Write(carriageReturnBytes, 0, carriageReturnBytes.Length);
                }
            }
        }
 public bool CanTranslate(LogMessage message)
 {
     if (message.MessageType == LogMessageType.TestResult)
     {
         if (message.Is(TestGranularity.TestScenario)
             && message.DecoratorMatches(LogDecorator.TestOutcome, v =>
                                                                       {
                                                                           switch ((TestOutcome)v)
                                                                           {
                                                                               case TestOutcome.Failed:
                                                                                   return true;
                                                                               default:
                                                                                   return false;
                                                                           }
                                                                       })
             )
         {
             return true;
         }
     }
     return false;
 }
Beispiel #26
0
            public override void Process(LogMessage logMessage)
            {
                if (logMessage.HasDecorator(LogDecorator.TestStage))
                {
                    var stage = (TestStage)logMessage[LogDecorator.TestStage];
                    if (stage == TestStage.Starting)
                    {
                        if (logMessage.HasDecorator(UnitTestLogDecorator.TestMethodMetadata))
                        {
                            var methodInfo = (TestMethod)logMessage[UnitTestLogDecorator.TestMethodMetadata];
                            var wc = new WebClient();
                            wc.UploadStringAsync(new Uri(baseUrl, "/TestMethodStarting?method=" + methodInfo.Name), "");
                        }
                        else if (logMessage.HasDecorator(UnitTestLogDecorator.TestClassMetadata))
                        {
                            var classInfo = (TestClass)logMessage[UnitTestLogDecorator.TestClassMetadata];
                            var wc = new WebClient();
                            wc.UploadStringAsync(new Uri(baseUrl, "/TestClassStarting?class=" + classInfo.Type.FullName), "");
                        }
                    }
                }

                if (logMessage.HasDecorator(UnitTestLogDecorator.ScenarioResult))
                {
                    var result = (ScenarioResult)logMessage[UnitTestLogDecorator.ScenarioResult];
                    var wc = new WebClient();
                    StringBuilder uri = new StringBuilder();
                    uri.Append("/TestMethodCompleted?result=" + result.Result);
                    if (result.TestClass != null)
                    {
                        uri.Append("&class=").Append(result.TestClass.Type.FullName);
                    }
                    if (result.TestMethod != null)
                    {
                        uri.Append("&method=").Append(result.TestMethod.Name);
                    }
                    wc.UploadStringAsync(new Uri(baseUrl, uri.ToString()), "");
                }
            }
        protected override void Before_all_tests()
        {
            base.Before_all_tests();

            var mockTestMethod = new MockTestMethod();
            var mockTestClass = new MockTestClass();

            var scenarioResult = new ScenarioResult(
                mockTestMethod,
                mockTestClass,
                TestOutcome.Passed,
                null);

            _logMessage = new LogMessage(LogMessageType.TestResult);
            _logMessage.Decorators.Add(UnitTestLogDecorator.IsUnitTestMessage, true);
            _logMessage.Decorators.Add(LogDecorator.NameProperty, "some_test_method_name_here");
            _logMessage.Decorators.Add(LogDecorator.TestGranularity, TestGranularity.TestScenario);
            _logMessage.Decorators.Add(UnitTestLogDecorator.ScenarioResult, scenarioResult);
            _logMessage.Decorators.Add(UnitTestLogDecorator.TestMethodMetadata, mockTestMethod);
            _logMessage.Decorators.Add(UnitTestLogDecorator.TestClassMetadata, mockTestClass);
            _logMessage.Decorators.Add(LogDecorator.TestOutcome, TestOutcome.Passed);
        }
Beispiel #28
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);
        }
Beispiel #29
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;
 }
Beispiel #30
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);
 }
 /// <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;
 }
 /// <summary>
 /// Process [Bug(...)].
 /// </summary>
 /// <param name="l">A KnownBugLogMessage object.</param>
 private void ProcessBug(LogMessage l)
 {
     _writer.AddPendingWriteLine(l.Message);
 }
Beispiel #33
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);
 }
Beispiel #34
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);
 }
Beispiel #35
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);
 }
Beispiel #36
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;
 }
Beispiel #37
0
        /// <summary>
        /// Record a test outcome.
        /// </summary>
        /// <param name="message">The accompanying message.</param>
        /// <param name="outcome">The outcome value.</param>
        public void TestResult(string message, TestOutcome outcome)
        {
            LogMessage m = Create(LogMessageType.TestResult, message);

            DecorateTestOutcome(m, outcome);
        }
Beispiel #38
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);
 }
Beispiel #39
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);
 }