Exemple #1
0
        public async Task <IActionResult> EndExam([FromBody] DtoEndExamInput input)
        {
            var userId = Guid.Parse(User.Claims.First(x => x.Type == "UserId").Value);

            var responseService = await _completeExamService.Execute(userId, input);

            if (responseService.Success)
            {
                return(Ok(responseService.Value));
            }
            return(BadRequest(responseService.Message));
        }
Exemple #2
0
        public async Task <ResponseService <MedicalExam> > Execute(Guid userId, DtoEndExamInput input)
        {
            var exam = await _medicalExamRepository.GetById(input.ExamId);

            if (exam == null)
            {
                return(GenerateErroServiceResponse <MedicalExam>("O exame não foi encontrado."));
            }
            try
            {
                exam.EndExam(userId, input.ExamResult);
                await _medicalExamRepository.Update(exam);

                return(GenerateSuccessServiceResponse(exam));
            }
            catch (Exception ex)
            {
                return(GenerateErroServiceResponse <MedicalExam>(ex.Message));
            }
        }
Exemple #3
0
        public async Task EndExamService_ShouldReturnSuccess_WhenExamIsValid()
        {
            var examId     = Guid.NewGuid();
            var examResult = "oba";
            var dto        = new DtoEndExamInput
            {
                ExamId     = examId,
                ExamResult = examResult
            };
            var exam = new MedicalExam
            {
                Id = examId
            };

            _medicalExamRepository.Setup(x => x.GetById(examId)).ReturnsAsync(exam);
            _medicalExamRepository.Setup(x => x.Update(exam)).ReturnsAsync(exam);

            var response = await _service.Execute(examId, dto);

            Assert.Equal(HttpStatusCode.OK, response.Status);
        }
Exemple #4
0
        public async Task EndExamService_ShouldReturnError_WhenExamIsInvalid()
        {
            var examId     = Guid.NewGuid();
            var examResult = "oba";
            var dto        = new DtoEndExamInput
            {
                ExamId     = examId,
                ExamResult = examResult
            };
            var exam = new MedicalExam
            {
                Id = examId
            };

            MedicalExam exameNaoExistente = null;

            _medicalExamRepository.Setup(x => x.GetById(examId)).ReturnsAsync(exameNaoExistente);
            _medicalExamRepository.Setup(x => x.Update(exam)).ReturnsAsync(exam);

            var response = await _service.Execute(examId, dto);

            Assert.Equal(HttpStatusCode.BadRequest, response.Status);
        }