public void LogOnPostReturnsViewIfValidateUserFails()
        {
            AccountController controller = GetAccountController(new MockMembershipService());
            var model = new LogOnModel
                            {
                                UserName = "******",
                                Password = "******",
                                RememberMe = false
                            };

            ActionResult result = controller.LogOn(model, null);

            Assert.IsInstanceOf<ViewResult>(result);
            var viewResult = (ViewResult) result;
            Assert.AreEqual(model, viewResult.ViewData.Model);
            Assert.AreEqual("The user name or password provided is incorrect.",
                            controller.ModelState[""].Errors[0].ErrorMessage);
        }
        public void LogOnPostReturnsRedirectOnSuccessWithoutReturnUrl()
        {
            AccountController controller = GetAccountController(new MockMembershipService());
            var model = new LogOnModel
                            {
                                UserName = "******",
                                Password = "******",
                                RememberMe = false
                            };

            ActionResult result = controller.LogOn(model, null);

            Assert.IsInstanceOf<RedirectToRouteResult>(result);
            var redirectResult = (RedirectToRouteResult) result;
            Assert.AreEqual("Goals", redirectResult.RouteValues["controller"]);
            Assert.AreEqual("Index", redirectResult.RouteValues["action"]);
            Assert.IsTrue(((MockFormsAuthenticationService) controller.FormsService).SignInWasCalled);
        }
        public void LogOnPostReturnsViewIfModelStateIsInvalid()
        {
            AccountController controller = GetAccountController(new MockMembershipService());
            var model = new LogOnModel
                            {
                                UserName = "******",
                                Password = "******",
                                RememberMe = false
                            };
            controller.ModelState.AddModelError("", "Dummy error message.");

            ActionResult result = controller.LogOn(model, null);

            Assert.IsInstanceOf<ViewResult>(result);
            var viewResult = (ViewResult) result;
            Assert.AreEqual(model, viewResult.ViewData.Model);
        }
        public void LogOnPostReturnsRedirectOnSuccessWithReturnUrl()
        {
            var mock = MockRepository.GenerateMock<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(new MockMembershipService());
            var model = new LogOnModel
                            {
                                UserName = "******",
                                Password = "******",
                                RememberMe = false
                            };

            ActionResult result = controller.LogOn(model, "/someUrl");

            Assert.IsInstanceOf<RedirectResult>(result);
            var redirectResult = (RedirectResult) result;
            Assert.AreEqual("/someUrl", redirectResult.Url);
            Assert.IsTrue(((MockFormsAuthenticationService) controller.FormsService).SignInWasCalled);
        }