public void StartLoginLocalReturnUrl()
        {
            var userManager = CreateMockUserManager();
            var signInManager = CreateMockSignInManager();
            var urlHelper = CreateMockUrlHelper();

            var controller = new AccountController(userManager.Object, signInManager.Object, urlHelper.Object);
            var result = controller.Login(LocalUri) as ViewResult;
            Assert.IsNotNull(result);
            Assert.AreEqual(LocalUri, result.ViewBag.ReturnUrl);
        }
        private async Task SubmitLogin(LoginViewModel loginModel, string returnUrl,
            bool verificationFail = false, bool validationFail = false, bool redirectToUri = false, bool redirectToHome = false)
        {
            var userManager = CreateMockUserManager();
            var signInManager = CreateMockSignInManager();
            var urlHelper = CreateMockUrlHelper();

            var controller = new AccountController(userManager.Object, signInManager.Object, urlHelper.Object);

            var vals = Validate(loginModel);

            foreach (var v in vals)
            {
                foreach (var m in v.MemberNames)
                    controller.ModelState.AddModelError(m, v.ErrorMessage);
            }

            var result = await controller.Login(loginModel, returnUrl);

            Assert.IsTrue(verificationFail || validationFail || redirectToUri || redirectToHome);

            if (verificationFail)
            {
                var vr = result as ViewResult;

                userManager.Verify(m => m.FindAsync(loginModel.Email, loginModel.Password), Times.AtLeastOnce);
                signInManager.Verify(m => m.PasswordSignInAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>()), Times.Never);

                Assert.IsNotNull(vr);
                Assert.AreEqual(loginModel, vr.Model);
            }
            else if (validationFail)
            {
                var vr = result as ViewResult;

                userManager.Verify(m => m.FindAsync(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
                signInManager.Verify(m => m.PasswordSignInAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>()), Times.Never);

                Assert.IsNotNull(vr);
                Assert.AreEqual(loginModel, vr.Model);
            }
            else if (redirectToUri)
            {
                var rr = result as RedirectResult;

                userManager.Verify(m => m.FindAsync(loginModel.Email, loginModel.Password), Times.AtLeastOnce);
                signInManager.Verify(m => m.PasswordSignInAsync(loginModel.Email, loginModel.Password, loginModel.RememberMe, false), Times.Once);
                urlHelper.Verify(m => m.IsLocalUrl(returnUrl), Times.AtLeastOnce);

                Assert.IsNotNull(rr);
                Assert.AreEqual(returnUrl, rr.Url);
                Assert.AreEqual(false, rr.Permanent);
            }
            else if (redirectToHome)
            {
                var rr = result as RedirectToRouteResult;

                userManager.Verify(m => m.FindAsync(loginModel.Email, loginModel.Password), Times.AtLeastOnce);
                signInManager.Verify(m => m.PasswordSignInAsync(loginModel.Email, loginModel.Password, loginModel.RememberMe, false), Times.Once);
                urlHelper.Verify(m => m.IsLocalUrl(returnUrl), Times.AtLeastOnce);

                Assert.IsNotNull(rr);
                Assert.AreEqual("Index", rr.RouteValues["action"]);
                Assert.AreEqual("Home", rr.RouteValues["controller"]);
                Assert.AreEqual(false, rr.Permanent);
            }
        }