public void Login_InvalidCredentials_ErrorMessage()
        {
            // arrange
            var model = new LoginViewModel { Password = "******", Email = "*****@*****.**", RememberMe = false };
            var returnUrl = "/home/index";
            var mockProvider = new MyMvcApplication.Models.Fakes.StubIAuthProvider
            {
                ValidateUserStringString = (usr, pwd) =>
                {
                    return usr == "*****@*****.**" && pwd == "123";
                },
                SetAuthCookieStringBoolean = (email, rememberMe) =>
                {

                }
            };

            // act
            var controller = new AccountDController(mockProvider);
            var viewResult = controller.Login(model, returnUrl) as ViewResult;

            // assert
            Assert.AreEqual(viewResult.ViewName, string.Empty);
            Assert.AreEqual(controller.ModelState["auth"].Errors[0].ErrorMessage, "The user name or password incorrect.", "Incorrect error message");
        }
        public void Login_ValidCredentials_AuthenticateAndRedirect()
        {
            // arrange
            var model = new LoginViewModel { Password = "******", Email = "*****@*****.**", RememberMe = true };
            var returnUrl = "/home/index";
            bool calledValidateUser = false;
            bool calledSetCookie = false;
            var mockProvider = new MyMvcApplication.Models.Fakes.StubIAuthProvider
            {
                ValidateUserStringString = (usr, pwd) =>
                {
                    calledValidateUser = true;
                    return usr == "*****@*****.**" && pwd == "123";
                },
                SetAuthCookieStringBoolean = (email, rememberMe) =>
                {
                    calledSetCookie = true;
                }                
            };

            // act
            var controller = new AccountDController(mockProvider);
            var redirectResult = controller.Login(model, returnUrl) as RedirectResult;

            // assert
            Assert.IsTrue(calledValidateUser, "Membership.ValidateUser not invoked");
            Assert.IsTrue(calledSetCookie, "FormsAuthentication.SetAuthCookie not invoked");
            Assert.AreEqual(returnUrl, redirectResult.Url);
        }