Esempio n. 1
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                CreateUserStatus createStatus = UserAuthenticationService.CreateUser(model.UserName, model.Password, model.Email);

                if (createStatus == CreateUserStatus.Success)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, AccountValidation.CreateUserErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = UserAuthenticationService.MinPasswordLength;
            return(View(model));
        }
Esempio n. 2
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                CreateUserStatus createStatus = UserAuthenticationService.CreateUser(model.UserName, model.Password, model.Email);

                if (createStatus == CreateUserStatus.Success)
                {
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError(string.Empty, AccountValidation.CreateUserErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = UserAuthenticationService.MinPasswordLength;
            return View(model);
        }
Esempio n. 3
0
        public void Register_post_returns_view_if_model_state_is_invalid()
        {
            // Arrange
            AccountController controller = GetAccountController();

            RegisterModel model = new RegisterModel()
            {
                UserName = "******",
                Email = "goodEmail",
                Password = "******",
                ConfirmPassword = "******"
            };
            controller.ModelState.AddModelError("", "Dummy error message.");

            // Act
            ActionResult result = controller.Register(model);

            // Assert
            var registerModel = result.AssertViewRendered().WithViewData<RegisterModel>();

            Assert.AreEqual(model, registerModel);
            Assert.AreEqual(10, result.AssertViewRendered().ViewData["PasswordLength"]);
        }
Esempio n. 4
0
        public void Register_post_returns_view_if_registration_fails()
        {
            // Arrange
            AccountController controller = GetAccountController();

            RegisterModel model = new RegisterModel()
            {
                UserName = "******",
                Email = "goodEmail",
                Password = "******",
                ConfirmPassword = "******"
            };

            // Act
            ActionResult result = controller.Register(model);

            // Assert
            var registerModel = result.AssertViewRendered().WithViewData<RegisterModel>();

            Assert.AreEqual(model, registerModel);
            Assert.AreEqual("Username already exists. Please enter a different user name.", controller.ModelState[""].Errors[0].ErrorMessage);
            Assert.AreEqual(10, result.AssertViewRendered().ViewData["PasswordLength"]);
        }
Esempio n. 5
0
        public void Register_post_returns_redirect_on_success()
        {
            // Arrange
            AccountController controller = GetAccountController();

            RegisterModel model = new RegisterModel()
            {
                UserName = "******",
                Email = "goodEmail",
                Password = "******",
                ConfirmPassword = "******"
            };

            // Act
            ActionResult result = controller.Register(model);

            // Assert
            result.AssertActionRedirect()
                .ToController("Home")
                .ToAction("Index");
        }