public async Task AddUserAsyncShouldAddUserCorrecty() { // Arrange var problem = new Problem { Id = 1, UserProblems = new List <UserProblem>(), }; await this.PlanItDbContext.Problems.AddAsync(problem); await this.PlanItDbContext.SaveChangesAsync(); var problemId = 1; var user = new PlanItUser { Id = "First", }; // Act var expectedCountUsers = 1; var expectedUserId = "First"; var actual = await this.ProblemsService .AddUserAsync(problemId, user); // Assert Assert.Equal(expectedCountUsers, actual.UserProblems.Count()); Assert.Equal(expectedUserId, actual.UserProblems.First().PlanItUserId); }
public async Task <Problem> AssignAsync <TInputModel>(PlanItUser user, TInputModel model) { var input = AutoMapperConfig.MapperInstance.Map <Problem>(model); var problem = new Problem { Name = input.Name, Instructions = input.Instructions, SubProjectId = input.SubProjectId, DueDate = input.DueDate?.ToUniversalTime(), HourlyRate = input.HourlyRate, }; problem.ProgressStatus = await this.progressStatusesService .GetByNameAsync(GlobalConstants.ProgressStatusAssigned); var userProblem = new UserProblem { User = user, Problem = problem, }; problem.UserProblems.Add(userProblem); await this.problemsRepository.AddAsync(problem); await this.problemsRepository.SaveChangesAsync(); return(problem); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl ??= this.Url.Content("~/Identity/Account/Login"); // For safety if (this.userManager.Users.ToList().Count > 0) { return(this.LocalRedirect(returnUrl)); } if (this.ModelState.IsValid) { var user = new PlanItUser { UserName = this.Input.Email, Email = this.Input.Email, FirstName = this.Input.FirstName, MiddleName = this.Input.MiddleName, LastName = this.Input.LastName, CompanyName = this.Input.Company, JobTitle = "founder", PhoneNumber = this.Input.PhoneNumber, EmailConfirmed = true, }; var result = await this.userManager.CreateAsync(user, this.Input.Password); if (result.Succeeded) { // Assign to user roles await this.userManager.AddToRoleAsync(user, GlobalConstants.CompanyOwnerRoleName); // Assign to user claims string fullName = $"{user.FirstName} {user.LastName}"; await this.userManager.AddClaimAsync(user, new Claim("FullName", fullName)); await this.userManager.AddClaimAsync(user, new Claim("JobTitle", user.JobTitle)); await this.userManager.AddClaimAsync(user, new Claim("CompanyName", user.CompanyName)); this.logger.LogInformation("Founder created a new account with password."); return(this.LocalRedirect(returnUrl)); } foreach (var error in result.Errors) { this.ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(this.Page()); }
public async Task <Hour> AddHourAsync(Problem problem, PlanItUser user, decimal hours) { var hour = new Hour { Problem = problem, User = user, WorkedHours = hours, Date = DateTime.UtcNow, }; await this.hoursRepository.AddAsync(hour); await this.hoursRepository.SaveChangesAsync(); return(hour); }
public async Task AllCompletedTasksCountByUserIdUserWithManyProbemsShouldReturnCorretcNumber() { // Arrange var user = new PlanItUser { Id = "First", UserProblems = new List <UserProblem> { new UserProblem { Problem = new Problem { ProgressStatus = new ProgressStatus { Name = GlobalConstants.ProgressStatusCompleted, }, }, }, new UserProblem { Problem = new Problem { ProgressStatus = new ProgressStatus { Name = GlobalConstants.ProgressStatusInProgress, }, }, }, }, }; await this.PlanItDbContext.Users.AddAsync(user); await this.PlanItDbContext.SaveChangesAsync(); // Act var expected = 1; var actual = this.ProblemsService.AllCompletedTasksCountByUserId(user.Id); // Assert Assert.Equal(expected, actual); }
public async Task <Problem> AddUserAsync(int taskId, PlanItUser user) { var problem = await this.problemsRepository .All() .Where(t => t.Id == taskId) .FirstOrDefaultAsync(); var userProblem = new UserProblem { User = user, Problem = problem, }; problem.UserProblems.Add(userProblem); this.problemsRepository.Update(problem); await this.problemsRepository.SaveChangesAsync(); return(problem); }
private static async Task SeedUserAsync(PlanItDbContext dbContext, UserManager <PlanItUser> userManager, int i) { var user = new PlanItUser { UserName = $"loafer{i}@aaa.bg", Email = $"loafer{i}@aaa.bg", FirstName = $"Ivan{i}", MiddleName = $"Petrov{i}", LastName = $"Georgiev{i}", CompanyName = $"Project{i}X", JobTitle = $"Engineer", PhoneNumber = $"+35988797212{i}", EmailConfirmed = true, }; var isExist = dbContext.Users.Any(u => u.Email == user.Email); if (!isExist) { var result = await userManager.CreateAsync(user, $"123456-{i}"); if (result.Succeeded) { // Assign to user roles await userManager.AddToRoleAsync(user, GlobalConstants.UserRoleName); // Assign to user claims - needed for the _loginPartial string fullName = $"{user.FirstName} {user.LastName}"; await userManager.AddClaimAsync(user, new Claim("FullName", fullName)); await userManager.AddClaimAsync(user, new Claim("JobTitle", user.JobTitle)); await userManager.AddClaimAsync(user, new Claim("CompanyName", user.CompanyName)); } else { throw new Exception(string.Join(Environment.NewLine, result.Errors.Select(e => e.Description))); } } }
private async Task LoadAsync(PlanItUser user) { var email = await this.userManager.GetEmailAsync(user); var phoneNumber = await this.userManager.GetPhoneNumberAsync(user); var jobTitle = user.CompanyName; this.Email = email; this.Input = new InputModel { PhoneNumber = phoneNumber, FirstName = user.FirstName, MiddleName = user.MiddleName, LastName = user.LastName, JobTitle = user.JobTitle.ToLower(), }; if (jobTitle != "founder") { this.Input.Company = jobTitle; } }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl ??= this.Url.Content("~/Identity/Account/Login"); var invite = await this.invitesService.GetByEmailAsync <InviteRegisterViewModel>(this.Email); if (invite == null) { this.ModelState.AddModelError(string.Empty, "Invalid invite email!"); } var existingUser = await this.userManager.FindByEmailAsync(invite.Email); if (existingUser != null) { this.ModelState.AddModelError(string.Empty, "Your account exist. Please email to support!"); } if (this.Input.JobTitle.ToLower() == "founder") { this.ModelState.AddModelError(string.Empty, "Job Title Founder already exists!!!"); } if (this.ModelState.IsValid) { var user = new PlanItUser { UserName = this.Email, Email = this.Email, FirstName = this.Input.FirstName, MiddleName = this.Input.MiddleName, LastName = this.Input.LastName, CompanyName = this.Input.Company, JobTitle = this.Input.JobTitle.ToLower(), PhoneNumber = this.Input.PhoneNumber, EmailConfirmed = true, }; var result = await this.userManager.CreateAsync(user, this.Input.Password); if (result.Succeeded) { // Assign to user roles await this.userManager.AddToRoleAsync(user, GlobalConstants.UserRoleName); // Assign to user claims - needed for the _loginPartial string fullName = $"{user.FirstName} {user.LastName}"; await this.userManager.AddClaimAsync(user, new Claim("FullName", fullName)); await this.userManager.AddClaimAsync(user, new Claim("JobTitle", user.JobTitle)); await this.userManager.AddClaimAsync(user, new Claim("CompanyName", user.CompanyName)); this.logger.LogInformation("User created a new account with password."); await this.invitesService.DeleteAsync(invite.Id); return(this.LocalRedirect(returnUrl)); } foreach (var error in result.Errors) { this.ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(this.Page()); }
public async Task AssignAsyncShouldAssignCorrectly() { // Arrange var inputProblem = new TaskAssignInputModel { Name = "First", Instructions = "Draw", SubProjectId = 2, DueDate = DateTime.Now, HourlyRate = 25, }; var status = new ProgressStatus { Name = GlobalConstants.ProgressStatusAssigned, }; await this.PlanItDbContext.ProgressStatuses.AddAsync(status); await this.PlanItDbContext.SaveChangesAsync(); var user = new PlanItUser { Id = "First", }; // Act var expected = new Problem { Id = 1, Name = "First", Instructions = "Draw", SubProjectId = 2, DueDate = DateTime.UtcNow, HourlyRate = 25, ProgressStatus = new ProgressStatus { Name = GlobalConstants.ProgressStatusAssigned, }, UserProblems = new List <UserProblem> { new UserProblem { PlanItUserId = "First", ProblemId = 1, }, }, }; var actual = await this.ProblemsService .AssignAsync <TaskAssignInputModel>(user, inputProblem); // Assert Assert.Equal(expected.Name, actual.Name); Assert.Equal(expected.Instructions, actual.Instructions); Assert.Equal(expected.SubProjectId, actual.SubProjectId); Assert.Equal(expected.DueDate?.ToString(DateTimeFormat), actual.DueDate?.ToString(DateTimeFormat)); Assert.Equal(expected.HourlyRate, actual.HourlyRate); Assert.Equal(expected.ProgressStatus.Name, actual.ProgressStatus.Name); Assert.Equal(expected.UserProblems.First().PlanItUserId, actual.UserProblems.First().PlanItUserId); Assert.Equal(expected.UserProblems.First().ProblemId, actual.UserProblems.First().ProblemId); }