Beispiel #1
0
        public LatestTestResultDto Save(LatestTestResultDto latestTestResultDto, TestResultType testResultType, DateTime utcNow)
        {
            var dbLatestTestResult = _db.LatestTestResults
                                     .SingleOrDefault(t =>
                                                      t.SuiteId == latestTestResultDto.SuiteId &&
                                                      t.TestId == latestTestResultDto.TestId
                                                      );

            var suiteNameChanged = false;

            if (dbLatestTestResult == null)
            {
                dbLatestTestResult = new DbLatestTestResult
                {
                    SuiteId   = latestTestResultDto.SuiteId,
                    TestId    = latestTestResultDto.TestId,
                    TestName  = latestTestResultDto.TestName,
                    SuiteName = latestTestResultDto.SuiteName
                }
            }
            ;
            else if (dbLatestTestResult.SuiteName != latestTestResultDto.SuiteName)
            {
                dbLatestTestResult.SuiteName = latestTestResultDto.SuiteName;
                suiteNameChanged             = true;
            }

            if (testResultType == TestResultType.Pass && dbLatestTestResult.PassingFromDateTime == null)
            {
                dbLatestTestResult.TestResultId        = latestTestResultDto.TestResultID;
                dbLatestTestResult.PassingFromDateTime = utcNow;
                dbLatestTestResult.FailingFromDateTime = null;
                SaveLatestTestResult(dbLatestTestResult);
            }
            else if ((testResultType == TestResultType.Fail || testResultType == TestResultType.Inconclusive) &&
                     dbLatestTestResult.FailingFromDateTime == null)
            {
                dbLatestTestResult.TestResultId        = latestTestResultDto.TestResultID;
                dbLatestTestResult.FailingFromDateTime = utcNow;
                dbLatestTestResult.PassingFromDateTime = null;
                SaveLatestTestResult(dbLatestTestResult);
            }
            else if (suiteNameChanged)
            {
                SaveLatestTestResult(dbLatestTestResult);
            }

            // todo: move to mapping class
            return(new LatestTestResultDto
            {
                LatestTestResultID = dbLatestTestResult.LatestTestResultID,
                TestResultID = dbLatestTestResult.TestResultId,
                SuiteId = dbLatestTestResult.SuiteId,
                TestId = dbLatestTestResult.TestId,
                TestName = dbLatestTestResult.TestName,
                SuiteName = dbLatestTestResult.SuiteName,
                PassingFromDate = dbLatestTestResult.PassingFromDateTime,
                FailingFromDate = dbLatestTestResult.FailingFromDateTime
            });
        }
Beispiel #2
0
 private void SaveLatestTestResult(DbLatestTestResult latestTestResult)
 {
     if (latestTestResult.LatestTestResultID == 0)
     {
         _db.LatestTestResults.Add(latestTestResult);
     }
     _db.SaveChanges();
 }