public void CadastrarAgendamentoTest() { // given var agendamento = new AgendamentoCadastrarViewModel(DateTime.Now, DateTime.Now, "Nada", "C62ACB1E-94E1-487F-0F68-08D79090D2CB", "16E16A8D-469F-4286-A470-08D78CC0F920"); this.agendamentoRepositoryMock.Setup(a => a.BuscarAgendamentoEntreDataEHora(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <Guid>(), It.IsAny <Guid>())).Returns(new List <Agendamento>()); this.agendamentoRepositoryMock.Setup(a => a.CadastrarAgendamento(It.IsAny <Agendamento>())).Returns(true); var agendamentoService = new AgendamentoService(this.agendamentoRepositoryMock.Object, this.consultaRepositoryMock.Object); // when var resultado = agendamentoService.CadastrarAgendamento(agendamento); // then Assert.NotNull(resultado); Assert.True(resultado.Id == 1); }
public void NaoCadastrarAgendamentoDentroIntervaloMesmoPacienteTempoTest() { // given var agendamento = new AgendamentoCadastrarViewModel(DateTime.Now, DateTime.Now, "Nada", "C62ACB1E-94E1-487F-0F68-08D79090D2CB", "16E16A8D-469F-4286-A470-08D78CC0F920"); var lista = new List <Agendamento>(); lista.Add(new Agendamento()); this.agendamentoRepositoryMock.Setup(a => a.BuscarAgendamentoEntreDataEHora(agendamento.DataHoraAgendamento.Subtract(new TimeSpan(0, 14, 0)), agendamento.DataHoraAgendamento.Add(new TimeSpan(0, 14, 0)), new Guid("16E16A8D-469F-4286-A470-08D78CC0F920"), It.IsAny <Guid>())).Returns(lista); this.agendamentoRepositoryMock.Setup(a => a.CadastrarAgendamento(It.IsAny <Agendamento>())).Returns(true); var agendamentoService = new AgendamentoService(this.agendamentoRepositoryMock.Object, this.consultaRepositoryMock.Object); // when var resultado = agendamentoService.CadastrarAgendamento(agendamento); // then Assert.NotNull(resultado); Assert.True(resultado.Id == 0); }
public Mensagem CadastrarAgendamento(AgendamentoCadastrarViewModel agendamentoViewModel) { agendamentoViewModel.DataHoraAgendamento = TimeZoneInfo.ConvertTime(agendamentoViewModel.DataHoraAgendamento, TimeZoneInfo.FindSystemTimeZoneById("E. South America Standard Time")); agendamentoViewModel.DataHoraRegistro = TimeZoneInfo.ConvertTime(agendamentoViewModel.DataHoraRegistro, TimeZoneInfo.FindSystemTimeZoneById("E. South America Standard Time")); if (this.agendamentoRepository.BuscarAgendamentoEntreDataEHora(agendamentoViewModel.DataHoraAgendamento.Subtract(new TimeSpan(0, 14, 0)), agendamentoViewModel.DataHoraAgendamento.Add(new TimeSpan(0, 14, 0)), Guid.Empty, new Guid(agendamentoViewModel.IdMedico)).ToList().Count() > 0) { return(new Mensagem(0, "Este médico já possui uma consulta marcada neste intervalo de hora!")); } if (this.agendamentoRepository.BuscarAgendamentoEntreDataEHora(agendamentoViewModel.DataHoraAgendamento.Subtract(new TimeSpan(0, 14, 0)), agendamentoViewModel.DataHoraAgendamento.Add(new TimeSpan(0, 14, 0)), new Guid(agendamentoViewModel.IdPaciente), Guid.Empty).ToList().Count() > 0) { return(new Mensagem(0, "Este paciente já possui uma consulta marcada neste intervalo de hora!")); } if (this.agendamentoRepository.CadastrarAgendamento(new Agendamento(agendamentoViewModel.DataHoraAgendamento, agendamentoViewModel.DataHoraRegistro, agendamentoViewModel.Observacoes, new Guid(agendamentoViewModel.IdMedico), new Guid(agendamentoViewModel.IdPaciente)))) { return(new Mensagem(1, "Agendamento registrado com sucesso!")); } return(new Mensagem(0, "Falha ao registrar agendamento")); }
public Mensagem CadastrarAgendamento([FromBody] AgendamentoCadastrarViewModel agendamentoViewModel) { return this.agendamentoService.CadastrarAgendamento(agendamentoViewModel); }