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); }
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); }
void ExecuteRequestAsync(IDSFDataObject dataObject, IDataListCompiler compiler, IEsbServiceInvoker invoker, bool isLocal, Guid oldID, out ErrorResultTO invokeErrors) { var clonedDataObject = dataObject.Clone(); StringBuilder dl1 = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._XML_Without_SystemTags), enTranslationDepth.Data, out invokeErrors); var shapeOfData = FindServiceShape(dataObject.WorkspaceID, dataObject.ResourceID); var executionContainer = invoker.GenerateInvokeContainer(clonedDataObject, clonedDataObject.ServiceName, isLocal, oldID); if (executionContainer != null) { if (!isLocal) { var remoteContainer = executionContainer as RemoteWorkflowExecutionContainer; if (remoteContainer != null) { if (!remoteContainer.ServerIsUp()) { invokeErrors.AddError("Asynchronous execution failed: Remote server unreachable"); } SetRemoteExecutionDataList(dataObject, executionContainer); shapeOfData = dataObject.RemoteInvokeResultShape; } } if (!invokeErrors.HasErrors()) { var task = Task.Factory.StartNew(() => { Dev2Logger.Log.Info("ASYNC EXECUTION USER CONTEXT IS [ " + Thread.CurrentPrincipal.Identity.Name + " ]"); ErrorResultTO error; clonedDataObject.DataListID = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML_Without_SystemTags), dl1, shapeOfData, out error); executionContainer.Execute(out error); }); // ReSharper disable ImplicitlyCapturedClosure task.ContinueWith(o => // ReSharper restore ImplicitlyCapturedClosure { DataListRegistar.DisposeScope(o.Id, clonedDataObject.DataListID); o.Dispose(); }); } } else { invokeErrors.AddError("Asynchronous execution failed: Resource not found"); } }
void ExecuteRequestAsync(IDSFDataObject dataObject, string inputDefs, IEsbServiceInvoker invoker, bool isLocal, Guid oldID, out ErrorResultTO invokeErrors, int update) { var clonedDataObject = dataObject.Clone(); invokeErrors = new ErrorResultTO(); var executionContainer = invoker.GenerateInvokeContainer(clonedDataObject, clonedDataObject.ServiceName, isLocal, oldID); if (executionContainer != null) { if (!isLocal) { var remoteContainer = executionContainer as RemoteWorkflowExecutionContainer; if (remoteContainer != null) { if (!remoteContainer.ServerIsUp()) { invokeErrors.AddError("Asynchronous execution failed: Remote server unreachable"); } SetRemoteExecutionDataList(dataObject, executionContainer, invokeErrors); } } if (!invokeErrors.HasErrors()) { var shapeDefinitionsToEnvironment = DataListUtil.InputsToEnvironment(dataObject.Environment, inputDefs, update); Task.Factory.StartNew(() => { Dev2Logger.Log.Info("ASYNC EXECUTION USER CONTEXT IS [ " + Thread.CurrentPrincipal.Identity.Name + " ]"); ErrorResultTO error; clonedDataObject.Environment = shapeDefinitionsToEnvironment; executionContainer.Execute(out error, update); return(clonedDataObject); }).ContinueWith(task => { if (task.Result != null) { task.Result.Environment = null; } }); } } else { invokeErrors.AddError("Asynchronous execution failed: Resource not found"); } }
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); }
// 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()); }
static TestResults RunListOfTests(IDSFDataObject dataObject, IPrincipal userPrinciple, Guid workspaceGuid, Dev2JsonSerializer serializer, IResourceCatalog catalog, ITestCatalog testCatalog, ITestCoverageCatalog testCoverageCatalog, IServiceTestExecutorWrapper serviceTestExecutorWrapper) { var result = new TestResults(); var selectedResources = catalog.GetResources(workspaceGuid) ?.Where(resource => dataObject.TestsResourceIds.Contains(resource.ResourceID)).ToArray(); if (selectedResources != null) { 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.FirstOrDefault(o => o.ResourceID == testsResourceId); if (res is null) { return(null); } else { var resourcePath = res.GetResourcePath(workspaceGuid).Replace("\\", "/"); var workflowTestResults = new WorkflowTestResults(res); var allTests = testCatalog.Fetch(testsResourceId); foreach (var(test, dataObjectClone) in from test in allTests let dataObjectClone = dataObject.Clone() select(test, dataObjectClone)) { dataObjectClone.Environment = new ExecutionEnvironment(); dataObjectClone.TestName = test.TestName; dataObjectClone.ServiceName = res.ResourceName; dataObjectClone.ResourceID = res.ResourceID; var lastTask = serviceTestExecutorWrapper.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); } }); if (workflowTask != null) { workflowTaskList.Add(workflowTask); } } Task.WaitAll(workflowTaskList.Cast <Task>().ToArray()); foreach (var task in workflowTaskList) { if (task.Result != null) { result.Add(task.Result); } } } result.EndTime = DateTime.Now; return(result); }