Beispiel #1
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;
            }
        }