public void DeleteUser_Authorized_200() { var controller = new UserManagementController(); var admin = _ut.CreateUserObject(); admin.IsAdministrator = true; var adminSession = _ut.CreateSessionObject(admin); _ut.CreateSessionInDb(adminSession); var userToDelete = _ut.CreateUserInDb().Id; var expectedStatusCode = HttpStatusCode.OK; var endpoint = API_Route_Local + "/user/delete/{userId}"; controller.Request = new HttpRequestMessage { RequestUri = new Uri(endpoint) }; controller.Request.Headers.Add("token", adminSession.Token); IHttpActionResult actionresult = controller.DeleteUser(userToDelete.ToString()); 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(userToDelete); Assert.IsNull(getUser); } }
public void Delete_User_Self() { var controller = new AuthController(_dbCtx); var creds = new LoginCredentials() { Username = "******", Password = "******" }; var result = controller.LoginUser(creds) as ObjectResult; var token = ((AuthResponse)result.Value).ResponseToken; var httpContext = new DefaultHttpContext(); httpContext.Request.Headers[_config.authHeader] = $"Bearer {token}"; var controllerContext = new ControllerContext() { HttpContext = httpContext }; var userController = new UserManagementController(_dbCtx); userController.ControllerContext = controllerContext; userController.DeleteUser(); var user = _dbCtx.UserAccounts.Where(x => x.AppUserName.Equals("Rheda")).FirstOrDefault(); var outcome = user == null; Assert.True(outcome); }
protected void Page_Load(object sender, EventArgs e) { managementController.LoadUserTable(rUsers); if(null != Request.QueryString["id"]) { managementController.DeleteUser(Request.QueryString["id"]); Response.Redirect("UserManagement.aspx"); } }
private void btnRemove_Click(object sender, EventArgs e) { UserModel user = new UserModel() { UserId = Convert.ToInt32(listViewUser.SelectedItems[0].SubItems[0].Text), }; UserOverview.DeleteUser(user); FillListView(); }
public void DeleteUser() { // Arrange var controller = new UserManagementController(); // Creating mock DTO UserManagementDTO obj = new UserManagementDTO() { UserName = "******" }; // Act IHttpActionResult actionResult = controller.DeleteUser(obj); var contentResult = actionResult as OkNegotiatedContentResult <string>; // Assert Assert.NotNull(actionResult); Assert.NotNull(contentResult.Content); Assert.Equal("Success: Account was deleted for amay", contentResult.Content); }
public void deleteuser_should_remove_user_and_redirect_to_index() { // Arrange User user = new User() { Id = Guid.NewGuid(), Email = "blah@localhost", IsActivated = true }; _userService.Users.Add(user); // Act RedirectToRouteResult result = _controller.DeleteUser(user.Email) as RedirectToRouteResult; // Assert Assert.That(_userService.Users.Count, Is.EqualTo(0)); Assert.That(result, Is.Not.Null, "RedirectToRouteResult"); Assert.That(result.RouteValues["action"], Is.EqualTo("Index")); }
/// <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 Delete_User_Self_Invalid() { var controller = new AuthController(_dbCtx); var creds = new LoginCredentials() { Username = "******", Password = "******" }; var result = controller.LoginUser(creds) as ObjectResult; var token = ((AuthResponse)result.Value).ResponseToken; var httpContext = new DefaultHttpContext(); httpContext.Request.Headers[_config.authHeader] = $"Bearer {token}"; var controllerContext = new ControllerContext() { HttpContext = httpContext }; var userController = new UserManagementController(_dbCtx); userController.ControllerContext = controllerContext; var responseResult = userController.DeleteUser(); var user = _dbCtx.UserAccounts.Where(x => x.AppUserName.Equals("John")).FirstOrDefault(); var objResult = responseResult as ObjectResult; // The operation should be unauthorized and there shouldn't be any notable side effects to the database var outcome = objResult.StatusCode == 401 && user != null; Assert.True(outcome); }
public void DeleteUser_NoUserId_412() { newUser = _tu.CreateUserObject(); Session newSession = _tu.CreateSessionObject(newUser); _tu.CreateSessionInDb(newSession); var endpoint = API_ROUTE_LOCAL + "/users/delete/"; _umController.Request = new HttpRequestMessage { RequestUri = new Uri(endpoint) }; var request = new HttpRequestMessage(); request.Headers.Add("token", newSession.Token); _umController.Request = request; //passing null parameter creates InvalidModelPayloadException that should be caught // and return a 400 NegotiatedContentResult <string> response = (NegotiatedContentResult <string>)_umController.DeleteUser((string)null); Assert.AreEqual(HttpStatusCode.PreconditionFailed, response.StatusCode); }
public void DeleteNonExistingUser_Authorized_404() { var controller = new UserManagementController(); var admin = _ut.CreateUserObject(); admin.IsAdministrator = true; var adminSession = _ut.CreateSessionObject(admin); _ut.CreateSessionInDb(adminSession); var nonexistingUserToDelete = Guid.NewGuid().ToString(); var expectedStatusCode = HttpStatusCode.NotFound; var endpoint = API_Route_Local + "/user/delete/{userId}"; controller.Request = new HttpRequestMessage { RequestUri = new Uri(endpoint) }; controller.Request.Headers.Add("token", adminSession.Token); NegotiatedContentResult <string> actionresult = (NegotiatedContentResult <string>)controller.DeleteUser(nonexistingUserToDelete); Assert.AreEqual(expectedStatusCode, actionresult.StatusCode); }