public async Task CreateAppointment_WithParameters_ShouldCreateAppointment() { 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", ClinicId = 1, FirstName = "Test", LastName = "Dentist", }; var timeStart = new DateTime(2019, 05, 05, 10, 0, 0); var timeEnd = new DateTime(2019, 05, 05, 10, 30, 0); Assert.NotNull(service.CreateAppointment(user, timeStart, timeEnd)); var result = await dbContext.Appointments.CountAsync(); Assert.Equal(1, result); }
public void GetAllPatientDentists_WithValidIdAndNoDentists_ShouldReturnEmptyDentistCollection() { 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 { PatientId = "1", DentistID = "1" }; var appointment2 = new Appointment { PatientId = "1", DentistID = "2", }; var appointment3 = new Appointment { PatientId = "1", DentistID = "2", }; var dentist1 = 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.Appointments.Add(appointment); dbContext.Appointments.Add(appointment2); dbContext.Appointments.Add(appointment3); dbContext.DentHubUsers.Add(dentist1); 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.GetAllPatientDentists("5"); Assert.Empty(result); }
public void GetAllActiveDentists_WithValidDentists_ShouldReturnDentistsCollection() { 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", IsActive = true, FirstName = "Dentist 1", LastName = "Test", SpecialtyId = 1, }; var dentist2 = new DentHubUser { Id = "2", IsActive = true, FirstName = "Dentist 2", LastName = "Test2", SpecialtyId = 2, }; var dentist3 = new DentHubUser { Id = "3", IsActive = false, FirstName = "Dentist 3", LastName = "Test3", SpecialtyId = 3, }; var dentist4 = new DentHubUser { Id = "4", IsActive = true, FirstName = "Dentist 4", LastName = "Test4", SpecialtyId = 44, }; dbContext.DentHubUsers.Add(dentist); dbContext.DentHubUsers.Add(dentist2); dbContext.DentHubUsers.Add(dentist3); dbContext.DentHubUsers.Add(dentist4); 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.GetAllActiveDentists(); Assert.Equal(new DentHubUser[] { dentist, dentist2, dentist4 }, result); }
public void GetPatientFiles_WithInvalidFiles_ShouldReturnEmptyPatientFileCollection() { 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", IsActive = true, FirstName = "Patient 1", LastName = "Test", }; var patient2 = new DentHubUser { Id = "2", IsActive = true, FirstName = "Patient 2", LastName = "Test2" }; var file1 = new PatientFile { Id = 1, PatientId = "1" }; var file2 = new PatientFile { Id = 2, PatientId = "1" }; var file3 = new PatientFile { Id = 3, PatientId = "2" }; dbContext.DentHubUsers.Add(patient); dbContext.DentHubUsers.Add(patient2); dbContext.PatientFiles.Add(file1); dbContext.PatientFiles.Add(file2); dbContext.PatientFiles.Add(file3); dbContext.SaveChanges(); var patuientFilesRepository = new DbRepository <PatientFile>(dbContext); var service = new PatientFileService(patuientFilesRepository); var result = service.GetPatientFiles("3"); Assert.Empty(result); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { var user = new DentHubUser { UserName = Input.Email, Email = Input.Email, FirstName = Input.FirstName, LastName = Input.LastName, SSN = Input.SSN, }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { var resultRole = await _userManager.AddToRoleAsync(user, "Patient"); var resultClaimRole = await _userManager.AddClaimAsync(user, new System.Security.Claims.Claim(ClaimTypes.Role, "Patient")); _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { userId = user.Id, code = code }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
public void GetAppointmentPatient_WithValidAppointmentIdAndPatient_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 appointment = new Appointment { Id = 1, PatientId = "1", DentistID = "1" }; var patient1 = new DentHubUser { Id = "1", Email = "*****@*****.**", FirstName = "Test", LastName = "LastName", IsActive = true, PhoneNumber = "1234", UserName = "******", }; var patient2 = new DentHubUser { Id = "2", Email = "*****@*****.**", FirstName = "Test2", LastName = "LastName2", IsActive = true, PhoneNumber = "123456", UserName = "******", }; dbContext.Appointments.Add(appointment); dbContext.DentHubUsers.Add(patient1); dbContext.DentHubUsers.Add(patient2); 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 PatientService(userRepository, appointmentService); var result = service.GetAppointmentPatient(1); Assert.Equal(patient1, result); }
public async Task CreateAppointment(DentHubUser user, DateTime timeStart, DateTime timeEnd) { var appointment = new Appointment { ClinicId = (int)user.ClinicId, Dentist = user, DentistID = user.Id, Status = Status.Offering, TimeStart = timeStart, TimeEnd = timeEnd, }; await this.AddAsync(appointment); await this.SaveChangesAsync(); }
public bool DuplicateOfferingExists(DentHubUser user, DateTime timeStart, DateTime timeEnd) { var offerings = GetAllDentistAppointments(user.Id) .Where(a => a.Status.ToString() == "Offering"); foreach (var offering in offerings) { if ((timeStart >= offering.TimeStart && timeStart < offering.TimeEnd) || (timeEnd > offering.TimeStart && timeEnd <= offering.TimeEnd)) { return(true); } } return(false); }
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 void GetAllActive_WithInvalidClinics_ShouldReturnEmptyClinicsCollection() { 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 = 10, IsActive = true, Name = "Clinic 1", }; var dentist = new DentHubUser { Id = "1", IsActive = false, ClinicId = 1 }; var clinic2 = new Clinic { Id = 2, IsActive = false, Name = "Clinic 2", }; var dentist2 = new DentHubUser { Id = "2", IsActive = true, ClinicId = 2 }; dbContext.Clinics.Add(clinic); dbContext.Clinics.Add(clinic2); dbContext.DentHubUsers.Add(dentist); dbContext.DentHubUsers.Add(dentist2); dbContext.SaveChanges(); var repository = new DbRepository <Clinic>(dbContext); var service = new ClinicService(repository); var result = service.GetAllActive(); Assert.Empty(result); }
private async Task LoadSharedKeyAndQrCodeUriAsync(DentHubUser user) { // Load the authenticator key & QR code URI to display on the form var unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user); if (string.IsNullOrEmpty(unformattedKey)) { await _userManager.ResetAuthenticatorKeyAsync(user); unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user); } SharedKey = FormatKey(unformattedKey); var email = await _userManager.GetEmailAsync(user); AuthenticatorUri = GenerateQrCodeUri(email, unformattedKey); }
private static void SeedDentists(DentHubContext dbContext, string[][] dentists, UserManager <DentHubUser> userManager, RoleManager <IdentityRole> roleManager) { foreach (var dentist in dentists) { var user = new DentHubUser { UserName = dentist[1], FirstName = dentist[3], LastName = dentist[4], Email = dentist[1], Clinic = dbContext.Clinics.FirstOrDefault(c => c.Name == dentist[5]), SpecialtyId = dbContext.Specialties.FirstOrDefault(s => s.Name == dentist[6]).Id }; var userResult = userManager.CreateAsync(user, dentist[2]).GetAwaiter().GetResult(); var role = roleManager.FindByNameAsync(dentist[0]).GetAwaiter().GetResult(); //if (role == null) //{ // var result = roleManager.CreateAsync(new IdentityRole(roleName)).GetAwaiter().GetResult(); // if (!result.Succeeded) // { // throw new Exception(string.Join(Environment.NewLine, result.Errors.Select(e => e.Description))); // } //} //if (user == null) //{ // var result = userManager.CreateAsync(new DentHubUser(GlobalConstants.AdminUserName)).GetAwaiter().GetResult(); // if (!result.Succeeded) // { // throw new Exception(string.Join(Environment.NewLine, result.Errors.Select(e => e.Description))); // } //} if (userResult.Succeeded) { var resultRole = userManager.AddToRoleAsync(user, role.Name).GetAwaiter().GetResult(); var resultClaimRole = userManager.AddClaimAsync(user, new System.Security.Claims.Claim(ClaimTypes.Role, "Dentist")).GetAwaiter().GetResult(); } } }
private static void SeedPatients(DentHubContext dbContext, string[][] patients, UserManager <DentHubUser> userManager, RoleManager <IdentityRole> roleManager) { foreach (var patient in patients) { var user = new DentHubUser { UserName = patient[1], FirstName = patient[3], LastName = patient[4], Email = patient[1], SSN = patient[5], }; var userResult = userManager.CreateAsync(user, patient[2]).GetAwaiter().GetResult(); var role = roleManager.FindByNameAsync(patient[0]).GetAwaiter().GetResult(); //if (role == null) //{ // var result = roleManager.CreateAsync(new IdentityRole(roleName)).GetAwaiter().GetResult(); // if (!result.Succeeded) // { // throw new Exception(string.Join(Environment.NewLine, result.Errors.Select(e => e.Description))); // } //} //if (user == null) //{ // var result = userManager.CreateAsync(new DentHubUser(GlobalConstants.AdminUserName)).GetAwaiter().GetResult(); // if (!result.Succeeded) // { // throw new Exception(string.Join(Environment.NewLine, result.Errors.Select(e => e.Description))); // } //} if (userResult.Succeeded) { var resultRole = userManager.AddToRoleAsync(user, role.Name).GetAwaiter().GetResult(); var resultClaimRole = userManager.AddClaimAsync(user, new System.Security.Claims.Claim(ClaimTypes.Role, "Patient")).GetAwaiter().GetResult(); } } }
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 <IActionResult> OnPostConfirmationAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); // Get the information about the user from the external login provider var info = await _signInManager.GetExternalLoginInfoAsync(); if (info == null) { ErrorMessage = "Error loading external login information during confirmation."; return(RedirectToPage("./Login", new { ReturnUrl = returnUrl })); } if (ModelState.IsValid) { var user = new DentHubUser { UserName = Input.Email, Email = Input.Email }; var result = await _userManager.CreateAsync(user); if (result.Succeeded) { result = await _userManager.AddLoginAsync(user, info); if (result.Succeeded) { await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider); return(LocalRedirect(returnUrl)); } } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } LoginProvider = info.LoginProvider; ReturnUrl = returnUrl; return(Page()); }
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 async Task BookAppointmentAsync(int id, DentHubUser user) { var appointment = GetAppointmentById(id); appointment.Patient = user; appointment.Status = Status.Booked; var ratingRecord = new Rating { Appointment = appointment, DentistId = appointment.DentistID, PatientId = appointment.PatientId, }; await this._ratingRepository.AddAsync(ratingRecord); await this._ratingRepository.SaveChangesAsync(); this.Update(appointment); await this.SaveChangesAsync(); }
public void DuplicateOfferingExists_WithNoDuplicates_ShouldReturnFalse() { 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 = "2", FirstName = "Test2", LastName = "Dentist", }; var appointment = new Appointment { Id = 31, ClinicId = 1, DentistID = "2", TimeStart = new DateTime(2019, 05, 05, 10, 0, 0), TimeEnd = new DateTime(2019, 05, 05, 10, 30, 0), Status = Status.Offering, }; dbContext.Appointments.Add(appointment); dbContext.DentHubUsers.Add(user); dbContext.SaveChanges(); var timeStart = new DateTime(2019, 05, 05, 10, 30, 0); var timeEnd = new DateTime(2019, 05, 05, 11, 00, 0); var result = service.DuplicateOfferingExists (user, timeStart, timeEnd); Assert.False(result); }
public void GetAllActiveDentists_WithInvalidDentists_ShouldReturnEmptyDentistsCollection() { 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", IsActive = false, FirstName = "Patient 1", LastName = "Test", SSN = "123" }; var patient2 = new DentHubUser { Id = "2", IsActive = true, FirstName = "Dentist 2", LastName = "Test2", SSN = null, }; dbContext.DentHubUsers.Add(patient); dbContext.DentHubUsers.Add(patient2); 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 PatientService(userRepository, appointmentService); var result = service.GetAllActivePatients(); Assert.Empty(result); }
private static void SeedAdmin(string userName, string roleName, UserManager <DentHubUser> userManager, RoleManager <IdentityRole> roleManager) { var user = new DentHubUser { UserName = GlobalConstants.AdminUserName, FirstName = GlobalConstants.AdminUserName, Email = GlobalConstants.AdminUserName, }; var userResult = userManager.CreateAsync(user, GlobalConstants.AdminPassword).GetAwaiter().GetResult(); var role = roleManager.FindByNameAsync(roleName).GetAwaiter().GetResult(); if (role == null) { var result = roleManager.CreateAsync(new IdentityRole(roleName)).GetAwaiter().GetResult(); if (!result.Succeeded) { throw new Exception(string.Join(Environment.NewLine, result.Errors.Select(e => e.Description))); } } if (user == null) { var result = userManager.CreateAsync(new DentHubUser(GlobalConstants.AdminUserName)).GetAwaiter().GetResult(); if (!result.Succeeded) { throw new Exception(string.Join(Environment.NewLine, result.Errors.Select(e => e.Description))); } } if (userResult.Succeeded) { var resultRole = userManager.AddToRoleAsync(user, role.Name).GetAwaiter().GetResult(); var resultClaimRole = userManager.AddClaimAsync(user, new System.Security.Claims.Claim(ClaimTypes.Role, "Administrator")).GetAwaiter().GetResult(); } }
public async Task <IActionResult> PatientFiles(string id) { var user = await this._userManager.GetUserAsync(User); DentHubUser patient = null; if (User.IsInRole("Patient")) { patient = this._patientService .GetPatientById(user.Id); } else { patient = this._patientService .GetPatientById(id); } var patientFiles = new FilesViewModel { PatientId = patient.Id, PatientName = this._patientService.GetPatientFullName(patient.Id), Files = this._patientFileService .GetPatientFiles(patient.Id) .Select(f => new FileInputModel { Id = f.Id, DateCreated = f.DateCreated, FileType = f.FileType.ToString(), Description = f.Description, Name = f.Name, PatientId = patient.Id, }).ToArray() }; return(View("PatientFiles", patientFiles)); }
public void Update(DentHubUser patient) { this._userRepository.Update(patient); }
public void GetAllDentistPatients_WithInvalidPatients_ShouldReturnEmptyPatientsCollection() { 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 = "10", IsActive = true, FirstName = "Patient 1", LastName = "Test", }; var patient2 = new DentHubUser { Id = "11", IsActive = false, FirstName = "Patient 2", LastName = "Test", }; var dentist = new DentHubUser { Id = "13", ClinicId = 14, IsActive = false, FirstName = "Dentist", LastName = "Test", SpecialtyId = 3, }; var appointment1 = new Appointment { Id = 1, PatientId = "11", DentistID = "14", }; var appointment2 = new Appointment { Id = 2, PatientId = "12", DentistID = "15", }; var appointment3 = new Appointment { Id = 3, PatientId = "11", DentistID = "16", }; dbContext.DentHubUsers.Add(dentist); dbContext.DentHubUsers.Add(patient); dbContext.DentHubUsers.Add(patient2); dbContext.Appointments.Add(appointment1); dbContext.Appointments.Add(appointment2); dbContext.Appointments.Add(appointment3); 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 PatientService(userRepository, appointmentService); var result = service.GetAllDentistPatients("13"); Assert.Empty(result); }
public void Update(DentHubUser dentist) { this._userRepository.Update(dentist); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { var clinic = this._clinicRepository .All() .FirstOrDefault(c => c.Id == int.Parse(Input.Clinic)); var specialty = this._specialtyRepository .All() .FirstOrDefault(s => s.Id == int.Parse(Input.Specialty)); var files = HttpContext.Request.Form.Files.ToList(); var cloudinaryUris = await this._cloudinaryService.UploadFilesAsync(files); var user = new DentHubUser { UserName = Input.Email, Email = Input.Email, FirstName = Input.FirstName, LastName = Input.LastName, ClinicId = clinic.Id, SpecialtyId = specialty.Id, ImageUrl = cloudinaryUris.FirstOrDefault() }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { var resultRole = await _userManager.AddToRoleAsync(user, "Dentist"); var resultClaimRole = await _userManager.AddClaimAsync(user, new System.Security.Claims.Claim(ClaimTypes.Role, "Dentist")); _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { userId = user.Id, code = code }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }