public async Task GetClinicById_WithInvalidId_ShouldReturnException() { var options = new DbContextOptionsBuilder <DentHubContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) // Give a Unique name to the DB .Options; var dbContext = new DentHubContext(options); var clinic = new Clinic { Id = 20, Name = "Clinic 20" }; var clinic2 = new Clinic { Id = 21, Name = "Clinic 21" }; dbContext.Clinics.Add(clinic); dbContext.Clinics.Add(clinic2); await dbContext.SaveChangesAsync(); var repository = new DbRepository <Clinic>(dbContext); var service = new ClinicService(repository); Assert.Throws <ArgumentException>(() => service.GetClinicById(22)); }
public async Task GetAppointmentById_WithInvalidId_ShouldReturnException() { var options = new DbContextOptionsBuilder <DentHubContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) // Give a Unique name to the DB .Options; var dbContext = new DentHubContext(options); var appointment = new Appointment { Id = 7, ClinicId = 1, DentistID = "2", PatientId = "3", Status = Status.Booked }; var appointment2 = new Appointment { Id = 8, ClinicId = 1, DentistID = "2", PatientId = "3", Status = Status.Booked }; dbContext.Appointments.Add(appointment); dbContext.Appointments.Add(appointment2); await dbContext.SaveChangesAsync(); var repository = new DbRepository <Appointment>(dbContext); var ratingRepository = new DbRepository <Rating>(dbContext); var service = new AppointmentService(repository, ratingRepository); Assert.Throws <ArgumentException>(() => service.GetAppointmentById(9)); }
public async Task BookAppointmentAsync_WithValidId_ShouldMakeAppointmentStatusBooked() { var options = new DbContextOptionsBuilder <DentHubContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) // Give a Unique name to the DB .Options; var dbContext = new DentHubContext(options); var repository = new DbRepository <Appointment>(dbContext); var ratingRepository = new DbRepository <Rating>(dbContext); var service = new AppointmentService(repository, ratingRepository); var user = new DentHubUser() { Id = "1", SSN = "123456", FirstName = "Test", LastName = "Patient", }; var appointment = new Appointment { Id = 20, ClinicId = 1, DentistID = "1", PatientId = null, Status = Status.Offering, }; dbContext.Appointments.Add(appointment); dbContext.DentHubUsers.Add(user); await dbContext.SaveChangesAsync(); await service .BookAppointmentAsync(20, user); var result = dbContext.Appointments .FirstOrDefaultAsync(a => a.Id == 20) .GetAwaiter() .GetResult(); Assert.Equal("Booked", result .Status .ToString()); Assert.Equal("1", result .PatientId); }
public async Task GetAllPatientAppointments_WithValidId_ShouldReturnAppointments() { var options = new DbContextOptionsBuilder <DentHubContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) // Give a Unique name to the DB .Options; var dbContext = new DentHubContext(options); var appointment = new Appointment { Id = 11, ClinicId = 1, DentistID = "1", PatientId = "1", Status = Status.Booked }; var appointment2 = new Appointment { Id = 12, ClinicId = 1, DentistID = "2", PatientId = "1", Status = Status.Booked }; var appointment3 = new Appointment { Id = 13, ClinicId = 1, DentistID = "2", PatientId = "2", Status = Status.Booked }; dbContext.Appointments.Add(appointment); dbContext.Appointments.Add(appointment2); dbContext.Appointments.Add(appointment3); await dbContext.SaveChangesAsync(); var repository = new DbRepository <Appointment>(dbContext); var ratingRepository = new DbRepository <Rating>(dbContext); var service = new AppointmentService(repository, ratingRepository); var result = service.GetAllPatientAppointments("1"); Assert.Equal(new Appointment[] { appointment, appointment2 }, result); }
public async Task GetPatientById_WithValidId_ShouldReturnPatient() { var options = new DbContextOptionsBuilder <DentHubContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) // Give a Unique name to the DB .Options; var dbContext = new DentHubContext(options); var patient = new DentHubUser { Id = "1", SSN = "123456", Email = "*****@*****.**", FirstName = "Test", LastName = "LastName", IsActive = true, PhoneNumber = "1234", UserName = "******", }; var patient2 = new DentHubUser { Id = "2", SSN = "1234567", Email = "*****@*****.**", FirstName = "Test2", LastName = "LastName2", IsActive = true, PhoneNumber = "123456", UserName = "******", }; dbContext.DentHubUsers.Add(patient); dbContext.DentHubUsers.Add(patient2); await dbContext.SaveChangesAsync(); var userRepository = new DbRepository <DentHubUser>(dbContext); var appointmentRepository = new DbRepository <Appointment>(dbContext); var ratingRepository = new DbRepository <Rating>(dbContext); var appointmentService = new AppointmentService(appointmentRepository, ratingRepository); var service = new PatientService(userRepository, appointmentService); var result = service.GetPatientById("2"); Assert.Same(patient2, result); }
public async Task GetPatientById_WithValidIdAndNoSSN_ShouldReturnException() { var options = new DbContextOptionsBuilder <DentHubContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) // Give a Unique name to the DB .Options; var dbContext = new DentHubContext(options); var patient5 = new DentHubUser { Id = "5", SSN = "123456", Email = "*****@*****.**", FirstName = "Test5", LastName = "LastName5", IsActive = false, PhoneNumber = "1234", UserName = "******", }; var patient6 = new DentHubUser { Id = "6", SSN = null, Email = "*****@*****.**", FirstName = "Test6", LastName = "LastName6", IsActive = true, PhoneNumber = "123456", UserName = "******", }; dbContext.DentHubUsers.Add(patient5); dbContext.DentHubUsers.Add(patient6); await dbContext.SaveChangesAsync(); var userRepository = new DbRepository <DentHubUser>(dbContext); var appointmentRepository = new DbRepository <Appointment>(dbContext); var ratingRepository = new DbRepository <Rating>(dbContext); var appointmentService = new AppointmentService(appointmentRepository, ratingRepository); var service = new PatientService(userRepository, appointmentService); Assert.Throws <ArgumentException>(() => service.GetPatientById("6")); }
public async Task GetDentistById_WithValidIdAndNoSpecialty_ShouldReturnException() { var options = new DbContextOptionsBuilder <DentHubContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) // Give a Unique name to the DB .Options; var dbContext = new DentHubContext(options); var dentist = new DentHubUser { Id = "20", SpecialtyId = 1, Email = "*****@*****.**", FirstName = "Test", LastName = "LastName", IsActive = false, PhoneNumber = "1234", UserName = "******", }; var dentist2 = new DentHubUser { Id = "21", Specialty = null, Email = "*****@*****.**", FirstName = "Test2", LastName = "LastName2", IsActive = true, PhoneNumber = "123456", UserName = "******", }; dbContext.DentHubUsers.Add(dentist); dbContext.DentHubUsers.Add(dentist2); await dbContext.SaveChangesAsync(); var userRepository = new DbRepository <DentHubUser>(dbContext); var appointmentRepository = new DbRepository <Appointment>(dbContext); var ratingRepository = new DbRepository <Rating>(dbContext); var appointmentService = new AppointmentService(appointmentRepository, ratingRepository); var service = new DentistService(userRepository, appointmentService); Assert.Throws <ArgumentException>(() => service.GetDentistById("21")); }
public Task <int> SaveChangesAsync() { return(context.SaveChangesAsync()); }