public async Task ShouldCreateUserAndValidate() { var result = await _service.Create("aUser", "pw"); Assert.IsNotNull(result); Assert.IsTrue(_service.ValidateCredentials(result, "pw")); }
public void Create_SuccessfullyCreateUser_UserCreated() { var userRepositoryMock = MockRepository.GenerateMock <IUserAccountRepository>(); userRepositoryMock.Expect(x => x.Create(null)).IgnoreArguments(); _userManagementService = UserManagementServiceFactory.Create(userRepositoryMock); _userManagementService.Create(Guid.NewGuid(), "Name", "*****@*****.**", "password", "Job Title", UserRole.Member); userRepositoryMock.VerifyAllExpectations(); }
public async Task PostCreateShouldCreateUser() { var user = new ApplicationUser { Id = Guid.NewGuid(), UserName = "******" }; _userService.Create("a", "b").Returns(user); var result = await _controller.Create(new RegisterViewModel { Username = "******", Password = "******", ConfirmPassword = "******" }); Assert.IsInstanceOfType(result, typeof(RedirectToActionResult)); await _signInManager.DidNotReceive().SignInAsync(Arg.Any <ApplicationUser>(), Arg.Any <bool>(), Arg.Any <string>()); }
public ActionResult Create(UserAccountViewModel viewModel) { if (ModelState.IsValid) { try { var id = Guid.NewGuid(); var roles = GetRoles(viewModel); _userManagementService.Create(id, viewModel.Name, viewModel.EmailAddress, viewModel.Password, viewModel.JobTitle, roles); return(RedirectToAction("Index")); } catch (DomainValidationException dex) { ModelState.UpdateFromDomain(dex.Result); } } return(View(viewModel)); }
public async Task <ActionResult> Register(RegisterUserViewModel viewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values.SelectMany(e => e.Errors))); } if (_userManagementService.ValidateUserExistByEmail(viewModel.Email)) { return(BadRequest("Email já cadastrado")); } var result = await _userManagementService.Create(viewModel); viewModel.Password = ""; viewModel.PasswordConfirm = ""; return(Ok(result)); }
public async Task <ActionResult> Registrar(UserRegisterViewModel viewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values.SelectMany(e => e.Errors))); } var result = await _userManagementService.Create(viewModel); if (!result.Succeeded) { return(BadRequest(result.Errors)); } viewModel.Senha = string.Empty; viewModel.ConfirmaSenha = string.Empty; return(Ok(viewModel)); }
public async Task <IActionResult> Create(RegisterViewModel vm) { if (ModelState.IsValid) { var user = await _userService.Create(vm.Username, vm.Password); if (user != null) { return(RedirectToAction(nameof(AccountController.List), "Account")); } else { return(RedirectToLocal(null)); } } else { return(View(vm)); } }
public void Create_IdNotSupplied_InvalidOperationExceptionThrown() { _userManagementService.Create(Guid.Empty, "Name", "*****@*****.**", "password", "Job Title", UserRole.Member); }