public async Task <EditPatientViewModel> GetPatient(string email) { var user = new EClinicUser(); if (String.IsNullOrEmpty(email)) { throw new ArgumentException("email is Null"); } try { user = this.db.Users.FirstOrDefault(x => x.Email == email && x.IsDeleted == false); } catch (Exception e) { throw new ArgumentException("email is Null"); } var exams = await this.examService.GetAllExamForPatient(email); var userToReturnn = new EditPatientViewModel() { Address = user.Address, Age = user.Age, CreatedOn = user.CreatedOn, FirstName = user.FirstName, MiddleName = user.MiddleName, LastName = user.LastName, ImageUrl = user.ImageUrl, Email = user.Email, Exams = exams }; return(userToReturnn); }
public async void ShowLastAppointmentForUserShoulThrowExeption() { //Arrange var options = new DbContextOptionsBuilder <EClinicDbContext>() .UseInMemoryDatabase(databaseName: "Appointment_CreateAppointment") .Options; var dbContext = new EClinicDbContext(options); var appointmentService = new Mock <AppointmentService>(dbContext).Object; AutoMapperConfig.RegisterMappings(typeof(SetingViewModel).GetTypeInfo().Assembly); var mockUserStore = new Mock <IUserStore <EClinicUser> >(); var userManager = new UserManager <EClinicUser>(mockUserStore.Object, null, null, null, null, null, null, null, null); var AdminUserToAdd = new EClinicUser { Email = "*****@*****.**", FirstName = "Ivo", MiddleName = "Peshov", LastName = "Petrov", UserName = "******", NormalizedEmail = "*****@*****.**", NormalizedUserName = "******", Address = "Nqkyde Tam 35", Age = 25, SecurityStamp = Guid.NewGuid().ToString(), CreatedOn = DateTime.UtcNow, }; var userToAdd = new EClinicUser { Email = "*****@*****.**", FirstName = "Petyr", MiddleName = "Peshov", LastName = "Petrov", UserName = "******", NormalizedEmail = "*****@*****.**", NormalizedUserName = "******", Address = "I tuk i tam", Age = 30, SecurityStamp = Guid.NewGuid().ToString(), CreatedOn = DateTime.UtcNow, }; dbContext.Users.Add(AdminUserToAdd); dbContext.Users.Add(userToAdd); dbContext.SaveChanges(); var date = new DateTime(2019, 08, 03, 09, 00, 00); await appointmentService.CreateAppointment("*****@*****.**", "*****@*****.**", date); dbContext.Appointments.Where(x => true).ToList(); await Assert.ThrowsAsync <ArgumentException>(async() => await appointmentService.ShowLastAppointmentForUser("")); }
public async Task <bool> DeleteUser(string email) { var user = new EClinicUser(); if (String.IsNullOrWhiteSpace(email)) { throw new ArgumentException("Delete User needs valid email"); } try { user = await this.db.Users.FirstOrDefaultAsync(x => x.Email == email); } catch (Exception e) { throw new ArgumentException("Delete User needs valid email"); } if (user == null) { return(false); } user.IsDeleted = true; user.DeletedOn = DateTime.UtcNow; await this.db.SaveChangesAsync(); return(true); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { var isRoot = _userManager.Users.Any(); var user = new EClinicUser { UserName = Input.Email, Address = Input.Address, Age = Input.Age, CreatedOn = DateTime.UtcNow, FirstName = Input.FirstName, MiddleName = Input.MiddleName, LastName = Input.LastName, Email = Input.Email }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { if (!isRoot) { await _userManager.AddToRoleAsync(user, GlobalConstants.AdministratorRoleName); } else { await _userManager.AddToRoleAsync(user, GlobalConstants.UserRoleName); } #region Email sender //_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>."); #endregion 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 async Task <bool> EditUser(EditUserViewModel viewModel) { EClinicUser user = new EClinicUser(); try { user = this.db.Users.First(x => x.Email == viewModel.Email); } catch (Exception e) { throw new ArgumentException("Edit user model is mising Email"); } if (user == null) { return(false); } var rolesToChange = viewModel.UserRoles; var allRoles = this.db.Roles.Select(x => x.Name).ToList(); foreach (var role in allRoles) { if (viewModel.UserRoles.Contains(role)) { if (!await this.userManager.IsInRoleAsync(user, role)) { await this.userManager.AddToRoleAsync(user, role); } } else { if (user.Email != "*****@*****.**" && role != "Administrator") { await this.userManager.RemoveFromRoleAsync(user, role); } } } user.FirstName = viewModel.FirstName; user.MiddleName = viewModel.MiddleName; user.LastName = viewModel.LastName; user.Address = viewModel.Address; user.Age = viewModel.Age; user.ModifiedOn = DateTime.UtcNow; var changesCount = this.db.SaveChanges(); if (changesCount > 0) { return(true); } return(false); }
public async Task <bool> EditPatient(EditPatientViewModel viewModel) { EClinicUser user = new EClinicUser(); try { user = this.db.Users.First(x => x.Email == viewModel.Email); } catch (Exception e) { throw new ArgumentException("Edit user model is mising Email"); } if (user == null) { return(false); } user.FirstName = viewModel.FirstName; user.MiddleName = viewModel.MiddleName; user.LastName = viewModel.LastName; user.Address = viewModel.Address; user.Age = viewModel.Age; user.ModifiedOn = DateTime.UtcNow; user.ImageUrl = viewModel.ImageUrl;; var changesCount = this.db.SaveChanges(); if (changesCount > 0) { return(true); } return(false); }
public async void GetUserWhitEmptyModelShoulThrowExeption() { var options = new DbContextOptionsBuilder <EClinicDbContext>() .UseInMemoryDatabase(databaseName: "Appointment_CreateAppointment") .Options; var dbContext = new EClinicDbContext(options); //var mockUserStore = new Mock<IUserStore<EClinicUser>>(); //var mockRoleManager = new Mock<IUserRoleStore<EClinicUser>>(); //var userManager = new UserManager<EClinicUser>(mockUserStore.Object, null, null, null, null, null, null, null, null); var userManager = MockHelpers.MockUserManager <EClinicUser>().Object; var examService = new Mock <ExamService>(dbContext).Object; var appointmentService = new Mock <AppointmentService>(dbContext).Object; var usersService = new Mock <UsersService>(dbContext, userManager, examService).Object; AutoMapperConfig.RegisterMappings(typeof(SetingViewModel).GetTypeInfo().Assembly); var AdminUserToAdd = new EClinicUser { Email = "*****@*****.**", FirstName = "Ivo", MiddleName = "Peshov", LastName = "Petrov", UserName = "******", NormalizedEmail = "*****@*****.**", NormalizedUserName = "******", Address = "Nqkyde Tam 35", Age = 25, SecurityStamp = Guid.NewGuid().ToString(), CreatedOn = DateTime.UtcNow, }; var userToAdd = new EClinicUser { Email = "*****@*****.**", FirstName = "Petyr", MiddleName = "Peshov", LastName = "Petrov", UserName = "******", NormalizedEmail = "*****@*****.**", NormalizedUserName = "******", Address = "I tuk i tam", Age = 30, SecurityStamp = Guid.NewGuid().ToString(), CreatedOn = DateTime.UtcNow, }; dbContext.Users.Add(AdminUserToAdd); dbContext.Users.Add(userToAdd); dbContext.SaveChanges(); var date = new DateTime(2019, 08, 03, 09, 00, 00); await appointmentService.CreateAppointment("*****@*****.**", "*****@*****.**", date); var exam = new CreateExamInputModel() { Condition = "good", DoctorUserName = "******", Diagnose = "adss", PatientUserName = "******", Prescription = "sdfsdd" }; await examService.CreateExam(exam); dbContext.Appointments.Where(x => true).ToList(); await Assert.ThrowsAsync <ArgumentException>(async() => await usersService.GetUser("")); }
public async void CreateAppointmentForUnexistingUserAndDoctorShouldReturnTrue() { //Arrange var options = new DbContextOptionsBuilder <EClinicDbContext>() .UseInMemoryDatabase(databaseName: "Appointment_CreateAppointment") .Options; var dbContext = new EClinicDbContext(options); var appointmentService = new AppointmentService(dbContext); //var usrManager = MockHelpers.MockUserManager<EClinicUser>(); var mockUserStore = new Mock <IUserStore <EClinicUser> >(); var userManager = new UserManager <EClinicUser>(mockUserStore.Object, null, null, null, null, null, null, null, null); //userManager.UserValidators.Add(new UserValidator<EClinicUser>()); //userManager.PasswordValidators.Add(new PasswordValidator<EClinicUser>()); var AdminUserToAdd = new EClinicUser { Email = "*****@*****.**", FirstName = "Ivo", MiddleName = "Peshov", LastName = "Petrov", UserName = "******", NormalizedEmail = "*****@*****.**", NormalizedUserName = "******", Address = "Nqkyde Tam 35", Age = 25, SecurityStamp = Guid.NewGuid().ToString(), CreatedOn = DateTime.UtcNow, }; var userToAdd = new EClinicUser { Email = "*****@*****.**", FirstName = "Petyr", MiddleName = "Peshov", LastName = "Petrov", UserName = "******", NormalizedEmail = "*****@*****.**", NormalizedUserName = "******", Address = "I tuk i tam", Age = 30, SecurityStamp = Guid.NewGuid().ToString(), CreatedOn = DateTime.UtcNow, }; //await userManager.CreateAsync(AdminUserToAdd); //await userManager.CreateAsync(userToAdd); dbContext.Users.Add(AdminUserToAdd); dbContext.Users.Add(userToAdd); dbContext.SaveChanges(); int count = dbContext.Users.Count(); var result = await appointmentService.CreateAppointment("*****@*****.**", "*****@*****.**", new DateTime(2019, 08, 03, 09, 00, 00)); Assert.True(result); }
public async void GetAllAppointsmentDatesForDoctorForDayShoulReturnOne() { //Arrange var options = new DbContextOptionsBuilder <EClinicDbContext>() .UseInMemoryDatabase(databaseName: "Appointment_CreateAppointment") .Options; var dbContext = new EClinicDbContext(options); var appointmentService = new Mock <AppointmentService>(dbContext).Object; AutoMapperConfig.RegisterMappings(typeof(SetingViewModel).GetTypeInfo().Assembly); var mockUserStore = new Mock <IUserStore <EClinicUser> >(); var userManager = new UserManager <EClinicUser>(mockUserStore.Object, null, null, null, null, null, null, null, null); var AdminUserToAdd = new EClinicUser { Email = "*****@*****.**", FirstName = "Ivo", MiddleName = "Peshov", LastName = "Petrov", UserName = "******", NormalizedEmail = "*****@*****.**", NormalizedUserName = "******", Address = "Nqkyde Tam 35", Age = 25, SecurityStamp = Guid.NewGuid().ToString(), CreatedOn = DateTime.UtcNow, }; var userToAdd = new EClinicUser { Email = "*****@*****.**", FirstName = "Petyr", MiddleName = "Peshov", LastName = "Petrov", UserName = "******", NormalizedEmail = "*****@*****.**", NormalizedUserName = "******", Address = "I tuk i tam", Age = 30, SecurityStamp = Guid.NewGuid().ToString(), CreatedOn = DateTime.UtcNow, }; dbContext.Users.Add(AdminUserToAdd); dbContext.Users.Add(userToAdd); dbContext.SaveChanges(); var date = new DateTime(2019, 08, 03, 09, 00, 00); await appointmentService.CreateAppointment("*****@*****.**", "*****@*****.**", date); dbContext.Appointments.Where(x => true).ToList(); //Act var result = await appointmentService.GetAllAppointsmentDatesForDoctorForDay(userToAdd.UserName, date); var actual = dbContext.Appointments.Where(x => x.DoctorId == dbContext.Users.FirstOrDefault(d => d.Email == "*****@*****.**").Id).ToList(); //Assert Assert.Equal(actual.Count(), result.Count()); }
public async Task SeedAsync(EClinicDbContext dbContext, IServiceProvider serviceProvider) { if (dbContext == null) { throw new ArgumentNullException(nameof(dbContext)); } if (serviceProvider == null) { throw new ArgumentNullException(nameof(serviceProvider)); } var logger = serviceProvider.GetService <ILoggerFactory>().CreateLogger(typeof(SiteDbContextSeeder)); var userStore = serviceProvider.GetService <UserManager <EClinicUser> >(); var seeders = new List <ISeeder> { new SiteSeeder(), }; foreach (var seeder in seeders) { await seeder.SeedAsync(dbContext, serviceProvider); await dbContext.SaveChangesAsync(); logger.LogInformation($"Seeder {seeder.GetType().Name} done."); } var AdminUserToAdd = new EClinicUser { Email = "*****@*****.**", FirstName = "Ivo", MiddleName = "Peshov", LastName = "Petrov", UserName = "******", NormalizedEmail = "*****@*****.**", NormalizedUserName = "******", Address = "Nqkyde Tam 35", Age = 25, SecurityStamp = Guid.NewGuid().ToString(), CreatedOn = DateTime.UtcNow, }; var userToAdd = new EClinicUser { Email = "*****@*****.**", FirstName = "Petyr", MiddleName = "Peshov", LastName = "Petrov", UserName = "******", NormalizedEmail = "*****@*****.**", NormalizedUserName = "******", Address = "I tuk i tam", Age = 30, SecurityStamp = Guid.NewGuid().ToString(), CreatedOn = DateTime.UtcNow, }; await userStore.CreateAsync(AdminUserToAdd, "123456"); await userStore.CreateAsync(userToAdd, "123456"); dbContext.SaveChanges(); var adminUser = await userStore.FindByEmailAsync("*****@*****.**"); var user = await userStore.FindByEmailAsync("*****@*****.**"); await userStore.AddToRoleAsync(adminUser, GlobalConstants.AdministratorRoleName); await userStore.AddToRoleAsync(user, GlobalConstants.UserRoleName); }
public async void CreateExamWithNoPRescriptionShoulReturnFalse() { var options = new DbContextOptionsBuilder <EClinicDbContext>() .UseInMemoryDatabase(databaseName: "Appointment_CreateAppointment") .Options; var dbContext = new EClinicDbContext(options); //var mockUserStore = new Mock<IUserStore<EClinicUser>>(); //var mockRoleManager = new Mock<IUserRoleStore<EClinicUser>>(); //var userManager = new UserManager<EClinicUser>(mockUserStore.Object, null, null, null, null, null, null, null, null); var userManager = MockHelpers.MockUserManager <EClinicUser>().Object; var examService = new Mock <ExamService>(dbContext).Object; var appointmentService = new Mock <AppointmentService>(dbContext).Object; var usersService = new Mock <UsersService>(dbContext, userManager, examService).Object; AutoMapperConfig.RegisterMappings(typeof(SetingViewModel).GetTypeInfo().Assembly); var AdminUserToAdd = new EClinicUser { Email = "*****@*****.**", FirstName = "Ivo", MiddleName = "Peshov", LastName = "Petrov", UserName = "******", NormalizedEmail = "*****@*****.**", NormalizedUserName = "******", Address = "Nqkyde Tam 35", Age = 25, SecurityStamp = Guid.NewGuid().ToString(), CreatedOn = DateTime.UtcNow, }; var userToAdd = new EClinicUser { Email = "*****@*****.**", FirstName = "Petyr", MiddleName = "Peshov", LastName = "Petrov", UserName = "******", NormalizedEmail = "*****@*****.**", NormalizedUserName = "******", Address = "I tuk i tam", Age = 30, SecurityStamp = Guid.NewGuid().ToString(), CreatedOn = DateTime.UtcNow, }; dbContext.Users.Add(AdminUserToAdd); dbContext.Users.Add(userToAdd); dbContext.SaveChanges(); var exam = new CreateExamInputModel() { Condition = "good", DoctorUserName = "******", Diagnose = "ssdcsds", PatientUserName = "******", Prescription = "" }; bool result = await examService.CreateExam(exam); Assert.False(result); }