public void GivenNonLocalReturnUrlAndValidSubmission_WhenPostingLoginDetails_ThenLogUserInAndRedirectToHomepage()
        {
            var vm = new LoginModel();
            const string returnUrl = "http://www.google.com.au/";
            _authenticationService.Login(vm).Returns(true);

            _controller.WithCallTo(c => c.Login(vm, returnUrl))
                .ShouldRedirectTo<HomeController>(c => c.Index());
        }
        public void GivenLocalReturnUrlAndValidSubmission_WhenPostingLoginDetails_ThenLogUserInAndRedirectToReturnUrl()
        {
            var vm = new LoginModel();
            const string returnUrl = "/localurl";
            _authenticationService.Login(vm).Returns(true);

            _controller.WithCallTo(c => c.Login(vm, returnUrl))
                .ShouldRedirectTo(returnUrl);
        }
        public void GivenInvalidSubmission_WhenPostingLoginDetails_ThenShowDefaultViewWithInvalidModelAndReturnUrl()
        {
            var vm = new LoginModel();
            const string returnUrl = "http://www.google.com.au/";

            _controller.WithModelErrors()
                .WithCallTo(c => c.Login(vm, returnUrl))
                .ShouldRenderDefaultView()
                .WithModel(vm);

            Assert.That(_controller.ViewBag.ReturnUrl, Is.EqualTo(returnUrl));
        }
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && _authenticationService.Login(model))
            {
                return RedirectToLocal(returnUrl);
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
        public void GivenValidSubmissionButIncorrectDetails_WhenPostingLoginDetails_ThenShowDefaultViewWithInvalidModelAndReturnUrlAndErrorMessage()
        {
            var vm = new LoginModel();
            const string returnUrl = "http://www.google.com.au/";
            _authenticationService.Login(vm).Returns(false);

            _controller.WithCallTo(c => c.Login(vm, returnUrl))
                .ShouldRenderDefaultView()
                .WithModel(vm)
                .AndModelError("").ThatEquals("The user name or password provided is incorrect.");

            Assert.That(_controller.ViewBag.ReturnUrl, Is.EqualTo(returnUrl));
        }
        public void GivenNoReturnUrlAndValidSubmission_WhenPostingLoginDetails_ThenLogUserInAndRedirectToHomepage([Values(null, "")] string returnUrl)
        {
            var vm = new LoginModel();
            _authenticationService.Login(vm).Returns(true);

            _controller.WithCallTo(c => c.Login(vm, returnUrl))
                .ShouldRedirectTo<HomeController>(c => c.Index());
        }
 public bool Login(LoginModel model)
 {
     return WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe);
 }