private void SubscribeResults(IUnitTestRun firstRun, Lifetime connectionLifetime, TaskCompletionSource <bool> tcs, UnitTestLaunch launch)
        {
            mySolution.Locks.AssertMainThread();

            launch.TestResult.AdviseNotNull(connectionLifetime, result =>
            {
                var unitTestElement = GetElementById(result.ProjectName, result.TestId);
                if (unitTestElement == null)
                {
                    // add dynamic tests
                    var parent = GetElementById(result.ProjectName, result.ParentId) as NUnitTestElement;
                    if (parent == null)
                    {
                        return;
                    }

                    var project           = parent.Id.Project;
                    var targetFrameworkId = parent.Id.TargetFrameworkId;

                    var uid         = myIDFactory.Create(myUnitTestProvider, project, targetFrameworkId, result.TestId);
                    unitTestElement = new NUnitRowTestElement(mySolution.GetComponent <NUnitServiceProvider>(), uid, parent, parent.TypeName.GetPersistent());
                    firstRun.AddDynamicElement(unitTestElement);
                    myElements.Add(myIDFactory.Create(myUnitTestProvider, project, targetFrameworkId, result.TestId), unitTestElement);
                }

                switch (result.Status)
                {
                case Status.Pending:
                    myUnitTestResultManager.MarkPending(unitTestElement,
                                                        firstRun.Launch.Session);
                    break;

                case Status.Running:
                    myUnitTestResultManager.TestStarting(unitTestElement,
                                                         firstRun.Launch.Session);
                    break;

                case Status.Success:
                case Status.Failure:
                case Status.Ignored:
                case Status.Inconclusive:
                    string message        = result.Status.ToString();
                    TaskResult taskResult = TaskResult.Inconclusive;
                    if (result.Status == Status.Failure)
                    {
                        taskResult = TaskResult.Error;
                    }
                    else if (result.Status == Status.Ignored)
                    {
                        taskResult = TaskResult.Skipped;
                    }
                    else if (result.Status == Status.Success)
                    {
                        taskResult = TaskResult.Success;
                    }

                    myUnitTestResultManager.TestOutput(unitTestElement, firstRun.Launch.Session, result.Output, TaskOutputType.STDOUT);
                    myUnitTestResultManager.TestDuration(unitTestElement, firstRun.Launch.Session, TimeSpan.FromMilliseconds(result.Duration));
                    myUnitTestResultManager.TestFinishing(unitTestElement,
                                                          firstRun.Launch.Session, message, taskResult);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(
                        $"Unknown test result from the protocol: {result.Status}");
                }
            });

            launch.RunResult.Advise(connectionLifetime, result =>
            {
                tcs.SetResult(true);
            });
        }
예제 #2
0
        private void RunInternal(IUnitTestRun firstRun, Lifetime connectionLifetime, EditorPluginModel unityModel, TaskCompletionSource <bool> tcs)
        {
            mySolution.Locks.AssertMainThread();

            var unitTestElements = CollectElementsToRunInUnityEditor(firstRun);
            var allNames         = InitElementsMap(unitTestElements);
            var emptyList        = new List <string>();

            var launch = new UnitTestLaunch(allNames, emptyList, emptyList);

            launch.TestResult.Advise(connectionLifetime, result =>
            {
                var unitTestElement = GetElementById(result.TestId);
                if (unitTestElement == null) //https://youtrack.jetbrains.com/issue/RIDER-15849
                {
                    var name        = result.ParentId.Substring(result.ParentId.LastIndexOf(".", StringComparison.Ordinal) + 1);
                    var brackets    = result.TestId.Substring(result.ParentId.Length);
                    var newID       = result.ParentId + "." + name + brackets;
                    unitTestElement = GetElementById(newID);
                }
                if (unitTestElement == null)
                {
                    // add dynamic tests
                    var parent = GetElementById(result.ParentId) as NUnitTestElement;
                    if (parent == null)
                    {
                        return;
                    }

                    var project           = parent.Id.Project;
                    var targetFrameworkId = parent.Id.TargetFrameworkId;

                    var uid         = myIDFactory.Create(myUnitTestProvider, project, targetFrameworkId, result.TestId);
                    unitTestElement = new NUnitDynamicRowTestElement(mySolution.GetComponent <NUnitServiceProvider>(), uid, parent, parent.TypeName.GetPersistent());
                    firstRun.AddDynamicElement(unitTestElement);
                    myElements.Add(myIDFactory.Create(myUnitTestProvider, project, targetFrameworkId, result.TestId), unitTestElement);
                }

                switch (result.Status)
                {
                case Status.Pending:
                    myUnitTestResultManager.MarkPending(unitTestElement,
                                                        firstRun.Launch.Session);
                    break;

                case Status.Running:
                    myUnitTestResultManager.TestStarting(unitTestElement,
                                                         firstRun.Launch.Session);
                    break;

                case Status.Passed:
                case Status.Failed:
                    var taskResult = result.Status == Status.Failed ? TaskResult.Error : TaskResult.Success;
                    var message    = result.Status == Status.Failed ? "Failed" : "Passed";

                    myUnitTestResultManager.TestOutput(unitTestElement, firstRun.Launch.Session, result.Output, TaskOutputType.STDOUT);
                    myUnitTestResultManager.TestDuration(unitTestElement, firstRun.Launch.Session, TimeSpan.FromMilliseconds(result.Duration));
                    myUnitTestResultManager.TestFinishing(unitTestElement,
                                                          firstRun.Launch.Session, message, taskResult);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(
                        $"Unknown test result from the protocol: {result.Status}");
                }
            });

            launch.RunResult.Advise(connectionLifetime, result =>
            {
                tcs.SetResult(true);
            });

            unityModel.UnitTestLaunch.Value = launch;
        }