private void SubscribeResults()

in resharper/resharper-unity/src/Unity.Rider/Integration/Core/Feature/UnitTesting/RunViaUnityEditorStrategy.cs [372:438]


        private void SubscribeResults(IUnitTestRun run, Lifetime connectionLifetime, UnitTestLaunch launch)
        {
            mySolution.Locks.AssertMainThread();

            launch.TestResult.AdviseNotNull(connectionLifetime, result =>
            {
                var unitTestElement = GetElementById(run, result.ProjectName, result.TestId);
                if (unitTestElement == null)
                {
                    // add dynamic tests
                    var parent = GetElementById(run, result.ProjectName, result.ParentId);
                    if (parent is NUnitTestElement elementParent)
                    {
                        //TODO: add ShortName to TestResult and populate it on Unity side
                        // Test cases in NUnit3 have the following ids:
                        //   - {namespace}.{class}.{method}{parameters} if the test case is not given a custom name
                        //   - {namespace}.{class}.{custom_name} if the test case is given a custom name
                        // We want to extract either {method}{parameters} or {custom_name}. For that we remove the last 
                        // part of parent id, which has the form {namespace}.{class}.{method}
                        var shortName = result.TestId.SubstringAfter(result.ParentId.SubstringBeforeLast(".") + ".");
                        
                        run.CreateDynamicElement(() => new NUnitRowTestElement(elementParent, shortName));
                    }
                    else if (parent is NUnitTestFixtureElement fixtureParent)
                    {
                        run.CreateDynamicElement(() => new NUnitTestElement(fixtureParent,
                            result.TestId.SubstringAfter($"{result.ParentId}."), null));
                    }
                }

                if (unitTestElement == null)
                    return;

                switch (result.Status)
                {
                    case Status.Pending:
                        myUnitTestResultManager.MarkPending(unitTestElement, run.Launch.Session);
                        break;
                    case Status.Running:
                        myUnitTestResultManager.TestStarting(unitTestElement, run.Launch.Session);
                        break;
                    case Status.Success:
                    case Status.Failure:
                    case Status.Ignored:
                    case Status.Inconclusive:
                        var message = string.Empty;
                        var messageHeader = "Message: " + Environment.NewLine; // header is hardcoded in Rider package
                        if (result.Output.StartsWith(messageHeader))
                            message = result.Output.Substring(messageHeader.Length);
                        var taskResult = UnitTestStatus.Inconclusive;
                        if (result.Status == Status.Failure)
                            taskResult = UnitTestStatus.Failed;
                        else if (result.Status == Status.Ignored)
                            taskResult = UnitTestStatus.Ignored;
                        else if (result.Status == Status.Inconclusive)
                            taskResult = UnitTestStatus.Inconclusive;
                        else if (result.Status == Status.Success)
                            taskResult = UnitTestStatus.Success;

                        myUnitTestResultManager.TestOutput(unitTestElement, run.Launch.Session, result.Output, TestOutputType.STDOUT);
                        myUnitTestResultManager.TestFinishing(unitTestElement, run.Launch.Session, taskResult, message, TimeSpan.FromMilliseconds(result.Duration));
                        break;
                    default:
                        throw new ArgumentOutOfRangeException($"Unknown test result from the protocol: {result.Status}");
                }
            });
        }