public void Register_Account() { // Arrange var mock = new Mock<IAuthenticationService>(); mock.Setup(x => x.SetAuthCookie(It.IsAny<string>(), It.IsAny<bool>())).Verifiable(); _controller = new AccountController(mock.Object); var input = new AccountInput { BlogTitle = "blog title", AccountEmail = "*****@*****.**", AccountName = "accountname", AccountPassword = "******", AccountDescription = "description", IsGravatarUse = true }; // Act var result = _controller.Register(input) as RedirectToRouteResult; // Assert result.RouteValues["controller"].ShouldEqual("Home"); result.RouteValues["action"].ShouldEqual("Index"); _dbContext.Accounts.Count().ShouldEqual(1); _dbContext.Blogs.Count().ShouldEqual(1); }
public ActionResult Register(AccountInput accountInput) { if (!ModelState.IsValid) return View("Register", accountInput); var blog = new Blog { Title = accountInput.BlogTitle, BlogOwner = new Account { Email = accountInput.AccountEmail, Name = accountInput.AccountName, Password = accountInput.AccountPassword, Description = accountInput.AccountDescription, IsGravatarUse = accountInput.IsGravatarUse } }; DbContext.Blogs.Add(blog); DbContext.SaveChanges(); _authenticationService.SetAuthCookie(accountInput.AccountEmail, accountInput.RememberMe); return RedirectToAction("Index", "Home"); }