public static void AddPatientToDatabase(string firstName, string lastName, params DateTime[] appointmentDate) { PatientEntity patient = new PatientEntity { FirstName = firstName, LastName = lastName }; foreach (DateTime item in appointmentDate) { var appointment = new AppointmentEntity { Date = item }; patient.AddAppointment(appointment); } ISessionFactory sessionForTests = NHibernateConfig.CreateSessionFactory(Database.TEST_DB_NAME); using (ISession session = sessionForTests.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { session.SaveOrUpdate(patient); transaction.Commit(); } } }
public void Add_additional_appointment_to_a_patient() { // Arrange string firstName = "Type O Negative"; string lastName = "Carnivore"; DateTime newerAppointmentDate = DateTime.Now; DateTime olderAppointmentDate = DateTime.Now - TimeSpan.FromDays(7); DatabaseTools.AddPatientToDatabase(firstName, lastName, newerAppointmentDate); IEnumerable <PatientEntity> patients = _patientDal.GetAllPatients(); PatientEntity patient = patients.First(x => x.FirstName == firstName); // Act patient.AddAppointment(new AppointmentEntity { Date = olderAppointmentDate }); _patientDal.SaveOrUpdatePatient(patient); // Assert IList <AppointmentEntity> appointments = DatabaseTools.GetAllAppointments(); appointments.OrderBy(x => x.Date); Assert.That(appointments.Count, Is.EqualTo(2)); Assert.AreEqual(appointments.First().Date.Date, olderAppointmentDate.Date); Assert.AreEqual(appointments.Last().Date.Date, newerAppointmentDate.Date); Assert.AreEqual(appointments.First().Patient.Id, appointments.Last().Patient.Id); }
public void Add_appointment_to_a_patient() { // Arrange string firstName = "Type O Negative"; string lastName = "Carnivore"; DateTime appointmentDate = DateTime.Now; string interview = "The patient is quite ill right now"; DatabaseTools.AddPatientToDatabase(firstName, lastName); IEnumerable <PatientEntity> patients = _patientDal.GetAllPatients(); PatientEntity patient = patients.First(x => x.FirstName == firstName); // Act patient.AddAppointment(new AppointmentEntity { Date = appointmentDate, Interview = interview }); _patientDal.SaveOrUpdatePatient(patient); // Assert IList <AppointmentEntity> appointments = DatabaseTools.GetAllAppointments(); Assert.That(appointments.Count, Is.EqualTo(1)); AppointmentEntity resultAppointment = appointments.First(); Assert.AreEqual(resultAppointment.Date.Date, appointmentDate.Date); StringAssert.Contains(interview, resultAppointment.Interview); Assert.AreEqual(resultAppointment.Patient.Id, appointments.Last().Patient.Id); }
public void AddAppointmentToPatient(Guid patientId, Appointment appointment) { PatientEntity patientEntity = _patientDal.GetPatientById(patientId); var appointmentEntity = Mapper.Map <AppointmentEntity>(appointment); patientEntity.AddAppointment(appointmentEntity); _patientDal.SaveOrUpdatePatient(patientEntity); InvokePatientChanged(patientId); }
public void Add_patient_to_database() { // Arrange string firstName = "Peter"; string lastName = "Steele"; string pesel = "62010417694"; DateTime appointmentDate = DateTime.Now; // Act var patient = new PatientEntity { FirstName = firstName, LastName = lastName, Pesel = pesel }; patient.AddAppointment(new AppointmentEntity { Date = appointmentDate }); _patientDal.SaveOrUpdatePatient(patient); IList <PatientEntity> query = DatabaseTools.GetPatientFromDatabase(firstName, lastName); // Assert Assert.IsNotNull(query); Assert.IsNotEmpty(query); Assert.IsTrue(query.Count == 1); PatientEntity result = query.First(); StringAssert.Contains(result.FirstName, firstName); StringAssert.Contains(result.LastName, lastName); ICollection <AppointmentEntity> appointments = result.Appointments; Assert.IsNotEmpty(appointments); Assert.IsTrue(appointments.Count == 1); Assert.That(result.Pesel, Is.EqualTo(pesel)); }