Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpPost]
- [AllowAnonymous]
- [ValidateAntiForgeryToken]
- public async Task<ActionResult> Register(RegisterViewModel model)
- {
- if (ModelState.IsValid)
- {
- var user = new ApplicationUser() { UserName = model.UserName, Blocked=false};
- var result = await UserManager.CreateAsync(user, model.Password);
- if (result.Succeeded)
- {
- await UserManager.AddToRoleAsync(user.Id, "user");
- await SignInAsync(user, isPersistent: false);
- return RedirectToAction("Index", "Home");
- }
- else
- {
- AddErrors(result);
- }
- }
- // If we got this far, something failed, redisplay form
- return View(model);
- }
- [TestMethod]
- public void AccountController_Register_UserRegistered()
- {
- var registerViewModel = new RegisterViewModel
- {
- UserName="User",
- Password = "123456",
- ConfirmPassword="123456"
- };
- var accountController = new AccountController();
- var result = accountController.Register(registerViewModel).Result;
- Assert.IsTrue(result is RedirectToRouteResult);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement