public void GetPatientById_WithEmptyPatientSet_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 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("7")); }
public void GetDentistById_WithValidId_ShouldReturnDentist() { 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 = "1", SpecialtyId = 1, Email = "*****@*****.**", FirstName = "Test", LastName = "LastName", IsActive = true, PhoneNumber = "1234", UserName = "******", }; var dentist2 = new DentHubUser { Id = "2", SpecialtyId = 2, Email = "*****@*****.**", FirstName = "Test2", LastName = "LastName2", IsActive = true, PhoneNumber = "123456", UserName = "******", }; dbContext.DentHubUsers.Add(dentist); dbContext.DentHubUsers.Add(dentist2); dbContext.SaveChanges(); 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); var result = service.GetDentistById("2"); Assert.Same(dentist2, result); }
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")); }