public async Task UpdateAppointmentAsync_ValidUpdate_ShouldReturnUpdatedAppointment() { // Arrange await this.fixture.ClearFactroInstanceAsync(); var appointmentApi = this.fixture.GetService <IAppointmentApi>(); var existingAppointment = await this.fixture.CreateTestAppointmentAsync(appointmentApi); var updatedSubject = $"{BaseTestFixture.TestPrefix}{Guid.NewGuid().ToString()}"; var updateAppointmentRequest = new UpdateAppointmentRequest { Subject = updatedSubject, }; var updateAppointmentResponse = new UpdateAppointmentResponse(); // Act Func <Task> act = async() => updateAppointmentResponse = await appointmentApi.UpdateAppointmentAsync(existingAppointment.Id, updateAppointmentRequest); // Assert await act.Should().NotThrowAsync(); using (new AssertionScope()) { var appointments = (await appointmentApi.GetAppointmentsAsync()) .Where(x => x.Subject.StartsWith(BaseTestFixture.TestPrefix)).ToList(); appointments.Should().ContainEquivalentOf(updateAppointmentResponse); appointments.Single(x => x.Id == existingAppointment.Id).Subject.Should().Be(updatedSubject); } await this.fixture.ClearFactroInstanceAsync(); }
public override async Task <ActionResult <UpdateAppointmentResponse> > HandleAsync(UpdateAppointmentRequest request, CancellationToken cancellationToken) { var response = new UpdateAppointmentResponse(request.CorrelationId()); var apptType = await _appointmentTypeRepository.GetByIdAsync(request.AppointmentTypeId); var spec = new ScheduleByIdWithAppointmentsSpec(request.ScheduleId); // TODO: Just get that day's appointments var schedule = await _scheduleReadRepository.GetBySpecAsync(spec); var apptToUpdate = schedule.Appointments.FirstOrDefault(a => a.Id == request.Id); apptToUpdate.UpdateAppointmentType(apptType); apptToUpdate.UpdateRoom(request.RoomId); apptToUpdate.UpdateStartTime(request.Start, schedule.AppointmentUpdatedHandler); apptToUpdate.UpdateTitle(request.Title); apptToUpdate.UpdateDoctor(request.DoctorId); await _scheduleRepository.UpdateAsync(schedule); var dto = _mapper.Map <AppointmentDto>(apptToUpdate); response.Appointment = dto; return(Ok(response)); }
public async Task UpdateAppointmentAsync_ValidRequest_ShouldReturnUpdatedAppointment() { // Arrange var existingAppointment = new GetAppointmentPayload { Id = Guid.NewGuid().ToString(), Subject = "TestSubject", }; var updateAppointmentRequest = new UpdateAppointmentRequest { Subject = "NewSubject", }; var expectedUpdatedAppointment = new UpdateAppointmentResponse { Id = existingAppointment.Id, Subject = updateAppointmentRequest.Subject, }; var expectedResponseContent = new StringContent(JsonConvert.SerializeObject(expectedUpdatedAppointment, this.fixture.JsonSerializerSettings)); var expectedResponse = new HttpResponseMessage { Content = expectedResponseContent, }; var appointmentApi = this.fixture.GetAppointmentApi(expectedResponse); var updateAppointmentResponse = new UpdateAppointmentResponse(); // Act Func <Task> act = async() => updateAppointmentResponse = await appointmentApi.UpdateAppointmentAsync(existingAppointment.Id, updateAppointmentRequest); // Assert await act.Should().NotThrowAsync(); using (new AssertionScope()) { updateAppointmentResponse.Id.Should().Be(existingAppointment.Id); updateAppointmentResponse.Subject.Should().Be(expectedUpdatedAppointment.Subject); } }
public override async Task <ActionResult <UpdateAppointmentResponse> > HandleAsync(UpdateAppointmentRequest request, CancellationToken cancellationToken) { var response = new UpdateAppointmentResponse(request.CorrelationId()); var toUpdate = _mapper.Map <Appointment>(request); var appointmentType = await _repository.GetByIdAsync <AppointmentType, int>(toUpdate.AppointmentTypeId); toUpdate.UpdateEndTime(appointmentType); await _repository.UpdateAsync <Appointment, Guid>(toUpdate); var dto = _mapper.Map <AppointmentDto>(toUpdate); response.Appointment = dto; return(Ok(response)); }
public void delete(UpdateAppointmentRequest request) { try { var response = new UpdateAppointmentResponse(); var bc = new AppointmentComponent(); bc.Update(request.Appointment); } catch (Exception ex) { var httpError = new HttpResponseMessage() { StatusCode = (HttpStatusCode)422, ReasonPhrase = ex.Message }; throw new HttpResponseException(httpError); } }