public void EditUser() { const string userId = "UniqueUserId_EditUser"; const string newUserId = "UniqueUserId_EditUser_Changed"; const string username = userId + "_"; const string newUsername = newUserId + "_"; Tests.MockStorage.Setup(s => s.GetCurrentUser()).Returns(Tests.Storage.GetUser(u => u.Username == "panza")); Storage.CreateUser(new User { Name = "Edit User", Username = username, Password = "******", UserId = userId }); var created = Storage.GetUser(u => u.Username == username); Assert.AreEqual(created.UserId, userId); created.UserId = newUserId; Storage.EditUser(created.Id, new User { Name = "Edit User", Username = newUsername, Password = "******", UserId = newUserId }); Assert.AreEqual(created.UserId, newUserId); Storage.DeleteUser(u => u.Username == newUsername); }
public ActionResult Edit(Guid id, EditUserModel user) { if (user.OpenId == null) { user.OpenId = string.Empty; } if (!ModelState.IsValid) { user.Password = null; //user.RolesList = _Storage.GetRoles().AsQueryable().Select(r => new SelectListItem { Text = IUDICO.UserManagement.Localization.getMessage(r.ToString()), Value = ((int)r).ToString(), Selected = (user.Role == r) }); return(View(user)); } if (!_Storage.UserUniqueIdAvailable(user.UserId, user.Id)) { ModelState.AddModelError("UserID", Localization.getMessage("Unique ID Error")); return(View(user)); } _Storage.EditUser(id, user); return(RedirectToAction("Index")); }
public override void AddUsersToRoles(string[] usernames, string[] roleNames) { if (roleNames.Length != 1) { throw new NotSupportedException(); } var users = _UserStorage.GetUsers(u => usernames.Contains(u.Username)); foreach (var user in users) { user.RoleId = (int)GetRole(roleNames[0]); _UserStorage.EditUser(user.Id, user); } }