public async Task ShouldCreateAppointment() { var body = new CreateAppointments() { assignmentDate = DateTime.Now.AddDays(1).ToShortDateString(), patientId = 11, doctorId = 3 }; var appointmentController = new AppointmentsController(new Services.AppointmentServices()) { Request = new HttpRequestMessage { Method = HttpMethod.Post, Content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json"), RequestUri = new Uri($"{url}") } }; appointmentController.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); var response = appointmentController.createAppointment(body); var result = await response.ExecuteAsync(new System.Threading.CancellationToken()); Assert.AreEqual(result.StatusCode, HttpStatusCode.OK); }
public IHttpActionResult createAppointment([FromBody] CreateAppointments entity) { try { if (entity == null) { ModelState.AddModelError("Entity", "First set the entity"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } appointmentsServices.createAppointment(Convert.ToDateTime(entity.assignmentDate), entity.patientId, entity.doctorId); return(Ok()); } catch (Exception e) { return(InternalServerError(e)); } }