public async Task CreateMedicalAppointment_InvalidUsername() { // Prepare var createMedicalAppointmentCommand = new CreateMedicalAppointmentCommand { Description = "Sample", CreatedAt = DateTime.Now.AddDays(15), Username = "******", TypeMedicalAppointmentId = 1 }; // Execute var responseCreate = await _client.PostAsJsonAsync($"{Endpoints.MEDICALAPPOINTMENTS}", createMedicalAppointmentCommand); Assert.Equal(HttpStatusCode.NotFound, responseCreate.StatusCode); }
public async Task <ActionResult <MedicalAppointmentViewModel> > CreateMedicalAppointmentAsync(CreateMedicalAppointmentCommand createMedicalAppointmentCommand) { DateTime dateTimeNow = DateTime.Now; if (dateTimeNow.Date > createMedicalAppointmentCommand.CreatedAt.Date) { return(BadRequest()); } var existingUser = await _userQueries.FindByUsernameAsync(createMedicalAppointmentCommand.Username); if (existingUser == null) { return(NotFound()); } var existingMedicalAppointment = await _queries.FindByCreatedAtUsernameAsync(createMedicalAppointmentCommand.CreatedAt, createMedicalAppointmentCommand.Username); if (existingMedicalAppointment != null) { return(Conflict()); } var medicalAppointment = _mapper.Map <MedicalAppointment>(createMedicalAppointmentCommand); await _behavior.CreateMedicalAppointmentAsync(medicalAppointment); var medicalAppointmentViewModel = await _queries.FindByIdAsync(medicalAppointment.Id); return(medicalAppointmentViewModel); }