public void Should_Add_User() { // given var department = new Department { Name = "Oddział Testowy" }; context.Departments.Add(department); context.SaveChanges(); var newUser = new UserViewModel { DepartmentID = department.ID, Email = "*****@*****.**", ConfirmPassword = "******", Password = "******", Role = UserRoleTypes.Admin, FirstName = "Testowy", SecondName = "User", PhoneNumber = "555666777", UserName = "******" }; var expectedUserCount = context.Admins.Count() + 1; // when useCase.AddNewUser(newUser); // then Assert.AreEqual(expectedUserCount, context.Admins.Count()); Assert.IsNotNull(context.Admins.FirstOrDefault(a => a.FirstName == newUser.FirstName)); }
public IActionResult AddUser(UserViewModel userModel) { if (ModelState.IsValid) { if (drugstore.Users .Any(u => u.Email.Contains(userModel.Email, StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError(nameof(userModel.Email), "Adres email zajęty"); } if (drugstore.Users .Any(u => u.UserName.Contains(userModel.UserName, StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError(nameof(userModel.UserName), "Nazwa użytkownika zajęta"); } if (ModelState.IsValid) { adminUseCase.AddNewUser(userModel); return(RedirectToAction(nameof(Index))); } } ViewData["Departments"] = drugstore.Departments.ToList(); return(View(userModel)); }