예제 #1
0
        /* Primary mutations - manupulating specific Evaluations */
        public Evaluation CreateEvaluation(
            string name,
            string projectId,
            string previousEvaluationId,
            string projectCategoryId
            )
        {
            var azureUniqueId = _authService.GetOID();

            var project    = _projectService.GetProject(projectId);
            var evaluation = _evaluationService.Create(
                name: name,
                project: project,
                previousEvaluationId: previousEvaluationId
                );

            _participantService.Create(
                azureUniqueId: azureUniqueId,
                evaluation: evaluation,
                organization: Organization.All,
                role: Role.Facilitator
                );

            var projectCategory = _projectCategoryService.Get(projectCategoryId);
            var questions       = _questionTemplateService.ActiveQuestions(projectCategory);

            _questionService.CreateBulk(questions, evaluation);
            _questionService.SquashOrder(evaluation.Questions);

            var log = $"Evaluation with id: {evaluation.Id} was created by azureId: {azureUniqueId}";

            _logger.LogInformation(log);
            return(evaluation);
        }
예제 #2
0
        public Evaluation CreateEvaluation(string name, string projectId)
        {
            string     azureUniqueId = _authService.GetOID();
            Project    project       = _projectService.GetProject(projectId);
            Evaluation evaluation    = _evaluationService.Create(name, project);

            _participantService.Create(azureUniqueId, evaluation, Organization.All, Role.Facilitator);

            _questionService.CreateBulk(_questionTemplateService.ActiveQuestions(), evaluation);
            return(evaluation);
        }
 public ActionResult <Participant> Create(Participant participantTmp)
 {
     _participantService.Create(participantTmp);
     return(CreatedAtRoute("GetParticipant",
                           new { id = participantTmp.Id },
                           participantTmp));
 }
예제 #4
0
        public void ProgressEvaluationToFollowup()
        {
            Project     project     = _projectService.Create("ProgressEvaluationToFollowup");
            Evaluation  evaluation  = _evaluationService.Create("ProgressEvaluationToFollowup", project);
            Participant participant = _participantService.Create("ProgressEvaluationToFollowup", evaluation, Organization.All, Role.Facilitator);

            List <Question> questions = _questionService.CreateBulk(_questionTemplateService.GetAll().ToList(), evaluation);

            _answerService.Create(participant, questions[0], Severity.High, "test_answer_0", Progression.Workshop);
            _answerService.Create(participant, questions[1], Severity.High, "test_answer_1", Progression.Workshop);
            _answerService.Create(participant, questions[2], Severity.High, "test_answer_2", Progression.Workshop);

            int nAnswersWorkshop = _context.Answers.Where(
                a => (a.Progression.Equals(Progression.Workshop) && a.Question.Evaluation.Equals(evaluation))
                ).Count();

            // Forces null on db relations
            // To simulate behavior of normal API call
            _context.ChangeTracker.Clear();

            _mutation.ProgressEvaluation(evaluation.Id, Progression.FollowUp);

            int nAnswersFollowup = _context.Answers.Where(
                a => (a.Progression.Equals(Progression.FollowUp) && a.Question.Evaluation.Equals(evaluation))
                ).Count();

            Assert.Equal(nAnswersWorkshop, nAnswersFollowup);
        }
예제 #5
0
        public void CreateFollowUpAnswers()
        {
            ParticipantService participantService = new ParticipantService(fixture.context);
            QuestionService    questionService    = new QuestionService(fixture.context);
            AnswerService      answerService      = new AnswerService(fixture.context);

            ProjectService    projectService    = new ProjectService(fixture.context);
            Project           project           = projectService.Create("AnswerService_GetFromQuestionExists");
            EvaluationService evaluationService = new EvaluationService(fixture.context);
            Evaluation        evaluation        = evaluationService.Create("AnswerService_GetFromQuestionExists", project, "");

            Participant             participant = participantService.Create("CreateFollowUpAnswers_id", evaluation, Organization.All, Role.Facilitator);
            QuestionTemplateService qts         = new QuestionTemplateService(fixture.context);
            List <Question>         questions   = questionService.CreateBulk(qts.GetAll().ToList(), evaluation);

            answerService.Create(participant, questions[0], Severity.High, "test_answer_0", Progression.Workshop);
            answerService.Create(participant, questions[1], Severity.High, "test_answer_1", Progression.Workshop);
            answerService.Create(participant, questions[2], Severity.High, "test_answer_2", Progression.Workshop);

            int nAnswersFollowupBefore = answerService.GetAll().Where(a => (a.Progression.Equals(Progression.FollowUp) && a.Question.Evaluation.Equals(evaluation))).Count();
            int nAnswersWorkshop       = answerService.GetAll().Where(a => (a.Progression.Equals(Progression.Workshop) && a.Question.Evaluation.Equals(evaluation))).Count();

            answerService.CreateFollowUpAnswers(evaluation);
            int nAnswersFollowup = answerService.GetAll().Where(a => (a.Progression.Equals(Progression.FollowUp) && a.Question.Evaluation.Equals(evaluation))).Count();

            Assert.Equal(nAnswersFollowupBefore + nAnswersWorkshop, nAnswersFollowup);
        }
