/// <summary> /// Converts appointment DAL model to appointment API model. /// </summary> /// <param name="appointment">Appointment to convert</param> /// <returns>Converted appointment</returns> private Appointment BuildAppointment(API.DAL.Models.Appointment appointment) { return(new Appointment { Id = appointment.Id, Startdate = appointment.Startdate, Enddate = appointment.Enddate, Practitioner = ApiHelper.BuildPractitionerURL(appointment.PractitionerId), Customer = ApiHelper.BuildCustomerURL(appointment.CustomerId) }); }
/// <summary> /// Creates a new Appointment /// </summary> /// <param name="appointment">The appointment that is being created</param> /// <returns>OkResult if the appointment was created successfully </returns> // POST: api/Appointment public IHttpActionResult Post([FromBody] Appointment appointment) { API.DAL.Models.Appointment c = BuildDalAppointment(appointment); try { _appointmentRepository.Create(c); } catch (DataAccessException e) { return(Content(HttpStatusCode.Conflict, e.Message)); } return(Ok()); }
public void ChooseAppointmentDay() { //Arrange var mock = new Mock <IAppointmentRepository>(); DateTime appointmentDay = new DateTime(2020, 12, 24); int practitionerIdGood = 1; List <API.DAL.Models.Appointment> takenAppointments = new List <API.DAL.Models.Appointment>(); API.DAL.Models.Appointment mockAppointment1 = new API.DAL.Models.Appointment { PractitionerId = 1, Startdate = new DateTime(2020, 12, 24, 8, 0, 0), Enddate = new DateTime(2020, 12, 24, 8, 30, 0) }; API.DAL.Models.Appointment mockAppointment2 = new API.DAL.Models.Appointment { PractitionerId = 1, Startdate = new DateTime(2020, 12, 24, 8, 30, 0), Enddate = new DateTime(2020, 12, 24, 9, 0, 0) }; takenAppointments.Add(mockAppointment1); takenAppointments.Add(mockAppointment2); mock.Setup(x => x.GetAllByPractitionerAndDate(appointmentDay, practitionerIdGood)).Returns(takenAppointments); List <API.DAL.Models.Appointment> expectedTakenAppointments = (List <API.DAL.Models.Appointment>)mock.Object.GetAllByPractitionerAndDate(appointmentDay, practitionerIdGood); var appointmentController = new AppointmentController(mock.Object); //Act var actionResult = appointmentController.Get(practitionerIdGood, appointmentDay.ToString()); var result = actionResult as OkNegotiatedContentResult <IEnumerable <API.Models.Appointment> >; IEnumerable <API.Models.Appointment> enumerableList = result.Content; List <API.Models.Appointment> allowedAppointments = enumerableList.ToList(); //Assert Assert.AreEqual((14 - expectedTakenAppointments.Count), allowedAppointments.Count); }