Beispiel #1
0
 public static TestCase CreateCase(TestCase instance)
 {
     try
     {
         using (ES1AutomationEntities context = new Core.Model.ES1AutomationEntities())
         {
             instance.IsActive = true;
             TestCase tc = context.TestCases.Add(instance);
             context.SaveChanges();
             return tc;
         }
     }
     catch (Exception e)
     {
         ATFEnvironment.Log.logger.Error(e);
         return null;
     }
 }
Beispiel #2
0
        public static TestCase CreateOrUpdateTestCase(TestCase testCase)
        {
            TestCase findTestCase = TestCase.GetTestCase(testCase.SourceId, testCase.ProviderId);

            // update testcase
            if (findTestCase == null)
            {
                testCase.CreateBy = 0;//automation
                testCase.CreateTime = DateTime.UtcNow;
                TestCase.CreateCase(testCase);
            }
            else
            {
                testCase.TestCaseId = findTestCase.TestCaseId;
                testCase.ModifyBy = 0;//automation
                testCase.ModifyTime = DateTime.UtcNow;

                testCase.Update();
            }

            return testCase;
        }
Beispiel #3
0
        public static bool Delete(TestCase instance)
        {
            try
            {
                List<TestSuite> parentSuites = null;

                using (ES1AutomationEntities context = new Core.Model.ES1AutomationEntities())
                {
                    if (TestCase.GetTestCase(instance.TestCaseId) == null)
                        return false;
                    instance.IsActive = false;
                    //context.TestCases.Remove(instance);
                    //context.SaveChanges();

                    string sId = instance.TestCaseId.ToString();
                    // Remove CaseId from test suites
                    parentSuites = (from ts in context.TestSuites
                                    where ts.TestCases.Contains(sId)
                                    select ts).ToList();

                    context.SaveChanges();
                }

                foreach (TestSuite ts in parentSuites)
                {
                    ts.DeleteSubTestCase(instance.TestCaseId);
                }
            }
            catch (Exception e)
            {
                ATFEnvironment.Log.logger.Error(e);
                return false;
            }

            return true;
        }
        public override void ParseResult(string resultFilePath, int jobId)
        {
            string[] files = System.IO.Directory.GetFiles(resultFilePath);
            try
            {
                foreach (string resultPath in files)
                {
                    string fi = Path.GetFileNameWithoutExtension(resultPath);
                    XmlDocument document = new XmlDocument();
                    document.Load(resultPath);
                    XmlNodeList testCaseResultList = document.SelectNodes("//testsuite/testcase");
                    foreach (XmlNode testCaseResult in testCaseResultList)
                    {
                        try
                        {
                            string caseName = GetTestCase(testCaseResult);  //get name from xml
                            string failureInfo = GetFailureInfo(testCaseResult);

                            Product product = AutomationJob.GetProductOfJobByJobId(jobId);
                            TestCase testcase = TestCase.GetTestCaseByName(caseName);
                            if (testcase == null)
                            {
                                TestCase tc = new TestCase()
                                {
                                    ProviderId = 2,//ATFTestCaseProvider
                                    Name = caseName,
                                    ProductId = product.ProductId,
                                    SourceId = "-1",  // set a default value to sign as a not existing case
                                    Feature = "Galaxy automation",
                                    Weight = 100,
                                    IsAutomated = true,
                                    IsActive = false,
                                };
                                testcase = TestCase.CreateCase(tc);
                            }

                            TestCaseExecution ex = new TestCaseExecution()
                            {
                                TestCaseId = testcase.TestCaseId,
                                JobId = jobId,
                                Status = (int)ExecutionStatus.NotRunning,
                                StartTime = null,
                                EndTime = null,
                                Info = fi,
                                RetryTimes = 0,
                                Timeout = ATFEnvironment.DefaultTestCaseTimeout,
                            };
                            TestCaseExecution exInDB = TestCaseExecution.CreateExecution(ex);
                            SaberAgent.Log.logger.Info(string.Format("Start to parse the result for execution {0} of job {1}", exInDB.ExecutionId, jobId));

                            ResultType result = GetResult(testCaseResult);
                            TestResult re = new TestResult
                            {
                                ExecutionId = exInDB.ExecutionId,
                                Result = (int)result,
                                IsTriaged = false,
                                TriagedBy = null,
                                Description = string.IsNullOrEmpty(failureInfo) ? "" : failureInfo,
                                Files = resultPath,
                            };

                            TestResult resultInDB = TestResult.CreateRunResult(re);

                            SaberAgent.Log.logger.Info(string.Format("Set status of execution {0} of job {1} to Compleate", exInDB.ExecutionId, jobId));
                            exInDB.SetStatus(ExecutionStatus.Complete);
                        }
                        catch (Exception e)
                        {
                            SaberAgent.Log.logger.Error(e);
                        }

                    }
                }
            }
            catch (Exception ex)
            {
                SaberAgent.Log.logger.Error(ex);
            }
            try
            {
                CopyResultFilesToServer(resultFilePath, jobId);
            }
            catch (Exception ex)
            {
                SaberAgent.Log.logger.Error(ex);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Invoked when <see cref="ToEntity"/> operation is about to return.
        /// </summary>
        /// <param name="entity"><see cref="TestCase"/> converted from <see cref="TestCaseDTO"/>.</param>
partial         static void OnEntity(this TestCaseDTO dto, TestCase entity);
Beispiel #6
0
        /// <summary>
        /// Converts this instance of <see cref="TestCaseDTO"/> to an instance of <see cref="TestCase"/>.
        /// </summary>
        /// <param name="dto"><see cref="TestCaseDTO"/> to convert.</param>
        public static TestCase ToEntity(this TestCaseDTO dto)
        {
            if (dto == null) return null;

            var entity = new TestCase();

            entity.TestCaseId = dto.TestCaseId;
            entity.SourceId = dto.SourceId;
            entity.Name = dto.Name;
            entity.ProductId = dto.ProductId;
            entity.Feature = dto.Feature;
            entity.ScriptPath = dto.ScriptPath;
            entity.Weight = dto.Weight;
            entity.Ranking = dto.Ranking;
            entity.Release = dto.Release;
            entity.IsAutomated = dto.IsAutomated;
            entity.CreateBy = dto.CreateBy;
            entity.CreateTime = dto.CreateTime;
            entity.ModifyBy = dto.ModifyBy;
            entity.ModifyTime = dto.ModifyTime;
            entity.Description = dto.Description;

            dto.OnEntity(entity);

            return entity;
        }