Esempio n. 1
0
        private void OnTestCaseResultCreated(TestCaseResult result)
        {
            lock (_sync)
            {
                IEnumerable <TestContextMessageClientEvent> testContextMessageClientEvents = _unhandledMessages.Where(x => x.FullTestName == result.FullMethodName());
                foreach (var message in testContextMessageClientEvents.OrderBy(x => x.Order))
                {
                    AppendTestContextMetadata(result, message);
                }

                _unhandledMessages.RemoveAll(x => x.FullTestName == result.FullMethodName());
            }
        }
        public void Handle(TestCaseResult message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            var name = message.FullMethodName();
            var durationMilliseconds = message.TimeToComplete.Milliseconds;

            switch (message.ResultType)
            {
            case ResultType.Ignored:
                WrapTestWithStartAndEnd(CommandFactory.TestIgnored(message.MethodName, string.Empty), message.MethodName, 0);
                break;

            case ResultType.Passed:

                WrapTestWithStartAndEnd(() =>
                {
                }, name, durationMilliseconds);
                break;

            case ResultType.Failed:
                WrapTestWithStartAndEnd(() => _messageWriter.Write(
                                            CommandFactory.TestFailed(
                                                name,
                                                message.ExceptionInfo.FullMessage,
                                                message.ExceptionInfo.FullMessage)),
                                        name,
                                        durationMilliseconds);
                break;

            case ResultType.SystemGeneratedFailure:
                WrapTestWithStartAndEnd(() => _messageWriter.Write(
                                            CommandFactory.TestFailed(
                                                name,
                                                "StatLight generated test failure",
                                                message.OtherInfo)),
                                        name,
                                        durationMilliseconds);
                break;

            default:
                "Unknown TestCaseResult (to StatLight) - {0}".FormatWith(message.ResultType)
                .WrapConsoleMessageWithColor(Settings.Default.ConsoleColorError, true);
                break;
            }
        }
        public void Handle(TestCaseResult message)
        {
            if (message.MethodName != null)
            {
                var testMethod = GetTestMethod(message.FullMethodName());
                if (testMethod != null)
                {
                    var taskResult = ToTaskResult(message.ResultType);

                    if (message.ExceptionInfo != null)
                    {
                        testMethod.Node.NotifyFinishedWithException(message.ExceptionInfo, taskResult);
                    }
                    else
                    {
                        testMethod.Node.NotifyFinished(null, taskResult);
                    }
                }
            }
        }
Esempio n. 4
0
        private static XElement CreateTestCaseElement(TestCaseResult result)
        {
            var element = new XElement("test-case",
                                       new XAttribute("name", result.FullMethodName()),
                                       new XAttribute("executed", result.ResultType == ResultType.Ignored ? "False" : "True"),
                                       new XAttribute("time", result.TimeToComplete.ToString(@"hh\:mm\:ss\.ffff", CultureInfo.InvariantCulture)),
                                       new XAttribute("result", result.ResultType == ResultType.Ignored ? "Ignored" : (result.ResultType == ResultType.Failed || result.ResultType == ResultType.SystemGeneratedFailure) ? "Failure" : "Success"));

            if (result.ResultType != ResultType.Ignored)
            {
                element.Add(new XAttribute("success", result.ResultType == ResultType.Passed ? "True" : "False"));
            }

            if (result.ResultType == ResultType.Failed || result.ResultType == ResultType.SystemGeneratedFailure)
            {
                element.Add(new XElement("failure",
                                         new XElement("message", GetErrorMessage(result)),
                                         new XElement("stack-trace", new XCData(GetErrorStackTrace(result)))));
            }

            return(element);
        }
        public void Handle(TestCaseResult message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            var name = message.FullMethodName();
            var durationMilliseconds = message.TimeToComplete.Milliseconds;

            switch (message.ResultType)
            {
            case ResultType.Ignored:
                WrapTestWithStartAndEnd(CommandFactory.TestIgnored(message.MethodName, string.Empty), message.MethodName, 0);
                break;

            case ResultType.Passed:

                WrapTestWithStartAndEnd(() =>
                {
                }, name, durationMilliseconds);
                break;

            case ResultType.Failed:

                var sb = new StringBuilder();

                sb.Append("Test Namespace:  ");
                sb.AppendLine(message.NamespaceName);

                sb.Append("Test Class:      ");
                sb.AppendLine(message.ClassName);

                sb.Append("Test Method:     ");
                sb.AppendLine(message.MethodName);

                if (!string.IsNullOrEmpty(message.OtherInfo))
                {
                    sb.Append("Other Info:      ");
                    sb.AppendLine(message.OtherInfo);
                }

                foreach (var metaData in message.Metadata)
                {
                    sb.Append("{0,-17}".FormatWith(metaData.Classification + ": "));
                    sb.Append(metaData.Name + " - ");
                    sb.AppendLine(metaData.Value);
                }

                sb.AppendLine(message.ExceptionInfo.FullMessage);

                var msg = sb.ToString();

                WrapTestWithStartAndEnd(() => _messageWriter.Write(
                                            CommandFactory.TestFailed(
                                                name,
                                                message.ExceptionInfo.FullMessage,
                                                msg)),
                                        name,
                                        durationMilliseconds);
                break;

            case ResultType.SystemGeneratedFailure:
                WrapTestWithStartAndEnd(() => _messageWriter.Write(
                                            CommandFactory.TestFailed(
                                                name,
                                                "StatLight generated test failure",
                                                message.OtherInfo)),
                                        name,
                                        durationMilliseconds);
                break;

            default:
                "Unknown TestCaseResult (to StatLight) - {0}".FormatWith(message.ResultType)
                .WrapConsoleMessageWithColor(Settings.Default.ConsoleColorError, true);
                break;
            }
        }