Esempio n. 1
0
        public async Task AccountController_RegisterTest()
        {
            AccountController controller = IoCFactory.Instance.CurrentContainer.Resolve<AccountController>();
            RegisterViewModel model = new RegisterViewModel()
            {
                Email = "*****@*****.**",
                Password = "******",
                ConfirmPassword = "******"
            };

            RedirectToRouteResult result = await controller.Register(model) as RedirectToRouteResult;
            Assert.IsNotNull((object)result);
            Assert.AreEqual((object)"Index", result.RouteValues["action"]);
            Assert.AreEqual((object)"Home", result.RouteValues["controller"]);


        }
Esempio n. 2
0
        public async Task AccountController_RegisterTest_InvalidEmailFormat()
        {
            //Arrange
            AccountController controller = IoCFactory.Instance.CurrentContainer.Resolve<AccountController>();
            RegisterViewModel model = new RegisterViewModel()
            {
                Email = "test.test",
                Password = "******",
                ConfirmPassword = "******"
            };

            //Act
            ViewResult result = await controller.Register(model) as ViewResult;
            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(controller.ModelState.Count == 1);
            string errors = string.Join("; ", controller.ModelState.Values
                                        .SelectMany(x => x.Errors)
                                        .Select(x => x.ErrorMessage));
            Assert.IsFalse(string.IsNullOrEmpty(errors));
        }
Esempio n. 3
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await this._userManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await _signInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                    
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await this._userManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await this._userManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }