Ejemplo n.º 1
0
 public static TestResult GetTestCaseResultForTestCaseInTask(int taskId, int testCaseId)
 {
     var testCaseExecution = AutomationTask.GetTestCaseExecutionForTestCaseInTask(taskId, testCaseId);
     if (testCaseExecution != null)//the execute has been started.
     {
         return TestResult.GetTestResultByExecutionId(testCaseExecution.ExecutionId);
     }
     else//the execute has not been started.
     {
         TestResult result = new TestResult();
         result.Result = (int)ResultType.NotRun;
         return result;
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts this instance of <see cref="TestResultDTO"/> to an instance of <see cref="TestResult"/>.
        /// </summary>
        /// <param name="dto"><see cref="TestResultDTO"/> to convert.</param>
        public static TestResult ToEntity(this TestResultDTO dto)
        {
            if (dto == null) return null;

            var entity = new TestResult();

            entity.ResultId = dto.ResultId;
            entity.ExecutionId = dto.ExecutionId;
            entity.Result = dto.Result;
            entity.IsTriaged = dto.IsTriaged;
            entity.TriagedBy = dto.TriagedBy;
            entity.Description = dto.Description;
            entity.Files = dto.Files;

            dto.OnEntity(entity);

            return entity;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Invoked when <see cref="ToEntity"/> operation is about to return.
        /// </summary>
        /// <param name="entity"><see cref="TestResult"/> converted from <see cref="TestResultDTO"/>.</param>
partial         static void OnEntity(this TestResultDTO dto, TestResult entity);
Ejemplo n.º 4
0
        /// <summary>
        /// Dispatch task to jobs based on the test suites defined for dependance
        /// </summary>
        /// <param name="task"></param>
        /// <param name="allCasesForTask"></param>
        private static void DispatchTaskToJobs(AutomationTask task, List<int> allCasesForTask)
        {
            int i = 0;
            string message = string.Empty;
            //Store whether the test cases have been dispatched to job or not based on dependency test suite
            Dictionary<string, bool> testCaseDispatchIndicator = new Dictionary<string, bool>();
            int testcaseProviderId = Product.GetProductByID(task.ProductId.GetValueOrDefault()).TestCaseProviderId.GetValueOrDefault();

            List<TestSuite> dependenceSuites = TestSuite.GetTestSuitesByProviderIdAndType(testcaseProviderId, SuiteType.Dependence).ToList();
            foreach (TestSuite dependenceSuite in dependenceSuites)
            {
                string testCasesForJob = string.Empty;
                foreach (string tc in dependenceSuite.TestCases.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (allCasesForTask.Contains(int.Parse(tc)) && !testCaseDispatchIndicator.ContainsKey(tc))
                    {
                        testCasesForJob = testCasesForJob == string.Empty ? tc : testCasesForJob + ',' + tc;
                        testCaseDispatchIndicator.Add(tc, true);
                    }
                }
                if (testCasesForJob != string.Empty)
                {
                    // Create AutomationJob
                    ++i;
                    AutomationJob job = new AutomationJob()
                    {
                        Name = "JobForTask " + task.TaskId.ToString() + "_" + i.ToString(),
                        Status = (int)JobStatus.Assigned,
                        Type = (int)JobType.Sequence,
                        Priority = task.Priority,
                        RetryTimes = 1,
                        Timeout = ATFConfiguration.GetIntValue("DefaultAutomationJobTimeout"),//1 hours
                        CreateDate = System.DateTime.UtcNow,
                        ModifyDate = System.DateTime.UtcNow,
                        CreateBy = 0,//automation, pre-defined user
                        ModifyBy = 0,//automation, pre-defined user
                    };
                    AutomationJob bCreateJob = AutomationJob.CreateJob(job);

                    message = string.Format("Job [{0}] is created.", bCreateJob.JobId);
                    task.AddProgressInformation(message);
                    ATFEnvironment.Log.logger.Info(message);

                    TaskJobMap map = new TaskJobMap()
                    {
                        TaskId = task.TaskId,
                        JobId = job.JobId,
                    };
                    TaskJobMap.CreateMap(map);

                    foreach (string id in testCasesForJob.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        TestCaseExecution ex = new TestCaseExecution()
                        {
                            TestCaseId = int.Parse(id),
                            JobId = job.JobId,
                            Status = (int)ExecutionStatus.NotRunning,
                            StartTime = null,
                            EndTime = null,
                            RetryTimes = 0,
                            Timeout = ATFEnvironment.DefaultTestCaseTimeout,
                        };
                        TestCaseExecution exInDB = TestCaseExecution.CreateExecution(ex);

                        message = string.Format("Execution [{0}] is created.", exInDB.ExecutionId);
                        //task.AddProgressInformation(message);
                        ATFEnvironment.Log.logger.Info(message);

                        TestResult result = new TestResult
                        {
                            ExecutionId = exInDB.ExecutionId,
                            Result = (int)ResultType.NotRun,
                            IsTriaged = false,
                            TriagedBy = null,
                            Files = null,
                        };
                        TestResult.CreateRunResult(result);

                        message = string.Format("Test result [{0}] is created.", result.ResultId);
                        //task.AddProgressInformation(message);
                        ATFEnvironment.Log.logger.Info(message);
                    }
                }
            }

            foreach (int testcaseId in allCasesForTask)
            {
                if (!testCaseDispatchIndicator.ContainsKey(testcaseId.ToString()))//not dispatched to jobs yet
                {
                    // Create AutomationJob
                    ++i;
                    AutomationJob job = new AutomationJob()
                    {
                        Name = "JobForTask " + task.TaskId.ToString() + "_" + i.ToString(),
                        Status = (int)JobStatus.Assigned,
                        Type = (int)JobType.Sequence,
                        Priority = task.Priority,
                        RetryTimes = 1,
                        Timeout = ATFConfiguration.GetIntValue("DefaultAutomationJobTimeout"),//1 hours
                        CreateDate = System.DateTime.UtcNow,
                        ModifyDate = System.DateTime.UtcNow,
                        CreateBy = 0,//automation, pre-defined user
                        ModifyBy = 0,//automation, pre-defined user
                    };
                    AutomationJob bCreateJob = AutomationJob.CreateJob(job);

                    message = string.Format("Job [{0}] is created.", bCreateJob.JobId);
                    task.AddProgressInformation(message);
                    ATFEnvironment.Log.logger.Info(message);

                    TaskJobMap map = new TaskJobMap()
                    {
                        TaskId = task.TaskId,
                        JobId = job.JobId,
                    };
                    TaskJobMap.CreateMap(map);

                    TestCaseExecution ex = new TestCaseExecution()
                    {
                        TestCaseId = testcaseId,
                        JobId = job.JobId,
                        Status = (int)ExecutionStatus.NotRunning,
                        StartTime = null,
                        EndTime = null,
                        RetryTimes = 0,
                        Timeout = ATFEnvironment.DefaultTestCaseTimeout,
                    };
                    TestCaseExecution exInDB = TestCaseExecution.CreateExecution(ex);

                    message = string.Format("Execution [{0}] is created.", exInDB.ExecutionId);
                    //task.AddProgressInformation(message);
                    ATFEnvironment.Log.logger.Info(message);

                    TestResult result = new TestResult
                    {
                        ExecutionId = exInDB.ExecutionId,
                        Result = (int)ResultType.NotRun,
                        IsTriaged = false,
                        TriagedBy = null,
                        Files = null,
                    };
                    TestResult.CreateRunResult(result);

                    message = string.Format("Test result [{0}] is created.", result.ResultId);
                    //task.AddProgressInformation(message);
                    ATFEnvironment.Log.logger.Info(message);
                }
            }
        }