예제 #6
0
        public void ParticipantUnique()
        {
            DbContextOptionsBuilder <BmtDbContext> builder = new DbContextOptionsBuilder <BmtDbContext>();

            builder.UseSqlite(_connection);

            // This is done because bug in xunit making Dbcontext dispose never being called when exception is thrown
            using (var _context = new BmtDbContext(builder.Options))
            {
                EvaluationService evaluationService = new EvaluationService(_context);
                Evaluation        evaluation        = evaluationService.GetAll().First();

                ParticipantService participantService = new ParticipantService(_context);
                participantService.Create("azure_unique_id", evaluation, Organization.All, Role.OrganizationLead);
                Assert.Throws <DbUpdateException>(() => participantService.Create("azure_unique_id", evaluation, Organization.All, Role.OrganizationLead));
            }
        }
예제 #7
0
        public void ProgressAllParticipants()
        {
            ProjectService     projectService     = new ProjectService(_context);
            ParticipantService participantService = new ParticipantService(_context);
            EvaluationService  evaluationService  = new EvaluationService(_context);
            Project            project            = projectService.Create("ProgressAllParticipants");
            Evaluation         evaluation         = evaluationService.Create("ProgressAllParticipants", project);
            Participant        participant1       = participantService.Create("ProgressAllParticipants1", evaluation, Organization.All, Role.Facilitator);
            Participant        participant2       = participantService.Create("ProgressAllParticipants2", evaluation, Organization.Commissioning, Role.OrganizationLead);

            Progression progression1Before = participant1.Progression;

            participantService.ProgressAllParticipants(evaluation, Progression.Individual);
            Progression progression1After = participant1.Progression;
            Progression progression2After = participant2.Progression;

            Assert.Equal(Progression.Nomination, progression1Before);
            Assert.Equal(Progression.Individual, progression1After);
            Assert.Equal(Progression.Individual, progression2After);
        }
예제 #8
0
        public void CreateGetsCorrectEvaluationId()
        {
            ParticipantService participantService = new ParticipantService(_context);
            EvaluationService  evaluationService  = new EvaluationService(_context);
            Evaluation         evaluation         = evaluationService.GetAll().First();

            string      evaluationIdBefore = evaluation.Id;
            Participant participant        = participantService.Create("CreateGetsCorrectEvaluationId_id", evaluation, Organization.Engineering, Role.Participant);
            string      evaluationIdAfter  = participant.Evaluation.Id;

            Assert.Equal(evaluationIdBefore, evaluationIdAfter);
        }
예제 #9
0
        public void GetExist()
        {
            EvaluationService evaluationService = new EvaluationService(_context);
            Evaluation        evaluation        = evaluationService.GetAll().First();

            ParticipantService participantService = new ParticipantService(_context);
            Participant        participantCreate  = participantService.Create("GetExist_id", evaluation, Organization.Engineering, Role.Participant);

            Participant participantGet = participantService.GetParticipant(participantCreate.Id);

            Assert.Equal(participantCreate, participantGet);
        }
예제 #10
0
        public void ParticipantAddedToEvaluation()
        {
            EvaluationService  evaluationService  = new EvaluationService(_context);
            Evaluation         evaluation         = evaluationService.GetAll().First();
            ParticipantService participantService = new ParticipantService(_context);

            int participantsBefore = evaluation.Participants.Count;

            participantService.Create("ParticipantAddedToEvaluation_id", evaluation, Organization.Engineering, Role.Participant);
            int participantsAfter = evaluation.Participants.Count;

            Assert.Equal(participantsBefore + 1, participantsAfter);
        }
