コード例 #1
0
        public async Task <ResponseService <MedicalConsultation> > Execute(DtoScheduleExamInput scheduleInput)
        {
            var medicalConsultation = await _medicalConsultationRepository.GetById(scheduleInput.MedicalConsultationId);

            if (medicalConsultation == null)
            {
                return(GenerateErroServiceResponse <MedicalConsultation>("A consulta não foi encontrada."));
            }

            if (scheduleInput.MedicalEquipamentId != null)
            {
                var equipament = await _medicalEquipamentRepository.GetById(scheduleInput.MedicalEquipamentId.Value);

                if (equipament == null)
                {
                    return(GenerateErroServiceResponse <MedicalConsultation>("O equipamento informado não foi encontrado."));
                }
            }
            try
            {
                medicalConsultation.ScheduleExam(scheduleInput.MedicalEquipamentId, scheduleInput.ExamDate);
                await _medicalConsultationRepository.Update(medicalConsultation);

                return(GenerateSuccessServiceResponse(medicalConsultation));
            }
            catch (Exception ex)
            {
                return(GenerateErroServiceResponse <MedicalConsultation>(ex.Message));
            }
        }
コード例 #2
0
        public async Task ScheduleExamService_ShouldReturnError_WhenExamIsInvalid()
        {
            var mcId = Guid.NewGuid();
            var meId = Guid.NewGuid();
            var dto  = new DtoScheduleExamInput
            {
                MedicalConsultationId = mcId,
                MedicalEquipamentId   = meId,
                ExamDate = DateTime.Now.AddDays(-1)
            };
            var mc = new MedicalConsultation {
                Id = mcId
            };
            var me = new MedicalEquipament {
                Id = meId
            };

            _mcRepository.Setup(x => x.GetById(mcId)).ReturnsAsync(mc);
            _meRepository.Setup(x => x.GetById(meId)).ReturnsAsync(me);

            var response = await _service.Execute(dto);

            Assert.Equal(HttpStatusCode.BadRequest, response.Status);
        }
コード例 #3
0
 public async Task <IActionResult> ScheduleExam([FromBody] DtoScheduleExamInput schedule)
 {
     return(Created("api/[controller]/{id}", await _scheduleExamService.Execute(schedule)));
 }