public IEnumerable <IEnumerable <ServiceMessage> > Convert(Event testEvent)
        {
            if (testEvent.MessageName == "start-run")
            {
                _hierarchy.Clear();
                _notStartedNUnit2Tests.Clear();
                _inAssembly.Clear();
                yield break;
            }

            var rootFlowId = testEvent.RootFlowId;
            var id         = testEvent.Id;
            var flowId     = rootFlowId;

            if (!string.IsNullOrEmpty(id))
            {
                var idParts = id.Split('-');
                if (idParts.Length == 2)
                {
                    flowId = idParts[0];
                }
            }

            if (string.IsNullOrEmpty(flowId))
            {
                flowId = ".";
            }

            var testFlowId = flowId;

            var eventId = new EventId(_teamCityInfo, flowId, testEvent.FullName);

            switch (testEvent.MessageName)
            {
            case "start-suite":
                _hierarchy.AddLink(id, testEvent.ParentId);

                if (!_inAssembly.ContainsKey(flowId))
                {
                    _inAssembly[flowId] = null;
                    _statistics.RegisterSuiteStart();
                    yield return(_serviceMessageFactory.SuiteStarted(eventId, testEvent));
                }

                break;

            case "test-suite":
                _hierarchy.AddLink(id, testEvent.ParentId);
                yield return(ProcessNotStartedTests(flowId, testEvent.TestEvent));

                yield return(_serviceMessageFactory.TestOutputAsMessage(eventId, testEvent.TestEvent));

                if (_inAssembly.ContainsKey(flowId))
                {
                    var suiteType = testEvent.TestEvent.GetAttribute("type");
                    if (suiteType == "Assembly" || suiteType == "SetUpFixture")
                    {
                        _inAssembly.Remove(flowId);
                        _statistics.RegisterSuiteFinish();
                        yield return(_serviceMessageFactory.SuiteFinished(eventId, testEvent));
                    }
                }

                break;

            case "start-test":
                _statistics.RegisterTestStart();
                _hierarchy.AddLink(id, testEvent.ParentId);
                break;

            case "test-case":
                var errorMessage = testEvent.TestEvent.SelectSingleNode("failure/message");
                if (errorMessage != null && errorMessage.InnerText.StartsWith("TestFixtureSetUp failed in", StringComparison.CurrentCultureIgnoreCase))
                {
                    _notStartedNUnit2Tests.Add(testEvent.TestEvent);
                    break;
                }

                var testEventId = new EventId(_teamCityInfo, testFlowId, testEvent.FullName);
                yield return(_serviceMessageFactory.TestStarted(testEventId));

                _statistics.RegisterTestFinish();
                yield return(_serviceMessageFactory.TestFinished(testEventId, testEvent.TestEvent, testEvent.TestEvent));

                break;

            case "test-run":
                yield return(ProcessNotStartedTests(flowId, testEvent.TestEvent));

                break;

            case "test-output":
                testFlowId = testEvent.TestId ?? rootFlowId;
                yield return(_serviceMessageFactory.TestOutput(new EventId(_teamCityInfo, testFlowId, testEvent.FullName), testEvent.TestEvent));

                break;
            }
        }
Пример #2
0
        public IEnumerable <IEnumerable <ServiceMessage> > Convert(Event testEvent)
        {
            if (testEvent.MessageName == "start-run")
            {
                _hierarchy.Clear();
                _notStartedNUnit3Tests.Clear();
                yield break;
            }

            var id       = testEvent.Id;
            var parentId = testEvent.ParentId;

            string rootId;
            var    flowId     = _hierarchy.TryFindRootId(parentId, out rootId) ? rootId : id;
            var    testFlowId = id != flowId ? id : flowId;
            var    rootFlowId = testEvent.RootFlowId;

            if (string.IsNullOrEmpty(rootFlowId))
            {
                rootFlowId = ".";
            }

            var eventId = new EventId(_teamCityInfo, flowId, testEvent.FullName);

            switch (testEvent.MessageName)
            {
            case "start-suite":
                _hierarchy.AddLink(id, parentId);

                // Root
                if (parentId == string.Empty)
                {
                    // Start a flow from a root flow https://youtrack.jetbrains.com/issue/TW-56310
                    yield return(_serviceMessageFactory.FlowStarted(flowId, rootFlowId));

                    _statistics.RegisterSuiteStart();
                    yield return(_serviceMessageFactory.SuiteStarted(eventId, testEvent));
                }

                break;

            case "test-suite":
                _hierarchy.AddLink(id, parentId);
                yield return(ProcessNotStartedTests(flowId, id, testEvent.TestEvent));

                yield return(_serviceMessageFactory.TestOutputAsMessage(eventId, testEvent.TestEvent));

                // Root
                if (parentId == string.Empty)
                {
                    _statistics.RegisterSuiteFinish();
                    yield return(_serviceMessageFactory.SuiteFinished(eventId, testEvent));

                    // Finish a child flow from a root flow https://youtrack.jetbrains.com/issue/TW-56310
                    yield return(_serviceMessageFactory.FlowFinished(flowId));
                }

                break;

            case "start-test":
                _hierarchy.AddLink(id, parentId);
                if (testFlowId != eventId.FlowId)
                {
                    yield return(_serviceMessageFactory.FlowStarted(testFlowId, eventId.FlowId));
                }

                _statistics.RegisterTestStart();
                yield return(_serviceMessageFactory.TestStarted(new EventId(_teamCityInfo, testFlowId, eventId.FullName)));

                break;

            case "test-case":
                if (_hierarchy.AddLink(id, parentId))
                {
                    // When a test without starting
                    _notStartedNUnit3Tests[testFlowId] = testEvent.TestEvent;
                    break;
                }

                _statistics.RegisterTestFinish();
                yield return(_serviceMessageFactory.TestFinished(new EventId(_teamCityInfo, testFlowId, testEvent.FullName), testEvent.TestEvent, testEvent.TestEvent));

                if (id != flowId && parentId != null)
                {
                    yield return(_serviceMessageFactory.FlowFinished(id));
                }

                break;

            case "test-run":
                yield return(ProcessNotStartedTests(flowId, id, testEvent.TestEvent));

                break;

            case "test-output":
                testFlowId = testEvent.TestId ?? rootFlowId;
                yield return(_serviceMessageFactory.TestOutput(new EventId(_teamCityInfo, testFlowId, testEvent.FullName), testEvent.TestEvent));

                break;
            }
        }