public ActionResult EditProfile(UserViewModel user) { if (!((bool?)this.Session["LoggedIn"] ?? false)) return RedirectToAction("Login", "Account"); try { using (var proxy = factory.GetWorkChannel()) { UserDTO currUser = ((UserDTO)this.Session["User"]); var newUser = proxy.UpdateUser(new UpdateRequest<UserDTO> { Login = ((UserDTO)this.Session["User"]).Email, Password = ((UserDTO)this.Session["User"]).Password, Data = new UserDTO { Address = user.Address, Email = user.Email, Name = user.Name, Password = currUser.Password, Phone = user.Phone, UserID = ((UserDTO)this.Session["User"]).UserID, Rights = ((UserDTO)this.Session["User"]).Rights } }); this.Session["User"] = newUser.Data; return RedirectToAction("Index"); //return View(); } } catch (Exception e) { return HandleFaults(e); } }
public void HomeControllerEditProfilePOST() { const bool ISAJAX = true; var info = new UserViewModel() { Email = "Admin", Password = "******", Address = "Address", Phone = 999, Name = "AdminName2" }; var factory = new WorkChannelFactoryMock(); HomeController ctrl = new HomeController(factory); FakeControllerSession.SetFakeControllerContext(ctrl, ISAJAX); //Redirect if not logged // TODO - maybe we need to remove this ctrl.Session["LoggedIn"] = false; var res1 = ctrl.EditProfile(info) as RedirectToRouteResult; Assert.IsNotNull(res1); Assert.AreEqual(res1.RouteValues["action"], "Login"); Assert.AreEqual(res1.RouteValues["controller"], "Account"); //Pass if everything ok ctrl.Session["LoggedIn"] = true; var res2 = ctrl.EditProfile(info) as RedirectToRouteResult; Assert.IsNotNull(res2); Assert.AreEqual(res2.RouteValues["action"], "Index"); var upd = factory.LastWorkChannel.UsersUpdated; Assert.AreEqual(upd.Count, 1); Assert.AreEqual(upd[0].Name, ((UserDTO)ctrl.Session["User"]).Name); Assert.AreEqual(upd[0].Name, "AdminName2"); //Fault when wrong user ((UserDTO)ctrl.Session["User"]).Email = "Unknown"; var res3 = ctrl.EditProfile(info) as ViewResult; Assert.IsNotNull(res3); Assert.AreEqual(res3.Model, "wrong user or password"); }