Advertisement
Guest User

Untitled

a guest
Apr 15th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. [HttpPost]
  2. [AllowAnonymous]
  3. [ValidateAntiForgeryToken]
  4. public async Task<ActionResult> Register(RegisterViewModel model)
  5. {
  6. if (ModelState.IsValid)
  7. {
  8. var user = new ApplicationUser() { UserName = model.UserName, Blocked=false};
  9. var result = await UserManager.CreateAsync(user, model.Password);
  10. if (result.Succeeded)
  11. {
  12. await UserManager.AddToRoleAsync(user.Id, "user");
  13. await SignInAsync(user, isPersistent: false);
  14. return RedirectToAction("Index", "Home");
  15. }
  16. else
  17. {
  18. AddErrors(result);
  19. }
  20. }
  21.  
  22. // If we got this far, something failed, redisplay form
  23. return View(model);
  24. }
  25.  
  26. [TestMethod]
  27. public void AccountController_Register_UserRegistered()
  28. {
  29.  
  30. var registerViewModel = new RegisterViewModel
  31. {
  32. UserName="User",
  33. Password = "123456",
  34. ConfirmPassword="123456"
  35. };
  36. var accountController = new AccountController();
  37. var result = accountController.Register(registerViewModel).Result;
  38. Assert.IsTrue(result is RedirectToRouteResult);
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement