public void ChangeTodoList_DeleteTodoItemFromTodoList() { TodoList todoList = new TodoList(m_TodoItems, false); int iTodoID = 2; //Find Todo Item by TodoID TodoItem item = todoList.GetItem(iTodoID); //Verifies Todo Item is contained in mock TodoList repository before deletion. int iTodoItemCount = todoList.Count; Assert.AreEqual(3, iTodoItemCount); Assert.IsTrue(todoList.Contains(iTodoID)); //Delete Todo Item by specifying the item's TodoID todoList.DeleteItem(iTodoID); //Verifies Todo Item is no longer contained in mock TodoList repository after deletion. iTodoItemCount = todoList.Count; Assert.AreEqual(2, iTodoItemCount); Assert.IsFalse(todoList.Contains(iTodoID)); //Verifies the Todo Item's modification status has been marked to delete. Assert.IsTrue(item.ItemStatus == TodoModelItemStatus.Deleted); }
private static void DeleteTodoAtList() { try { TodoList tl = GetListFromUser(); TodoItem ti = GetItemFromUser(tl); tl.DeleteItem(ti); } catch (IndexOutOfRangeException e) { PrintOutput(e.Message); } }
/// <summary> /// Deletes the selected Todo item in the TodoList grid from both the grid and from the TodoList data model object, as well as marks it for /// deletion in its underlying data source. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDeleteTodoItem_Click(object sender, EventArgs e) { try { if (gridTodoList.SelectedRows.Count == 0) { return; } DataGridViewRow rowTodoItem = gridTodoList.SelectedRows[0]; TodoItem item = m_TodoList.GetItem((int)rowTodoItem.Cells["TodoID"].Value); m_TodoList.DeleteItem(item.TodoID); gridTodoList.Rows.Remove(rowTodoItem); gridTodoList.Update(); m_blTodoListModified = true; } catch (Exception err) { ErrorHandler.ShowErrorMessage(err, "Error in btnDeleteTodoItem_Click function of frmMain form."); } }