public void UpdateUser_Authorized_200() { var controller = new UserManagementController(); var admin = _ut.CreateUserObject(); admin.IsAdministrator = true; var adminSession = _ut.CreateSessionObject(admin); _ut.CreateSessionInDb(adminSession); var existingUser = _ut.CreateUserInDb(); // modify user var modifiedUser = _ut.CreateUserObject(); modifiedUser.Id = existingUser.Id; modifiedUser.IsAdministrator = existingUser.IsAdministrator; modifiedUser.Disabled = true; modifiedUser.City = "Long Beach"; // mock payload var mock_payload = new UpdateUserRequestDTO { Id = modifiedUser.Id.ToString(), City = modifiedUser.City, State = modifiedUser.State, Country = modifiedUser.Country, Manager = modifiedUser.ManagerId.ToString(), IsAdmin = modifiedUser.IsAdministrator, Disabled = modifiedUser.Disabled }; var expectedStatusCode = HttpStatusCode.OK; var endpoint = API_Route_Local + "/user/update"; controller.Request = new HttpRequestMessage { RequestUri = new Uri(endpoint) }; controller.Request.Headers.Add("token", adminSession.Token); IHttpActionResult actionresult = controller.UpdateUser(mock_payload); Assert.IsInstanceOfType(actionresult, typeof(NegotiatedContentResult <string>)); var contentresult = actionresult as NegotiatedContentResult <string>; Assert.AreEqual(expectedStatusCode, contentresult.StatusCode); // persistence test using (var _db = _ut.CreateDataBaseContext()) { var getUser = _db.Users.Find(modifiedUser.Id); Assert.AreNotEqual(existingUser, getUser); Assert.AreEqual(existingUser.Id, getUser.Id); Assert.AreEqual(existingUser.IsAdministrator, getUser.IsAdministrator); } }
private void btnUpdateUserData_Click(object sender, EventArgs e) { UserManagementController userManagementController = new UserManagementController(); User user = new User(); //get new data string newFirstName = textBoxFirstName.Text; string newLastName = textBoxLastName.Text; string newEmail = textBoxEmail.Text; string newPhone = textBoxPhone.Text; //gooi dit in een aparte methode (validate data) if (string.IsNullOrEmpty(newFirstName)) { newFirstName = lblCurrentFirstName.Text; } if (string.IsNullOrEmpty(newLastName)) { newLastName = lblCurrentLastName.Text; } if (string.IsNullOrEmpty(newEmail)) // REGEX check { newEmail = lblCurrentEmail.Text; } if (string.IsNullOrEmpty(newPhone)) // REGEX check { newPhone = lblCurrentPhone.Text; } //put data in user object user.firstName = newFirstName; user.lastName = newLastName; user.email = newEmail; user.phoneNumber = int.Parse(newPhone); //go to logic layer userManagementController.UpdateUser("5e6624de1c9d4400008a5134", user); //empty textboxes textBoxFirstName.Text = ""; textBoxLastName.Text = ""; textBoxEmail.Text = ""; textBoxPhone.Text = ""; }
/// <summary> /// Set up the event handlers for child controls. /// </summary> protected void SetupEventHandlers() { AddEditUserDialog.OKClicked += delegate(UserRowData user) { if (AddEditUserDialog.EditMode) { // Commit the change into database if (_controller.UpdateUser(user)) { UserPanel.UpdateUI(); return(true); } return(false); } else { try { if (_controller.AddUser(user)) { UserPanel.UpdateUI(); return(true); } return(false); } catch (Exception) { return(false); } } }; DeleteConfirmation.Confirmed += delegate(object data) { // delete the device and reload the affected partition. UserRowData user = data as UserRowData; _controller.DeleteUser(user); UserPanel.UpdateUI(); }; }
public void UpdateUser_InvalidUserId_404() { newUser = _tu.CreateUserObject(); newUser.IsAdministrator = true; Session newSession = _tu.CreateSessionObject(newUser); _tu.CreateSessionInDb(newSession); var endpoint = API_ROUTE_LOCAL + "/user/update"; _umController.Request = new HttpRequestMessage { RequestUri = new Uri(endpoint) }; var userDTO = new UpdateUserRequestDTO { Id = Guid.NewGuid().ToString(), City = newUser.City, State = newUser.State, Country = newUser.Country, Manager = newUser.ManagerId.ToString(), IsAdmin = newUser.IsAdministrator, Disabled = newUser.Disabled }; var request = new HttpRequestMessage(); request.Headers.Add("token", newSession.Token); _umController.Request = request; //non existent userID should result in UserNotFoundException // and return a 404 NegotiatedContentResult <string> response = (NegotiatedContentResult <string>)_umController.UpdateUser(userDTO); Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); }
public void UpdateUser_InvalidManagerGuid_400() { var controller = new UserManagementController(); var admin = _ut.CreateUserObject(); admin.IsAdministrator = true; var adminSession = _ut.CreateSessionObject(admin); _ut.CreateSessionInDb(adminSession); var existingUser = _ut.CreateUserInDb(); var invalidManagerId = Guid.NewGuid().ToString() + "makeinvalid"; // modify user var modifiedUser = _ut.CreateUserObject(); modifiedUser.Id = existingUser.Id; modifiedUser.IsAdministrator = existingUser.IsAdministrator; // mock payload var mock_payload = new UpdateUserRequestDTO { Id = modifiedUser.Id.ToString(), City = modifiedUser.City, State = modifiedUser.State, Country = modifiedUser.Country, Manager = invalidManagerId, IsAdmin = modifiedUser.IsAdministrator, Disabled = modifiedUser.Disabled }; var expectedStatusCode = HttpStatusCode.BadRequest; var endpoint = API_Route_Local + "/user/update"; controller.Request = new HttpRequestMessage { RequestUri = new Uri(endpoint) }; controller.Request.Headers.Add("token", adminSession.Token); NegotiatedContentResult <string> actionresult = (NegotiatedContentResult <string>)controller.UpdateUser(mock_payload); Assert.AreEqual(expectedStatusCode, actionresult.StatusCode); }