예제 #1
0
        public EvaluationScore CreateAnswers(Guid idEvaluation, EvaluationAnswer answersList)
        {
            return(ServiceErrorHandler.Handle(() =>
            {
                Log.Info($"Checking if evaluation with id {idEvaluation} exists");
                var answersDao = this.answersDaoBuilder.Create();
                var evaluationsDao = this.evaluationsDaoBuilder.Create();
                var templatesDao = this.templatesDaoBuilder.Create();

                if (!evaluationsDao.EvaluationExists(idEvaluation))
                {
                    throw new ItemNotFoundServiceException($"Unable to find an evaluation with id {idEvaluation}");
                }

                var evaluation = evaluationsDao.GetEvaluation(idEvaluation);
                var template = templatesDao.GetTemplate(evaluation.IdTemplate);
                var evaluationTemplate = EvaluationScoreHelpers.GenerateEvaluationTemplate(template, evaluation);
                evaluationTemplate.AppendAnswers(answersList);
                var scoreService = ServicesFacade.Instance.GetScoreService();
                var caluculatedEvaluation = scoreService.CalculateScore(evaluationTemplate);

                Log.Info($"Creating answers for evaluation {idEvaluation}");
                caluculatedEvaluation.IdEvaluation = idEvaluation;
                caluculatedEvaluation.Date = DateTime.Now.ToUniversalTime();
                EvaluationScore newAnswers = answersDao.CreateAnswers(caluculatedEvaluation);

                Log.Info($"Evaluation answers created succesfully, Id {newAnswers.Id}");
                return newAnswers;
            }));
        }
        public void TestGenerateEvaluationTemplate()
        {
            var actual = EvaluationScoreHelpers.GenerateEvaluationTemplate(this.Template, this.Evaluation);

            Assert.Equal(this.Expected.IdEvaluation, actual.IdEvaluation);
        }