public void RegisterPostReturnsViewIfModelStateIsInvalid() { AccountController controller = GetAccountController(new MockMembershipService()); var model = new RegisterModel { UserName = "******", Email = "goodEmail", Password = "******", ConfirmPassword = "******" }; controller.ModelState.AddModelError("", "Dummy error message."); ActionResult result = controller.Register(model); Assert.IsInstanceOf<ViewResult>(result); var viewResult = (ViewResult) result; Assert.AreEqual(model, viewResult.ViewData.Model); Assert.AreEqual(10, viewResult.ViewData["PasswordLength"]); }
public void RegisterPostReturnsViewWithCorrectMessageIfRegistrationFails() { string uname = "duplicateUser"; string email = "goodEmail"; string password = "******"; var mock = MockRepository.GenerateStub<IMembershipService>();; mock.Stub(s => s.CreateUser( Arg<string>.Is.Anything, Arg<string>.Is.Anything, Arg<string>.Is.Anything, Arg<string>.Is.Anything, Arg<string>.Is.Anything)) .IgnoreArguments() .Return(MembershipCreateStatus.DuplicateUserName); mock.Stub(s => s.MinPasswordLength).Return(10); AccountController controller = GetAccountController(mock); var model = new RegisterModel { UserName =uname, Email = email, Password = password, ConfirmPassword = password }; ActionResult result = controller.Register(model); Assert.IsInstanceOf<ViewResult>(result); var viewResult = (ViewResult) result; Assert.AreEqual(model, viewResult.ViewData.Model); Assert.AreEqual("Username already exists. Please enter a different user name.", controller.ModelState[""].Errors[0].ErrorMessage); Assert.AreEqual(10, viewResult.ViewData["PasswordLength"]); }
public void RegisterPostReturnsRedirectOnSuccess() { var mock = MockRepository.GenerateStub<IMembershipService>(); ; mock.Stub(s => s.CreateUser( Arg<string>.Is.Anything, Arg<string>.Is.Anything, Arg<string>.Is.Anything, Arg<string>.Is.Anything, Arg<string>.Is.Anything)) .IgnoreArguments() .Return(MembershipCreateStatus.Success); mock.Stub(s => s.MinPasswordLength).Return(10); AccountController controller = GetAccountController(mock); var model = new RegisterModel { UserName = "******", Email = "goodEmail", Password = "******", ConfirmPassword = "******" }; ActionResult result = controller.Register(model); Assert.IsInstanceOf<RedirectToRouteResult>(result); var redirectResult = (RedirectToRouteResult) result; Assert.AreEqual("Goals", redirectResult.RouteValues["controller"]); Assert.AreEqual("Index", redirectResult.RouteValues["action"]); }