public async Task AccountRegisterPostValidModelDoesMagic()
 {
     var regModel = new RegistrationViewModel { Password = "******", Email = "*****@*****.**", PasswordConfirm = "hacker" };
     this.accountController.ModelState.AddModelError("Capcha", "Capcha error");
     var result = await this.accountController.Register(regModel);
     result.Should().BeViewResult().WithViewName("~/Features/Account/RegistrationForm.cshtml").ModelAs<RegistrationViewModel>();
     ViewDataDictionary viewData = ((ViewResult)result).ViewData;
     viewData.ModelState.IsValid.Should().BeFalse();
     viewData.ModelState.Values.Count.Should().Be(1);
 }
 public async Task AccountRegisterPostInvalidModelReturnsToRegister()
 {
     var regModel = new RegistrationViewModel { Email = string.Empty, Password = string.Empty };
     this.accountController.ModelState.AddModelError("Email", "email must have value");
     var result = await this.accountController.Register(regModel);
     result.Should().BeViewResult().WithViewName("~/Features/Account/RegistrationForm.cshtml").ModelAs<RegistrationViewModel>();
     ViewDataDictionary viewData = ((ViewResult)result).ViewData;
     viewData.ModelState.IsValid.Should().BeFalse();
     viewData.ModelState.Values.Count.Should().Be(1);
 }
 public void RegistrationModelValidatorChecksPasswordsMatch()
 {
     var model = new RegistrationViewModel { Password = "******", PasswordConfirm = "NoSecret1$", Email = "*****@*****.**" };
     this.validator.ShouldNotHaveValidationErrorFor(l => l.PasswordConfirm, model);
 }
        public virtual async Task<ActionResult> Register(RegistrationViewModel model)
        {
            if (model == null)
            {
                return this.View(MVC.Account.Views.RegistrationForm, new RegistrationViewModel());
            }

            ExtensionMethodExecuter.IsCaptchaValid(this, T("Captcha is not valid."));

            if (!this.ModelState.IsValid)
            {
                return this.View(MVC.Account.Views.RegistrationForm, model);
            }

            // Create user object in database
            var result = await this.UserManager.CreateAsyncWrap(model.Email, model.Password);
            if (result.Item1.Succeeded && result.Item2 != 0)
            {
                int userId = result.Item2;

                // Create all necessary information to send e-mail verification
                string callbackUrl = await this.SendEmailVerificationToken(userId);
#if !PROD
                // For testing this will show same link in next page, to ease confirmation procedure
                ViewBag.Link = callbackUrl;
#endif
                return this.View(MVC.Account.Views.ViewNames.DisplayEmailConfirmation);
            }

            foreach (var errorMessage in result.Item1.Errors)
            {
                this.WebMessages.AddErrorMessage(errorMessage);
            }

            return this.View(MVC.Account.Views.RegistrationForm, model);
        }
 public void RegistrationModelValidatorChecksPasswordsDoesntMatch3()
 {
     var model = new RegistrationViewModel { Password = "******", PasswordConfirm = "abcdefg ", Email = "*****@*****.**" };
     this.validator.ShouldHaveValidationErrorFor(l => l.PasswordConfirm, model);
 }