public void PutPatientCheckReturnPatientCheck() { IHttpActionResult result; CreatedAtRouteNegotiatedContentResult<PatientCheckModel> contentResult; OkNegotiatedContentResult<PatientCheckModel> patientCheckResult; OkNegotiatedContentResult<PatientCheckModel> readContentResult; DateTime now = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); int createdPatientID; int createdSpecialtyID; // Create a new test patient, and get its patient ID using (var patientController = new PatientsController()) { var patient = new PatientModel { FirstName = "Testpatient", LastName = "Testerson", Birthdate = new DateTime(1968, 12, 27), Email = "*****@*****.**", BloodType = "A+", CreatedDate = new DateTime(2015, 11, 10), Archived = false }; result = patientController.PostPatient(patient); CreatedAtRouteNegotiatedContentResult<PatientModel> createdContentResult = (CreatedAtRouteNegotiatedContentResult<PatientModel>)result; createdPatientID = createdContentResult.Content.PatientID; } // Create a new test specialty, and get its specialty ID using (var specialtyController = new SpecialtiesController()) { var specialty = new SpecialtyModel { SpecialtyName = "Very Special Doctor" }; result = specialtyController.PostSpecialty(specialty); CreatedAtRouteNegotiatedContentResult<SpecialtyModel> specialtyContentResult = (CreatedAtRouteNegotiatedContentResult<SpecialtyModel>)result; createdSpecialtyID = specialtyContentResult.Content.SpecialtyID; } using (var patientCheckController = new PatientChecksController()) { var newPatientCheck = new PatientCheckModel { PatientID = createdPatientID, SpecialtyID = createdSpecialtyID, CheckinDateTime = now, CheckoutDateTime = now.AddHours(2) }; result = patientCheckController.PostPatientCheck(newPatientCheck); contentResult = (CreatedAtRouteNegotiatedContentResult<PatientCheckModel>)result; } using (var SecondPatientCheckController = new PatientChecksController()) { result = SecondPatientCheckController.GetPatientCheck(contentResult.Content.PatientCheckID); Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<PatientCheckModel>)); patientCheckResult = (OkNegotiatedContentResult<PatientCheckModel>)result; } using (var ThirdPatientCheckController = new PatientChecksController()) { var modifiedPatientCheck = patientCheckResult.Content; modifiedPatientCheck.CheckoutDateTime = now; result = ThirdPatientCheckController.PutPatientCheck(patientCheckResult.Content.PatientCheckID, modifiedPatientCheck); Assert.IsInstanceOfType(result, typeof(StatusCodeResult)); } using (var FourthPatientCheckController = new PatientChecksController()) { IHttpActionResult resultAlteredPatientCheck = FourthPatientCheckController.GetPatientCheck(patientCheckResult.Content.PatientCheckID); OkNegotiatedContentResult<PatientCheckModel> alteredResult = (OkNegotiatedContentResult<PatientCheckModel>)resultAlteredPatientCheck; PatientCheckModel updatedPatientCheck = (PatientCheckModel)alteredResult.Content; Assert.IsInstanceOfType(resultAlteredPatientCheck, typeof(OkNegotiatedContentResult<PatientCheckModel>)); readContentResult = (OkNegotiatedContentResult<PatientCheckModel>)resultAlteredPatientCheck; Assert.IsTrue(readContentResult.Content.CheckoutDateTime == now); } // Delete the test patient check using (var FifthPatientCheckController = new PatientChecksController()) { result = FifthPatientCheckController.DeletePatientCheck(readContentResult.Content.PatientCheckID); } // Delete the test patient (actual deletion, not archiving) using (MedAgendaDbContext db = new MedAgendaDbContext()) { Patient dbPatient = db.Patients.Find(createdPatientID); db.Patients.Remove(dbPatient); db.SaveChanges(); } // Delete the test specialty using (var specialtyController = new SpecialtiesController()) { result = specialtyController.DeleteSpecialty(createdSpecialtyID); } }
public void DeletePatientCheck() { int createdPatientID; int createdSpecialtyID; IHttpActionResult result; CreatedAtRouteNegotiatedContentResult<PatientCheckModel> contentResult; // Create a new test patient, and get its patient ID using (var patientController = new PatientsController()) { var patient = new PatientModel { FirstName = "Testpatient", LastName = "Testerson", Birthdate = new DateTime(1968, 12, 27), Email = "*****@*****.**", BloodType = "A+", CreatedDate = new DateTime(2015, 11, 10), Archived = false }; result = patientController.PostPatient(patient); CreatedAtRouteNegotiatedContentResult<PatientModel> createdContentResult = (CreatedAtRouteNegotiatedContentResult<PatientModel>)result; createdPatientID = createdContentResult.Content.PatientID; } // Create a new test specialty, and get its specialty ID using (var specialtyController = new SpecialtiesController()) { var specialty = new SpecialtyModel { SpecialtyName = "Very Special Doctor" }; result = specialtyController.PostSpecialty(specialty); CreatedAtRouteNegotiatedContentResult<SpecialtyModel> specialtyContentResult = (CreatedAtRouteNegotiatedContentResult<SpecialtyModel>)result; createdSpecialtyID = specialtyContentResult.Content.SpecialtyID; } using (var patientCheckController = new PatientChecksController()) { var newPatientCheck = new PatientCheckModel { PatientID = createdPatientID, SpecialtyID = createdSpecialtyID, CheckinDateTime = DateTime.Now, CheckoutDateTime = DateTime.Now.AddHours(2) }; result = patientCheckController.PostPatientCheck(newPatientCheck); contentResult = (CreatedAtRouteNegotiatedContentResult<PatientCheckModel>)result; } using (var SecondPatientCheckController = new PatientChecksController()) { result = SecondPatientCheckController.DeletePatientCheck(contentResult.Content.PatientCheckID); Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<PatientCheckModel>)); } using (var ThirdPatientCheckController = new PatientChecksController()) { result = ThirdPatientCheckController.GetPatientCheck(contentResult.Content.PatientCheckID); Assert.IsInstanceOfType(result, typeof(NotFoundResult)); } // Delete the test patient (actual deletion, not archiving) using (MedAgendaDbContext db = new MedAgendaDbContext()) { Patient dbPatient = db.Patients.Find(createdPatientID); db.Patients.Remove(dbPatient); db.SaveChanges(); } // Delete the test specialty using (var specialtyController = new SpecialtiesController()) { result = specialtyController.DeleteSpecialty(createdSpecialtyID); } }