Ejemplo n.º 1
0
 public Task <IServiceTestModelTO> ExecuteTestAsync(string resourcePath, IPrincipal userPrinciple, Guid workspaceGuid, Dev2JsonSerializer serializer, IDSFDataObject dataObjectClone)
 {
     return(ServiceTestExecutor.ExecuteTestAsync(resourcePath, userPrinciple, workspaceGuid, serializer, dataObjectClone));
 }
Ejemplo n.º 2
0
        static TestResults RunListOfTests(IDSFDataObject dataObject, IPrincipal userPrinciple, Guid workspaceGuid, Dev2JsonSerializer serializer, IResourceCatalog catalog, ITestCatalog testCatalog, ITestCoverageCatalog testCoverageCatalog)
        {
            var result = new TestResults();

            testCoverageCatalog.ReloadAllReports();

            var selectedResources = catalog.GetResources(workspaceGuid)
                                    .Where(resource => dataObject.TestsResourceIds.Contains(resource.ResourceID)).ToArray();

            var workflowTaskList = new List <Task <WorkflowTestResults> >();

            foreach (var testsResourceId in dataObject.TestsResourceIds)
            {
                var workflowTask = Task <WorkflowTestResults> .Factory.StartNew(() =>
                {
                    var workflowTestTaskList = new List <Task <IServiceTestModelTO> >();
                    var res                 = selectedResources.First(o => o.ResourceID == testsResourceId);
                    var resourcePath        = res.GetResourcePath(workspaceGuid).Replace("\\", "/");
                    var workflowTestResults = new WorkflowTestResults(res);

                    var allTests = testCatalog.Fetch(testsResourceId);
                    foreach (var test in allTests)
                    {
                        var dataObjectClone         = dataObject.Clone();
                        dataObjectClone.Environment = new ExecutionEnvironment();
                        dataObjectClone.TestName    = test.TestName;
                        dataObjectClone.ServiceName = res.ResourceName;
                        dataObjectClone.ResourceID  = res.ResourceID;
                        var lastTask = ServiceTestExecutor.ExecuteTestAsync(resourcePath, userPrinciple, workspaceGuid,
                                                                            serializer, dataObjectClone);
                        workflowTestTaskList.Add(lastTask);

                        var report = testCoverageCatalog.FetchReport(res.ResourceID, test.TestName);
                        var lastTestCoverageRun = report?.LastRunDate;
                        if (report is null || test.LastRunDate > lastTestCoverageRun)
                        {
                            testCoverageCatalog.GenerateSingleTestCoverage(res.ResourceID, lastTask.Result);
                        }
                    }

                    Task.WaitAll(workflowTestTaskList.Cast <Task>().ToArray());
                    foreach (var task in workflowTestTaskList)
                    {
                        workflowTestResults.Add(task.Result);
                    }

                    var testResults = workflowTestResults.Results;
                    if (testResults.Count > 0)
                    {
                        testCoverageCatalog.GenerateAllTestsCoverage(res.ResourceName, res.ResourceID, testResults);
                    }

                    return(workflowTestResults);
                });

                workflowTaskList.Add(workflowTask);
            }

            Task.WaitAll(workflowTaskList.Cast <Task>().ToArray());

            foreach (var task in workflowTaskList)
            {
                result.Add(task.Result);
            }

            result.EndTime = DateTime.Now;

            return(result);
        }