예제 #11
0
        public void GetAzureId()
        {
            EvaluationService evaluationService = new EvaluationService(_context);
            Evaluation        evaluation        = evaluationService.GetAll().First();

            ParticipantService participantService = new ParticipantService(_context);
            string             azureUniqueId      = "GetAzureId_id";
            Participant        participantCreated = participantService.Create(azureUniqueId, evaluation, Organization.Engineering, Role.Participant);

            Participant participantGet = participantService.GetParticipant(azureUniqueId, evaluation);

            Assert.Equal(participantCreated, participantGet);
        }
예제 #12
0
        public void Delete()
        {
            EvaluationService evaluationService = new EvaluationService(_context);
            Evaluation        evaluation        = evaluationService.GetAll().First();

            ParticipantService participantService = new ParticipantService(_context);

            Participant participantCreate = participantService.Create("Delete_id", evaluation, Organization.Engineering, Role.Participant);

            participantService.Remove(participantCreate.Id);

            Assert.Throws <NotFoundInDBException>(() => participantService.GetParticipant(participantCreate.Id));
        }
예제 #13
0
        public void ParticipantAddedToProject()
        {
            ProjectService     projectService     = new ProjectService(_context);
            Project            project            = projectService.GetAll().First();
            Evaluation         evaluation         = project.Evaluations.First();
            ParticipantService participantService = new ParticipantService(_context);

            int participantsBefore = project.Evaluations.First().Participants.Count;

            participantService.Create("ParticipantAddedToProject", evaluation, Organization.Engineering, Role.Participant);
            int participantsAfter = project.Evaluations.First().Participants.Count;

            Assert.Equal(participantsBefore + 1, participantsAfter);
        }
예제 #14
0
        public void ParticipantDeletedFromEvaluation()
        {
            EvaluationService  evaluationService  = new EvaluationService(fixture.context);
            Evaluation         evaluation         = evaluationService.GetAll().First();
            ParticipantService participantService = new ParticipantService(fixture.context);
            Participant        participant        = participantService.Create("ParticipantDeletedFromEvaluation_id", evaluation, Organization.Engineering, Role.Participant);

            int participantsBefore = evaluation.Participants.Count;

            participantService.Remove(participant.Id);
            int participantsAfter = evaluation.Participants.Count;

            Assert.Equal(participantsBefore - 1, participantsAfter);
        }
예제 #15
0
        public void Create()
        {
            EvaluationService evaluationService = new EvaluationService(_context);
            Evaluation        evaluation        = evaluationService.GetAll().First();

            ParticipantService participantService = new ParticipantService(_context);

            int nParticipantsBefore = participantService.GetAll().Count();

            participantService.Create("Create_id", evaluation, Organization.Engineering, Role.Participant);
            int nParticipantsAfter = participantService.GetAll().Count();

            Assert.Equal(nParticipantsBefore + 1, nParticipantsAfter);
        }
예제 #16
0
        public void GetFromQuestionNotExists()
        {
            EvaluationService evaluationService = new EvaluationService(_context);
            Evaluation        evaluation        = evaluationService.GetAll().First();

            ParticipantService participantService = new ParticipantService(_context);
            Participant        participant        = participantService.Create("GetFromQuestionNotExists_id", evaluation, Organization.All, Role.ReadOnly);

            QuestionService questionService = new QuestionService(_context);
            Question        question        = questionService.GetAll().First();

            AnswerService answerService = new AnswerService(_context);

            Assert.Throws <NotFoundInDBException>(() => answerService.GetAnswer(question, participant, Progression.Nomination));
        }
예제 #17
0
        public void ProgressParticipant()
        {
            ProjectService     projectService     = new ProjectService(_context);
            ParticipantService participantService = new ParticipantService(_context);
            EvaluationService  evaluationService  = new EvaluationService(_context);
            Project            project            = projectService.Create("ProgressParticipant");
            Evaluation         evaluation         = evaluationService.Create("ProgressParticipant", project);
            Participant        participant        = participantService.Create("ProgressParticipant", evaluation, Organization.All, Role.Facilitator);

            Progression progressionBefore = participant.Progression;

            participantService.ProgressParticipant(participant, Progression.Individual);
            Progression progressionAfter = participant.Progression;

            Assert.Equal(Progression.Nomination, progressionBefore);
            Assert.Equal(Progression.Individual, progressionAfter);
        }