public void TestCreateNewAppointmentInThePast() { Appointment appt = new Appointment(); try { appt.StartTime = DateTime.Now.AddDays(-1); appt.EndTime = DateTime.Now.AddDays(-1).AddMinutes(15); appt.FirstName = "John"; appt.LastName = "Doe"; appt.Comments = "Appointment Created"; bool result = AppointmentSchedulingServices.AddAppointment(appt); } catch (InvalidRangeException) { Assert.IsTrue(true, "Cannot create appointments in the past."); } catch (AssertFailedException) { throw; } catch (Exception ex) { Assert.Fail("Exception thrown --> " + ex.ToString()); } }
public void TestUpperOverlapOnAddAppointment() { Appointment appt = new Appointment(); try { List <Appointment> apptList = AppointmentSchedulingServices.GetAllAppointments(); if (apptList != null && apptList.Count > 0) { appt = apptList[apptList.Count - 1]; appt.StartTime = appt.StartTime.Value.AddMinutes(15); appt.EndTime = appt.EndTime.AddMinutes(15); bool result = AppointmentSchedulingServices.AddAppointment(appt); } else { Assert.Fail("Appointment List was Empty"); } } catch (AssertFailedException) { throw; } catch (InvalidRangeException) { Assert.IsTrue(true, "Invalid range expected."); } catch (Exception ex) { Assert.Fail("Exception thrown --> " + ex.ToString()); } }
/// <summary> /// The AddAppointment operation maps to HTTP PUT method for creating new appointments. /// </summary> /// <param name="appointment">The new appointment object</param> /// <returns>Success flag and Error message</returns> public ApiResponse AddAppointment(AppointmentContract appointment) { Appointment appt; bool success = false; ApiResponse response = new ApiResponse(); try { if (!(String.IsNullOrEmpty(appointment.FirstName) || String.IsNullOrEmpty(appointment.LastName) || String.IsNullOrEmpty(appointment.StartTime) || String.IsNullOrEmpty(appointment.EndTime))) { appt = AppointmentSvc.getAppointmentModelType(appointment); if ((appt.StartTime > DateTime.Now) && (appt.StartTime <= appt.EndTime)) { success = AppointmentSchedulingServices.AddAppointment(appt); } else { response.ErrorMessage = "Please select a date in the future."; } } } catch (Exception e) { response.ErrorMessage = "Error creating appointment --> " + e.Message.ToString(); } finally { response.Success = success.ToString(); } return(response); }