public AutomationRunningStatusDTO GetPassRateHistory(string projectId) { AutomationRunningStatusDTO progress = new AutomationRunningStatusDTO(); List<AutomationTask> tasks = Project.GetLatestNAutomationTasksForProject(int.Parse(projectId), 12); if (tasks.Count == 0) { progress.TestCasesExecutionStatusList = "No Executions."; progress.TestCasesExecutionStatusCountList = "0"; progress.Information = string.Format("There're no tasks trigged for this project, so there's no trend chart available."); } else { tasks.Reverse(); foreach (AutomationTask task in tasks) { AutomationRunningStatusDTO dto = AutomationTask.GetTaskProgress(task); //add build id to status list progress.TestCasesExecutionStatusList += "|Task " + task.TaskId.ToString() + ":" + Build.GetBuildById(task.BuildId).Name; //add passreate to count list int passRate = 0; List<string> resultTypes = dto.TestCasesExecutionStatusList.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(); List<string> resultCounts = dto.TestCasesExecutionStatusCountList.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(); int passedCount = 0; int totalCount = 0; for (int i = 0; i < resultTypes.Count; i++) { if (resultTypes[i] == ResultType.Pass.ToString()) { passedCount = int.Parse(resultCounts[i]); } totalCount += int.Parse(resultCounts[i]); } if (totalCount == 0) { passRate = 0; } else { passRate = passedCount * 100 / totalCount; } progress.TestCasesExecutionStatusCountList += " " + passRate.ToString(); } progress.TestCasesExecutionStatusList = progress.TestCasesExecutionStatusList.TrimStart('|'); progress.TestCasesExecutionStatusCountList = progress.TestCasesExecutionStatusCountList.TrimStart(' '); progress.Information = string.Format("TestCasesExecutionStatusList contains the task id list, and TestCasesExecutionStatusCountList contains the passrate list"); } return progress; }
public static AutomationRunningStatusDTO GetTaskProgress(AutomationTask task) { AutomationRunningStatusDTO progress = new AutomationRunningStatusDTO(); var testCasesExecutionStatusList = ""; var testCasesExecutionStatusCountList = ""; if (null == task) { progress.ExecutionPercentage = -1; progress.Status = (int)TaskStatus.Cancelled; progress.TaskId = -1; progress.Information = "There's no tasks executed yet for this project."; var resultType = typeof(ResultType); foreach (string result in Enum.GetNames(resultType)) { ResultType r = (ResultType)Enum.Parse(resultType, result); int count = 0; if (r == ResultType.NotRun) { count = 1; } else { count = 0; } testCasesExecutionStatusList += " " + r.ToString(); testCasesExecutionStatusCountList += " " + count.ToString(); } } else { progress.ExecutionPercentage = GetTaskExecutionPercentageByTaskId(task); progress.Status = task.Status; progress.TaskId = task.TaskId; progress.Information = task.Information == null ? "Not Started Yet!" : task.Information; var resultType = typeof(ResultType); foreach (string result in Enum.GetNames(resultType)) { ResultType r = (ResultType)Enum.Parse(resultType, result); int count = AutomationTask.GetResultTypeCountForTask(task.TaskId, r); testCasesExecutionStatusList += " " + r.ToString(); testCasesExecutionStatusCountList += " " + count.ToString(); } } progress.TestCasesExecutionStatusList = testCasesExecutionStatusList.TrimStart(' '); progress.TestCasesExecutionStatusCountList = testCasesExecutionStatusCountList.TrimStart(' '); return progress; }