public void GivenTheUserHasEnteredAllTheInformation()
 {
     _registerModel = new RegisterModel
     {
         UserName = "******" + new Random(1000).NextDouble().ToString(),
         Email = "*****@*****.**",
         Password = "******",
         ConfirmPassword = "******"
     };
     _controller = new AccountController(_formsService.Object, _memberService.Object);
 }
 public void GivenTheUserHasNotEnteredTheUsername()
 {
     _registerModel = new RegisterModel
     {
         UserName = string.Empty,
         Email = "*****@*****.**",
         Password = "******",
         ConfirmPassword = "******"
     };
     _controller = new AccountController(_formsService.Object,
                      _memberService.Object);
 }
        public ActionResult Register(RegisterModel model)
        {
            //validate input
            if (string.IsNullOrEmpty(model.UserName))
            {
                ModelState.AddModelError("username", "Username is required");
            }

            if (model.Password != model.ConfirmPassword)
            {
                ModelState.AddModelError("password", "The password and confirmation password do not match");
            }

            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return View(model);
        }