public void CreateUser_CreateNormalUser_CountPlusOne() { var repository = DependencyResolver.Current.GetService<IRepository>(); var controller = DependencyResolver.Current.GetService<webTemplate.Areas.Default.Controllers.UserController>(); var countBefore = repository.Users.Count(); var httpContext = new MockHttpContext().Object; var route = new RouteData(); route.Values.Add("controller", "User"); route.Values.Add("action", "Register"); route.Values.Add("area", "Default"); ControllerContext context = new ControllerContext(new RequestContext(httpContext, route), controller); controller.ControllerContext = context; controller.Session.Add(CaptchaImage.CaptchaValueKey, "1111"); var registerUserView = new RegisterUserView() { ID = 0, Email = "*****@*****.**", Password = "******", ConfirmPassword = "******", Captcha = "1111", }; Validator.ValidateObject<RegisterUserView>(registerUserView); controller.Register(registerUserView); var countAfter = repository.Users.Count(); Assert.AreEqual(countBefore + 1, countAfter); }
public void Validate_EmailIsAlreadyExists_Fail() { var registerUserView = new RegisterUserView() { ID = 0, Email = "*****@*****.**", Password = "******", ConfirmPassword = "******", Captcha = "1111" }; Validator.ValidateObject<RegisterUserView>(registerUserView); }
public void Validate_ConfirmPasswordIsEmpty_Fail() { var registerUserView = new RegisterUserView() { ID = 0, Email = "*****@*****.**", Password = "******", ConfirmPassword = "", Captcha = "1111" }; Validator.ValidateObject<RegisterUserView>(registerUserView); }
public void Index_AskForDefaultPage_GetViewResult() { var controller = new webTemplate.Areas.Default.Controllers.UserController(); var registerUserView = new RegisterUserView() { ID = 0, Email = "*****@*****.**", Password = "******", ConfirmPassword = "******", Captcha = "1111" }; }
public void Validate_EmailIsAlreadyExistsButCanEdit_PassValidate() { var registerUserView = new RegisterUserView() { ID = 2, Email = "*****@*****.**", Password = "******", ConfirmPassword = "******", Captcha = "1111" }; Validator.ValidateObject<RegisterUserView>(registerUserView); Assert.IsNotNull(registerUserView); }
public void Register_CaptchaIsInCorrect_Fail() { var httpContext = new MockHttpContext().Object; var controller = DependencyResolver.Current.GetService<Areas.Default.Controllers.UserController>(); var route = new RouteData(); route.Values.Add("controller", "User"); route.Values.Add("action", "Register"); route.Values.Add("area", "Default"); ControllerContext context = new ControllerContext(new RequestContext(httpContext, route), controller); controller.ControllerContext = context; controller.Session.Add(CaptchaImage.CaptchaValueKey, "1112"); var registerUserView = new RegisterUserView() { ID = 0, Captcha = "1111" }; controller.Register(registerUserView); }
public ActionResult Register(RegisterUserView registerUserView) { if (Session[CaptchaImage.CaptchaValueKey] as string != registerUserView.Captcha) { ModelState.AddModelError("Captcha", GlobalRes.captcha_error); } if (ModelState.IsValid) { var user = (User)ModelMapper.Map(registerUserView, typeof(RegisterUserView), typeof(User)); Repository.CreateUser(user); NotifyMail.SendNotify("Register_" + CurrentLangCode, user.Email, format => string.Format(format, HostName), format => string.Format(format, CurrentLangCode, user.ActivatedLink, HostName)); return View("RegisterSuccess", user); } return View(registerUserView); }
public ActionResult Register() { var registerUserView = new RegisterUserView(); return View(registerUserView); }
public void Validate_EmailIsNotCorrect_Fail() { var registerUserView = new RegisterUserView() { ID = 0, Email = "chernikov", Password = "******", ConfirmPassword = "******", Captcha = "1111" }; Validator.ValidateObject<RegisterUserView>(registerUserView); }
public void Validate_EmailIsEmpty_Fail() { var registerUserView = new RegisterUserView() { ID = 0, Email = string.Empty, Password = "******", ConfirmPassword = "******", Captcha = "1111" }; Validator.ValidateObject<RegisterUserView>(registerUserView); }