Example #1
0
        public ActionResult ResultPost(int userTestId, TestResultData model)
        {
            GetCurrentTests().RemoveAll(x => x.Id == userTestId);

            UserTestService.EnableTracking();
            UserTestService.LoadWith(x => x.TestPassRule, x => x.Test);
            var userTest = UserTestService.GetByPK(userTestId);

            UserTestResultPermission(userTest);

            var testName = TestService.GetValues(userTest.TestId, x => new{ x.Name, x.CompanyId });

            var allTestIds = GetAllTestIds(userTest);


            var allQuestionIds = model.Data.Select(x => x.QuestionId).ToList();
            var questions      = GetQuestions(allTestIds).Where(x =>
                                                                allQuestionIds.Contains(x.Id)).ToList();

            var answers = ProcessAnswers(userTest, model, questions);

            SetTestStatus(userTest, answers);
            SendTestResult(testName.Name, userTest, testName.CompanyId);

            ModuleStats(userTest, answers, questions, allTestIds);

            CheckIsBest(userTest);

            UserTestService.SubmitChanges();
            return(Json("ok"));
        }
        private async Task <TestResultData[]> GetTestResultsWithBugRefsAsync(TestResultsDetailsForGroup resultsForGroup)
        {
            var results = await resultsForGroup.Results
                          .ParallelSelectAsync(async resultIdObj =>
            {
                var resultData = new TestResultData();

                resultData.TestResult =
                    await _tcmApiHelper.GetTestResultByIdAsync(int.Parse(resultIdObj.TestRun.Id), resultIdObj.Id);

                // Remove flaky tests
                if (resultData.TestResult.IsTestFlaky())
                {
                    return(null);
                }

                resultData.AssociatedBugRefs =
                    await _tcmApiHelper.QueryTestResultBugsAsync(
                        resultData.TestResult.AutomatedTestName,
                        resultData.TestResult.Id);

                return(resultData);
            });

            //Remove all null values from array
            results = results.Where(r => r != null).ToArray();
            return(results);
        }
Example #3
0
        public TestResultData GetTestCache(string id, [FromUri] TestSourceData testSourceData)
        {
            TestResult testResult;

            var buildSource = new BuildSource(testSourceData.MachineName, testSourceData.EnlistmentRoot);
            var isJenkins   = string.IsNullOrEmpty(testSourceData.Source)
                ? null
                : (bool?)(testSourceData.Source == "jenkins");

            if (_storage.TryGetValue(id, out testResult))
            {
                var isJenkinsValue = isJenkins ?? false;
                _statsUtil.AddHit(isJenkinsValue);
                _statsUtil.AddUnitTestQuery(testResult.UnitTestData, testResult.Elapsed, isJenkinsValue);

                var testResultData = new TestResultData()
                {
                    ExitCode           = testResult.ExitCode,
                    OutputStandard     = testResult.OutputStandard,
                    OutputError        = testResult.OutputError,
                    ResultsFileName    = testResult.ResultsFileName,
                    ResultsFileContent = testResult.ResultsFileContent,
                    ElapsedSeconds     = (int)testResult.Elapsed.TotalSeconds
                };
                return(testResultData);
            }

            _statsUtil.AddMiss(isJenkins ?? false);
            throw new HttpResponseException(HttpStatusCode.NotFound);
        }
Example #4
0
            private void Process(string displayName, TestState state, string output = "")
            {
                Console.WriteLine($"{state} - {displayName}");
                var result = new TestResultData(displayName, state, output);

                _writer.Write(TestDataKind.Value);
                _writer.Write(result);
            }
Example #5
0
            private void Process(string displayName, string uniqueID, TestState state, string output = "")
            {
                System.Diagnostics.Trace.WriteLine($"{state} - {displayName}");
                var result = new TestResultData(displayName, uniqueID, state, output);

                _writer.Write(TestDataKind.Value);
                _writer.Write(result);
            }
Example #6
0
        public async Task Dispatch_Command_SpecificResult_Should_Not_Loose_Value()
        {
            var bus = new InMemoryCommandBus();

            var cmd    = new TestResultData();
            var result = await bus.DispatchAsync(cmd);

            result.Should().BeOfType <Result <string> >();
        }
Example #7
0
        public static void AddTestResult(this TestResultsGroupData source, TestResultData result)
        {
            if (!string.IsNullOrEmpty(result.TestResult.Outcome))
            {
                var testOutcome = EnumHelper.Parse <TestOutcome>(result.TestResult.Outcome);
                if (!source.TestResults.ContainsKey(testOutcome))
                {
                    source.TestResults[testOutcome] = new List <TestResultData>();
                }

                source.TestResults[testOutcome].Add(result);
            }
            else
            {
                // TODO - Log.LogWarning(
                //"Found test with outcome as null. " +
                //$"Test result id {result.TestResult.Id} in Test run {result.TestResult.TestRun?.Id}");
            }
        }
Example #8
0
        private Dictionary <int, bool> ProcessAnswers(UserTest userTest, TestResultData model,
                                                      List <TestQuestion> questions)
        {
            var userTestId = userTest.Id;
            var answers    = new Dictionary <int, bool>();
            var answerList = new List <UserTestAnswer>();

            if (model.Data == null)
            {
                Logger.Exception(new Exception("model.Data == null"), User);
            }
            foreach (var questionAnswer in model.Data)
            {
                var question = questions.First(x => x.Id == questionAnswer.QuestionId);
                var isRight  = IsRight(question, questionAnswer);
                answers.Add(questionAnswer.QuestionId, isRight);
                var answer = new UserTestAnswer {
                    QuestionId = questionAnswer.QuestionId,
                    IsRight    = isRight,
                    UserTestId = userTestId,
                    Answer     = questionAnswer.GetText(),
                };
                answerList.Add(answer);
            }

            if (userTest.IsCoursePlanned || userTest.ShowAnswers)
            {
                UserTestAnswerService.EnableTracking();
                foreach (var userTestAnswer in answerList.Where(x => !x.Answer.IsEmpty()))
                {
                    UserTestAnswerService.Insert(userTestAnswer);
                }
                UserTestAnswerService.SubmitChanges();
            }

            return(answers);
        }
Example #9
0
 public void Write(TestResultData testCaseResultData)
 {
     WriteCore(() => testCaseResultData.WriteTo(_writer));
 }