コード例 #1
0
        // todo: unit test public interfaces
        public void DeleteAll(int suiteId)
        {
            var temporaryTestResultsToDelete = _db.TemporaryTestResults.Where(ttr => ttr.SuiteId == suiteId);

            _db.TemporaryTestResults.RemoveRange(temporaryTestResultsToDelete);
            _db.SaveChanges();
        }
コード例 #2
0
        public ICollection <TestStepResult> Save(int testId, int testResultId, IEnumerable <TestStepResult> testStepResults)
        {
            var dbTestSteps = _db.TestSteps.AsNoTracking().ToList();
            var dbTest      = _db.Tests
                              .Include(t => t.TestSteps)
                              .Single(t => t.TestID == testId);

            var savedTestStepResults = new List <TestStepResult>();

            foreach (var testStepResult in testStepResults)
            {
                var dbTestStepResult = new DbTestStepResult
                {
                    TestResultId = testResultId,
                    TestStepResultStartDateTime = testStepResult.StartTime,
                    TestStepResultEndDateTime   = testStepResult.EndTime,
                    TestStepResultTypeId        = Map(testStepResult.ResultType)
                };

                // use FirstOrDefault instead of SingleOrDefault because first-run multi-threaded tests can end up inserting duplicate step names
                // (before the check for duplicates happens)
                var existingTestStep = dbTestSteps
                                       .FirstOrDefault(t => t.TestStepName == testStepResult.TestStep.Name);
                if (existingTestStep != null)
                {
                    dbTestStepResult.TestStepId = existingTestStep.TestStepID;
                }
                else
                {
                    dbTestStepResult.TestStep = new DbTestStep {
                        TestStepName = testStepResult.TestStep.Name
                    }
                };

                _db.TestStepResults.Add(dbTestStepResult);
                _db.SaveChanges();

                if (!dbTest.TestSteps.Any(t => t.TestStepID == dbTestStepResult.TestStepId))
                {
                    dbTest.TestSteps.Add(
                        _db.TestSteps
                        .Single(ts => ts.TestStepID == dbTestStepResult.TestStepId));
                }

                savedTestStepResults.Add(Map(dbTestStepResult, dbTest));
            }

            _db.SaveChanges();

            return(savedTestStepResults);
        }
コード例 #3
0
 private void SaveTestFailedDuration(DbTestFailureDuration testFailedDuration)
 {
     if (testFailedDuration.TestFailureDurationID == 0)
     {
         _db.TestFailureDurations.Add(testFailedDuration);
     }
     _db.SaveChanges();
 }
コード例 #4
0
 private void SaveLatestTestResult(DbLatestTestResult latestTestResult)
 {
     if (latestTestResult.LatestTestResultID == 0)
     {
         _db.LatestTestResults.Add(latestTestResult);
     }
     _db.SaveChanges();
 }
コード例 #5
0
ファイル: SuiteResultService.cs プロジェクト: bkolonay/zignet
        public int SaveSuiteResult(SuiteResult domainSuiteResult)
        {
            DbSuiteResult dbSuiteResult = null;

            if (domainSuiteResult.SuiteResultID == 0)
            {
                dbSuiteResult = _suiteResultMapper.Map(domainSuiteResult);
                _db.SuiteResults.Add(dbSuiteResult);
            }
            else
            {
                dbSuiteResult = _db.SuiteResults.Single(s => s.SuiteResultID == domainSuiteResult.SuiteResultID);
                _suiteResultMapper.Map(dbSuiteResult, domainSuiteResult);
            }

            _db.SaveChanges();
            return(dbSuiteResult.SuiteResultID);
        }
