Ejemplo n.º 1
0
        public async Task DeleteAppointmentAsync_ValidId_ShouldReturnDeletedAppointment()
        {
            // Arrange
            var existingAppointment = new GetAppointmentPayload
            {
                Id = Guid.NewGuid().ToString(),
            };

            var expectedResponseContent =
                new StringContent(JsonConvert.SerializeObject(existingAppointment, this.fixture.JsonSerializerSettings));

            var expectedResponse = new HttpResponseMessage
            {
                Content = expectedResponseContent,
            };

            var appointmentApi = this.fixture.GetAppointmentApi(expectedResponse);

            var deleteAppointmentResponse = new DeleteAppointmentResponse();

            // Act
            Func <Task> act = async() => deleteAppointmentResponse = await appointmentApi.DeleteAppointmentAsync(existingAppointment.Id);

            // Assert
            await act.Should().NotThrowAsync();

            deleteAppointmentResponse.Id.Should().Be(existingAppointment.Id);
        }
        public override async Task <ActionResult <DeleteAppointmentResponse> > HandleAsync([FromRoute] DeleteAppointmentRequest request, CancellationToken cancellationToken)
        {
            var response = new DeleteAppointmentResponse(request.CorrelationId());

            var toDelete = _mapper.Map <Appointment>(request);
            await _repository.DeleteAsync <Appointment, Guid>(toDelete);

            return(Ok(response));
        }
Ejemplo n.º 3
0
 public void delete(DeleteAppointmentRequest request)
 {
     try
     {
         var response = new DeleteAppointmentResponse();
         var bc       = new AppointmentComponent();
         bc.Delete(request.Appointment);
     }
     catch (Exception ex)
     {
         var httpError = new HttpResponseMessage()
         {
             StatusCode   = (HttpStatusCode)422,
             ReasonPhrase = ex.Message
         };
         throw new HttpResponseException(httpError);
     }
 }
Ejemplo n.º 4
0
        public async Task DeleteAppointmentAsync_ExistingAppointment_ShouldDeleteExistingAppointment()
        {
            // Arrange
            await this.fixture.ClearFactroInstanceAsync();

            var appointmentApi = this.fixture.GetService <IAppointmentApi>();

            var existingAppointment = await this.fixture.CreateTestAppointmentAsync(appointmentApi);

            var deleteAppointmentResponse = new DeleteAppointmentResponse();

            // Act
            Func <Task> act = async() => deleteAppointmentResponse = await appointmentApi.DeleteAppointmentAsync(existingAppointment.Id);

            // Assert
            await act.Should().NotThrowAsync();

            deleteAppointmentResponse.Should().BeEquivalentTo(existingAppointment);

            await this.fixture.ClearFactroInstanceAsync();
        }
        public override async Task <ActionResult <DeleteAppointmentResponse> > HandleAsync([FromRoute] DeleteAppointmentRequest request, CancellationToken cancellationToken)
        {
            var response = new DeleteAppointmentResponse(request.CorrelationId());

            var spec     = new ScheduleByIdWithAppointmentsSpec(request.ScheduleId); // TODO: Just get that day's appointments
            var schedule = await _scheduleReadRepository.GetBySpecAsync(spec);

            var apptToDelete = schedule.Appointments.FirstOrDefault(a => a.Id == request.AppointmentId);

            if (apptToDelete == null)
            {
                return(NotFound());
            }

            schedule.DeleteAppointment(apptToDelete);

            await _scheduleRepository.UpdateAsync(schedule);

            // verify we can still get the schedule
            response.Schedule = _mapper.Map <ScheduleDto>(await _scheduleReadRepository.GetBySpecAsync(spec));

            return(Ok(response));
        }