public ActionResult GenFormLogin(string userName, string password) { ILoginServices loginServices = new LoginServices(); LoginUser user = LoginUser.NewLoginUser(userName, password); loginServices.Login(user); if (loginServices.IsLoggedIn(user)) { DateTime expires = DateTime.Now.AddHours(1); var loginCookie = new HttpCookie("loginCookie", ApplicationContext.User.Identity.Name); Session["user"] = ApplicationContext.User; loginCookie.Expires = expires; Response.AppendCookie(loginCookie); } return(this.Direct(new { success = loginServices.IsLoggedIn(user), data = new { user = user.UserName, password = user.Password } })); }
public void TestUserLoginGetResponse() { // Setup var services = GenFormServiceProvider.Instance.Resolve <ILoginServices>(); Isolate.WhenCalled(() => services.Login(LoginUser.NewLoginUser("Admin", "Admin"))).CallOriginal(); var controller = new LoginController(); // controller receives login request from GUI var response = controller.Login("Admin", "Admin"); // LoginController delegates request to ServiceLayer Isolate.Verify.WasCalledWithExactArguments(() => services.Login(LoginUser.NewLoginUser("Admin", "Admin"))); // Assert result var result = GetSuccessValueFromActionResult(response); Assert.IsTrue(result); }