コード例 #6
0
        public TestResult Save(TestResult testResult)
        {
            var existingTest = _db.Tests
                               .AsNoTracking()
                               .Include(t => t.TestCategories)
                               .Select(t =>
                                       new Test
            {
                TestID     = t.TestID,
                Name       = t.TestName,
                Categories = t.TestCategories.Select(tc => new TestCategory {
                    TestCategoryID = tc.TestCategoryID, Name = tc.CategoryName
                }).ToList()
            }
                                       )
                               .SingleOrDefault(t => t.Name == testResult.Test.Name);

            if (existingTest != null)
            {
                testResult.Test.TestID     = existingTest.TestID;
                testResult.Test.Categories = testResult.Test.Categories.Concat(existingTest.Categories).ToList();
            }

            var dbTestResult = new DbTestResult
            {
                SuiteResultId           = testResult.SuiteResult.SuiteResultID,
                TestResultStartDateTime = testResult.StartTime,
                TestResultEndDateTime   = testResult.EndTime,
                TestResultTypeId        = _testResultMapper.ToDbTestResultTypeId(testResult.ResultType)
            };

            if (testResult.ResultType == TestResultType.Fail)
            {
                var testFailureTypeId = _testResultMapper.ToDbTestFailureTypeId(testResult.TestFailureDetails.FailureType);
                var testFailureType   = _db.TestFailureTypes.Single(t => t.TestFailureTypeID == testFailureTypeId);
                dbTestResult.TestFailureTypes.Add(testFailureType);
                if (!string.IsNullOrWhiteSpace(testResult.TestFailureDetails.FailureDetailMessage))
                {
                    dbTestResult.TestFailureDetails.Add(
                        new DbTestFailureDetail {
                        TestFailureDetail1 = testResult.TestFailureDetails.FailureDetailMessage
                    });
                }
            }

            if (testResult.Test.TestID != 0)
            {
                dbTestResult.Test = _db.Tests
                                    .Include(t => t.Suites)
                                    .Single(t => t.TestID == testResult.Test.TestID);
            }
            else
            {
                dbTestResult.Test = new DbTest
                {
                    TestName       = testResult.Test.Name,
                    TestCategories = new List <DbTestCategory>()
                }
            };

            dbTestResult.Test.TestCategories.Clear();
            var dbTestCategories = _db.TestCategories.ToList();

            foreach (var testCategory in testResult.Test.Categories)
            {
                // use FirstOrDefault instead of SingleOrDefault because first-run multi-threaded tests end up inserting duplicate categories
                // (before the check for duplicates happens)
                var existingDbTestCategory = dbTestCategories
                                             .FirstOrDefault(c => c.CategoryName == testCategory.Name);
                if (existingDbTestCategory != null)
                {
                    dbTestResult.Test.TestCategories.Add(existingDbTestCategory);
                }
                else
                {
                    dbTestResult.Test.TestCategories.Add(new DbTestCategory {
                        CategoryName = testCategory.Name
                    });
                }
            }

            var suiteResult = _db.SuiteResults
                              .AsNoTracking()
                              .Single(sr => sr.SuiteResultID == testResult.SuiteResult.SuiteResultID);

            if (!dbTestResult.Test.Suites.Any(s => s.SuiteID == suiteResult.SuiteId))
            {
                dbTestResult.Test.Suites.Add(
                    _db.Suites
                    .Single(s => s.SuiteID == suiteResult.SuiteId));
            }

            _db.TestResults.Add(dbTestResult);
            _db.SaveChanges();

            var savedTestResult = Map(dbTestResult, suiteResult.SuiteId);

            _testStepService.Save(savedTestResult.Test.TestID, savedTestResult.TestResultID, testResult.TestStepResults);

            _temporaryTestResultService.Save(_testResultMapper.ToTemporaryTestResult(savedTestResult));

            var utcNow = DateTime.UtcNow;

            savedTestResult.SuiteResult.Suite.Name = _db.Suites
                                                     .AsNoTracking()
                                                     .Single(s => s.SuiteID == suiteResult.SuiteId)
                                                     .SuiteName;
            _latestTestResultService.Save(
                _testResultMapper.ToLatestTestResult(savedTestResult), savedTestResult.ResultType, utcNow);

            _testFailureDurationService.Save(
                _testResultMapper.ToTestFailureDuration(savedTestResult), savedTestResult.ResultType, utcNow);

            return(savedTestResult);
        }