示例#1
0
        static List <IServiceTestModelTO> RunListOfTests(IDSFDataObject dataObject, IPrincipal userPrinciple, Guid workspaceGuid, Dev2JsonSerializer serializer, IResourceCatalog catalog, ITestCatalog testCatalog)
        {
            var testResults = new List <IServiceTestModelTO>();
            var taskList    = new List <Task>();

            foreach (var testsResourceId in dataObject.TestsResourceIds)
            {
                var allTests = testCatalog.Fetch(testsResourceId);
                foreach (var test in allTests)
                {
                    var dataObjectClone = dataObject.Clone();
                    dataObjectClone.Environment = new ExecutionEnvironment();
                    dataObjectClone.TestName    = test.TestName;
                    var res = catalog.GetResource(GlobalConstants.ServerWorkspaceID, testsResourceId);
                    dataObjectClone.ServiceName = res.ResourceName;
                    dataObjectClone.ResourceID  = res.ResourceID;
                    var resourcePath = res.GetResourcePath(GlobalConstants.ServerWorkspaceID).Replace("\\", "/");
                    var lastTask     = ServiceTestExecutor.GetTaskForTestExecution(resourcePath, userPrinciple, workspaceGuid,
                                                                                   serializer, testResults, dataObjectClone);
                    taskList.Add(lastTask);
                }
            }
            Task.WaitAll(taskList.ToArray());
            return(testResults);
        }
示例#2
0
        public static DataListFormat RunMultipleTestBatches(this IDSFDataObject dataObject, IPrincipal userPrinciple, Guid workspaceGuid,
                                                            Dev2JsonSerializer serializer, DataListFormat formatter,
                                                            IResourceCatalog catalog, ITestCatalog testCatalog,
                                                            ref string executePayload)
        {
            foreach (var testsResourceId in dataObject.TestsResourceIds)
            {
                var allTests    = testCatalog.Fetch(testsResourceId);
                var taskList    = new List <Task>();
                var testResults = new List <IServiceTestModelTO>();
                foreach (var test in allTests)
                {
                    dataObject.ResourceID = testsResourceId;
                    var dataObjectClone = dataObject.Clone();
                    dataObjectClone.Environment = new ExecutionEnvironment();
                    dataObjectClone.TestName    = test.TestName;
                    var res          = catalog.GetResource(GlobalConstants.ServerWorkspaceID, testsResourceId);
                    var resourcePath = res.GetResourcePath(GlobalConstants.ServerWorkspaceID).Replace("\\", "/");

                    var lastTask = ServiceTestExecutor.GetTaskForTestExecution(resourcePath, userPrinciple, workspaceGuid,
                                                                               serializer, testResults, dataObjectClone);
                    taskList.Add(lastTask);
                }
                Task.WaitAll(taskList.ToArray());

                formatter = DataListFormat.CreateFormat("JSON", EmitionTypes.JSON, "application/json");
                var objArray = (from testRunResult in testResults
                                where testRunResult != null
                                select testRunResult.BuildTestResultForWebRequest()
                                ).ToList();

                executePayload = executePayload + Environment.NewLine + serializer.Serialize(objArray);
            }
            return(formatter);
        }
示例#3
0
        static List <IServiceTestModelTO> RunAllTestsForWorkflow(IDSFDataObject dataObject, string serviceName, IPrincipal userPrinciple, Guid workspaceGuid, Dev2JsonSerializer serializer, ITestCatalog testCatalog)
        {
            var allTests    = testCatalog.Fetch(dataObject.ResourceID) ?? new List <IServiceTestModelTO>();
            var taskList    = new List <Task>();
            var testResults = new List <IServiceTestModelTO>();

            foreach (var test in allTests.Where(to => to.Enabled))
            {
                dataObject.ResourceID = test.ResourceId;
                var dataObjectClone = dataObject.Clone();
                dataObjectClone.Environment = new ExecutionEnvironment();
                dataObjectClone.TestName    = test.TestName;
                dataObjectClone.ServiceName = serviceName;
                var lastTask = ServiceTestExecutor.GetTaskForTestExecution(serviceName, userPrinciple, workspaceGuid,
                                                                           serializer, testResults, dataObjectClone);
                taskList.Add(lastTask);
            }
            Task.WaitAll(taskList.ToArray());
            return(testResults);
        }
示例#4
0
        // ReSharper disable once RedundantAssignment
        public static IEnumerable <JObject> RunSingleTestBatch(this IDSFDataObject dataObject, string serviceName, IPrincipal userPrinciple, Guid workspaceGuid, Dev2JsonSerializer serializer, ITestCatalog catalog, ref DataListFormat formatter)
        {
            var allTests    = catalog.Fetch(dataObject.ResourceID) ?? new List <IServiceTestModelTO>();
            var taskList    = new List <Task>();
            var testResults = new List <IServiceTestModelTO>();

            foreach (var test in allTests.Where(to => to.Enabled))
            {
                var dataObjectClone = dataObject.Clone();
                dataObjectClone.Environment = new ExecutionEnvironment();
                dataObjectClone.TestName    = test.TestName;
                var lastTask = ServiceTestExecutor.GetTaskForTestExecution(serviceName, userPrinciple, workspaceGuid, serializer,
                                                                           testResults, dataObjectClone);
                taskList.Add(lastTask);
            }
            Task.WaitAll(taskList.ToArray());

            formatter = DataListFormat.CreateFormat("JSON", EmitionTypes.JSON, "application/json");
            return((from testRunResult in testResults
                    where testRunResult != null
                    select testRunResult.BuildTestResultForWebRequest()
                    ).ToList());
        }
示例#5
0
 public Task <IServiceTestModelTO> ExecuteTestAsync(string resourcePath, IPrincipal userPrinciple, Guid workspaceGuid, Dev2JsonSerializer serializer, IDSFDataObject dataObjectClone)
 {
     return(ServiceTestExecutor.ExecuteTestAsync(resourcePath, userPrinciple, workspaceGuid, serializer, dataObjectClone));
 }
        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);
        }