public void TestCorrectLogin() { LoginModel loginModel = new LoginModel(); loginModel.UserName = "******"; loginModel.Password = "******"; try { RedirectToRouteResult result = (RedirectToRouteResult)usersController.Login(loginModel, "www.google.com"); Assert.AreEqual(0, 1); } catch (NullReferenceException e) { Assert.AreEqual(1,1); } }
public void TestLoginWithIncorrectUsername() { LoginModel loginModel = new LoginModel(); loginModel.UserName = "******"; loginModel.Password = "******"; ViewResult result = (ViewResult)usersController.Login(loginModel, ""); Assert.AreEqual("System.Web.Mvc.ViewResult", result.GetType().FullName); }
public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid && Membership.ValidateUser(model.UserName, model.Password)) { using (DREAMContext db = new DREAMContext()) { MembershipUser user = Membership.GetUser(model.UserName); if (user.LastPasswordChangedDate < DateTime.Now.AddDays(-42)) { RouteValueDictionary routes = new RouteValueDictionary(); routes.Add("userName", model.UserName); routes.Add("success", true); routes.Add("statusMessage", "Your Password is greater than 42 days old. Please change your password to continue using the DREAM system."); return RedirectToAction("ChangePassword", "Users", routes); } } FormsAuthentication.RedirectFromLoginPage(model.UserName, model.RememberMe); return RedirectToLocal(returnUrl); } // If we got this far, something failed, redisplay form ModelState.AddModelError("", "The user name or password provided is incorrect."); return View(model); }