public void Update(Appointment appointment) { var request = new UpdateAppointmentRequest(); request.Appointment = appointment; var response = HttpPost <UpdateAppointmentRequest>("api/appointment/update", request, MediaType.Json); }
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 void Update(UpdateAppointmentRequest request) { var session = _sessionFactory.OpenSession(); CurrentSessionContext.Bind(session); try { using (var transactionScope = new TransactionScope()) { var appointment = _appointmentRepository.GetById(request.Id); DomainEvents.Register <AppointmentUpdatedEvent>(AppointmentUpdated); appointment.Update( request.Date, request.StartTime, request.EndTime, request.LeadName, request.Address); session.Flush(); transactionScope.Complete(); } } finally { CurrentSessionContext.Unbind(_sessionFactory); session.Dispose(); } }
private async Task SaveAppointment() { if (IsValid()) { if (Appointment.AppointmentId == Guid.Empty) { CreateAppointmentRequest toCreate = new CreateAppointmentRequest() { Details = Title, SelectedDoctor = (int)Appointment.DoctorId, PatientId = Patient.PatientId, ClientId = Patient.ClientId, ScheduleId = ScheduleId, RoomId = Appointment.RoomId, AppointmentTypeId = Appointment.AppointmentTypeId, DateOfAppointment = Appointment.Start.DateTime, }; await AppointmentService.CreateAsync(toCreate); } else { var toUpdate = UpdateAppointmentRequest.FromDto(Appointment); await AppointmentService.EditAsync(toUpdate); } await OnAppointmentChanged.InvokeAsync(Appointment.Title); } }
public ValidationMessageCollection ValidateUpdate(UpdateAppointmentRequest request) { var session = _sessionFactory.OpenSession(); CurrentSessionContext.Bind(session); try { Appointment appointment; using (var transaction = session.BeginTransaction()) { appointment = _appointmentRepository.GetById(request.Id); transaction.Commit(); } return(appointment.ValidateUpdate( request.Date, request.StartTime, request.EndTime, request.LeadName, request.Address)); } finally { CurrentSessionContext.Unbind(_sessionFactory); session.Dispose(); } }
public ActionResult BookUpdate(BookAppointmentViewModel viewModel) { if (viewModel.Updating) { var updateBookingRequest = new UpdateAppointmentRequest { Id = viewModel.AppointmentId.Value, Date = viewModel.Date, StartTime = viewModel.StartTime, EndTime = viewModel.EndTime, LeadName = viewModel.LeadName, Address = viewModel.Address }; var validationResult = _appointmentService.ValidateUpdate(updateBookingRequest); if (!validationResult.IsValid) { foreach (var error in validationResult.Errors) { ModelState.AddModelError(error.Field ?? "", error.Text); } return(View("BookUpdate", viewModel)); } _appointmentService.Update(updateBookingRequest); } else { Guid id = Guid.NewGuid(); var makeBookingRequest = new BookAppointmentRequest { Id = id, ConsultantId = viewModel.ConsultantId.Value, Date = viewModel.Date, StartTime = viewModel.StartTime, EndTime = viewModel.EndTime, LeadName = viewModel.LeadName, Address = viewModel.Address }; var validationResult = _appointmentService.ValidateBook(makeBookingRequest); if (!validationResult.IsValid) { foreach (var error in validationResult.Errors) { ModelState.AddModelError(error.Field ?? "", error.Text); } return(View("BookUpdate", viewModel)); } _appointmentService.Book(makeBookingRequest); } return(RedirectToAction("Index", "Consultant", new { consultantId = viewModel.ConsultantId })); }
public async Task UpdateAppointmentAsync_NotExistingAppointmentId_ShouldThrowFactroApiException() { // Arrange await this.fixture.ClearFactroInstanceAsync(); var appointmentApi = this.fixture.GetService <IAppointmentApi>(); var updatedSubject = $"{BaseTestFixture.TestPrefix}{Guid.NewGuid().ToString()}"; var updateAppointmentRequest = new UpdateAppointmentRequest { Subject = updatedSubject, }; var updateAppointmentResponse = default(UpdateAppointmentResponse); // Act Func <Task> act = async() => updateAppointmentResponse = await appointmentApi.UpdateAppointmentAsync(Guid.NewGuid().ToString(), updateAppointmentRequest); // Assert await act.Should().ThrowAsync <FactroApiException>(); using (new AssertionScope()) { var appointments = (await appointmentApi.GetAppointmentsAsync()) .Where(x => x.Subject.StartsWith(BaseTestFixture.TestPrefix)).ToList(); appointments.All(x => x.Subject != updatedSubject).Should().BeTrue(); updateAppointmentResponse.Should().BeNull(); } await this.fixture.ClearFactroInstanceAsync(); }
public async Task UpdateAppointmentAsync_InvalidUpdate_ShouldNotUpdateAppointment() { // Arrange await this.fixture.ClearFactroInstanceAsync(); var appointmentApi = this.fixture.GetService <IAppointmentApi>(); var existingAppointment = await this.fixture.CreateTestAppointmentAsync(appointmentApi); const string updatedSubject = null; var updateAppointmentRequest = new UpdateAppointmentRequest { Subject = updatedSubject, }; // Act Func <Task> act = async() => 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.Single(x => x.Id == existingAppointment.Id).Should().BeEquivalentTo(existingAppointment); } await this.fixture.ClearFactroInstanceAsync(); }
public async Task UpdateAppointmentAsync_InvalidAppointmentId_ShouldThrowArgumentNullException(string appointmentId) { // Arrange var appointmentApi = this.fixture.GetAppointmentApi(); var updateAppointmentRequest = new UpdateAppointmentRequest(); // Act Func <Task> act = async() => await appointmentApi.UpdateAppointmentAsync(appointmentId, updateAppointmentRequest); // Assert await act.Should().ThrowAsync <ArgumentNullException>(); }
public async Task <IActionResult> Patch([FromRoute] Guid id, [FromBody] UpdateAppointmentRequest patchAppointment) { var patch = JsonPatchDocumentExtensions.CreatePatch(patchAppointment.Original, patchAppointment.Changed); var guidUserId = Guid.Parse(User.Claims.FirstOrDefault(x => x.Type == "id").Value); var patchResponse = await appointmentApi.PatchAppointment(id, guidUserId, patch.Operations); if (!patchResponse.IsSuccessStatusCode) { return(await patchResponse.UpdateActionResult()); } return(NoContent()); // Because theoretically the user on frontend already has the data changed, no point in returning a new data }
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); } }
private StringContent GetUpdatedAppointmentJson(AppointmentDto originalAppointment) { var request = new UpdateAppointmentRequest() { // requiredkeys Id = originalAppointment.AppointmentId, ScheduleId = originalAppointment.ScheduleId, // fields to update AppointmentTypeId = _testAppointmentTypeId, RoomId = _testRoomId, Title = _testTitle, DoctorId = _testDoctorId }; var jsonContent = new StringContent(JsonSerializer.Serialize(request), Encoding.UTF8, "application/json"); return(jsonContent); }
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); } }
public async Task KendoCall(string action, string jsonData) { if (action == "edit") { var result = JsonSerializer.Deserialize <AppointmentDto>(jsonData, JsonOptions); await OnEditCallback.InvokeAsync(result); } else if (action == "move") { var result = JsonSerializer.Deserialize <AppointmentDto>(jsonData, JsonOptions); await AppointmentService.EditAsync(UpdateAppointmentRequest.FromDto(result)); } else if (action == "delete") { var result = JsonSerializer.Deserialize <AppointmentDto>(jsonData, JsonOptions); await AppointmentService.DeleteAsync(result.AppointmentId); SchedulerService.Appointments.Remove(SchedulerService.Appointments.First(x => x.AppointmentId == result.AppointmentId)); CallJSMethod(); } }
public async Task UpdateAppointmentAsync_UnsuccessfulRequest_ShouldThrowAppointmentApiException() { // Arrange var appointmentId = Guid.NewGuid().ToString(); var updateAppointmentRequest = new UpdateAppointmentRequest(); var expectedResponse = new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, RequestMessage = new HttpRequestMessage { RequestUri = new Uri("http://www.mock-web-address.com"), }, }; var appointmentApi = this.fixture.GetAppointmentApi(expectedResponse); // Act Func <Task> act = async() => await appointmentApi.UpdateAppointmentAsync(appointmentId, updateAppointmentRequest); // Assert await act.Should().ThrowAsync <FactroApiException>(); }
public async Task <AppointmentDto> EditAsync(UpdateAppointmentRequest appointment) { _logger.LogInformation($"Creating new appointment for {appointment}"); return((await _httpService.HttpPutAsync <UpdateAppointmentResponse>(UpdateAppointmentRequest.Route, appointment)).Appointment); }
/// <inheritdoc/> /// <exception cref="ArgumentNullException"><paramref name="appointmentId"/> is null, empty or whitespace.</exception> public async Task <UpdateAppointmentResponse> UpdateAppointmentAsync(string appointmentId, UpdateAppointmentRequest updateAppointmentRequest) { if (string.IsNullOrWhiteSpace(appointmentId)) { throw new ArgumentNullException(nameof(appointmentId), $"{nameof(appointmentId)} can not be null, empty or whitespace."); } if (updateAppointmentRequest == null) { throw new ArgumentNullException(nameof(updateAppointmentRequest), $"{nameof(updateAppointmentRequest)} can not be null."); } var requestRoute = AppointmentApiEndpoints.Base.Update(appointmentId); var requestString = JsonConvert.SerializeObject(updateAppointmentRequest, this.jsonSerializerSettings); var requestContent = ApiHelpers.GetStringContent(requestString); var response = await this.httpClient.PutAsync(requestRoute, requestContent); if (!response.IsSuccessStatusCode) { throw new FactroApiException( $"Could not update appointment with id '{appointmentId}'.", response.RequestMessage.RequestUri.ToString(), response.StatusCode, response.Content == null ? null : await response.Content.ReadAsStringAsync()); } var responseContentString = await response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject <UpdateAppointmentResponse>( responseContentString, this.jsonSerializerSettings); return(result); }
public async Task <AppointmentDto> EditAsync(UpdateAppointmentRequest appointment) { return((await _httpService.HttpPutAsync <UpdateAppointmentResponse>("appointments", appointment)).Appointment); }