public void Test_Delete_DeletesTaskAssociationsFromDatabase() { //Arrange Category testCategory = new Category("Home stuff"); testCategory.Save(); string testDescription = "Mow the lawn"; Task testTask = new Task(testDescription, new DateTime(2016, 2, 2)); testTask.Save(); //Act testTask.AddCategory(testCategory); testTask.Delete(); List<Task> resultCategoryTasks = testCategory.GetTasks(); List<Task> testCategoryTasks = new List<Task> {}; //Assert Assert.Equal(testCategoryTasks, resultCategoryTasks); }
public void Test_Delete_DeletesTaskAssociationsFromDatabase() { Category testCategory = new Category("Home stuff"); testCategory.Save(); string testDescription = "Mow the lawn"; DateTime date1 = new DateTime(2008, 4, 10); Task testTask = new Task(testDescription, date1); testTask.Save(); testTask.AddCategory(testCategory); testTask.Delete(); List <Task> resultCategoryTasks = testCategory.GetTasks(); List <Task> testCategoryTasks = new List <Task> { }; Assert.Equal(testCategoryTasks, resultCategoryTasks); }
public void Test_Delete_DeletesTaskAssociationsFromDatabase() { //Arrange Category testCategory = new Category("Home stuff"); testCategory.Save(); Task testTask = new Task("Mow the lawn"); testTask.Save(); //Act testTask.AddCategory(testCategory); testTask.Delete(); List <Task> resultCategoryTasks = testCategory.GetTasks(); List <Task> testCategoryTasks = new List <Task> { }; //Assert Assert.Equal(testCategoryTasks, resultCategoryTasks); }
public void Test_Delete_RemoveTaskFromDatabase() { // Arrange Task firstTask = new Task("Wash Dishes", "1999-01-01"); firstTask.Save(); Task secondTask = new Task("Empty Dishwasher", "2000-01-01"); secondTask.Save(); // Act List <Task> testTaskList = new List <Task> { secondTask }; firstTask.Delete(); List <Task> resultTaskList = Task.GetAll(); //Assert Assert.Equal(testTaskList, resultTaskList); }
public void Test_Delete_DeletesTaskAssociationsFromDatabase() { //Arrange Category testCategory = new Category("Home stuff"); testCategory.Save(); string testDescription = "Mow the lawn"; bool testComplete = false; Task testTask = new Task(testDescription, testComplete); testTask.Save(); //Act testTask.AddCategory(testCategory); testTask.Delete(); List <Task> resultCategoryTasks = testCategory.GetTasks(); List <Task> testCategoryTasks = new List <Task> { }; //Assert Assert.Equal(testCategoryTasks, resultCategoryTasks); }
public void Test_Delete_DeletesTaskFromDatabase() { //Arrange Category testCategory = new Category("Home stuff"); testCategory.Save(); string description1 = "Mow the lawn"; Task testTask1 = new Task(description1); testTask1.Save(); string description2 = "Do homework"; Task testTask2 = new Task(description2); testTask2.Save(); //Act testTask1.AddCategory(testCategory); testTask1.Delete(); List<Task> resultTasks = Task.GetAll(); List<Task> testTaskList = new List<Task> {testTask2}; List<Task> resultCategoryTasks = testCategory.GetTasks(); List<Task> testCategoryTasks = new List<Task> {}; //Assert Assert.Equal(testTaskList, resultTasks); Assert.Equal(testCategoryTasks, resultCategoryTasks); }
public HomeModule() { Get["/"] = _ => { Dictionary <string, object> passedModel = new Dictionary <string, object>() { }; passedModel["categories"] = Category.GetAll(); passedModel["tasks"] = Task.GetAll(); return(View["index.cshtml", passedModel]); }; Get["/tasks"] = _ => { List <Task> AllTasks = Task.GetAll(); return(View["tasks.cshtml", AllTasks]); }; Get["/categories"] = _ => { List <Category> AllCategories = Category.GetAll(); return(View["categories.cshtml", AllCategories]); }; //Create a new task Get["/tasks/new"] = _ => { return(View["tasks_form.cshtml"]); }; Post["/tasks/new"] = _ => { Task newTask = new Task(Request.Form["task-description"], Request.Form["date"]); newTask.Save(); Dictionary <string, object> passedModel = new Dictionary <string, object>() { }; passedModel["categories"] = Category.GetAll(); passedModel["tasks"] = Task.GetAll(); return(View["index.cshtml", passedModel]); }; //Create a new category Get["/categories/new"] = _ => { return(View["categories_form.cshtml"]); }; Post["/categories/new"] = _ => { Category newCategory = new Category(Request.Form["category-name"]); newCategory.Save(); Dictionary <string, object> passedModel = new Dictionary <string, object>() { }; passedModel["categories"] = Category.GetAll(); passedModel["tasks"] = Task.GetAll(); return(View["index.cshtml", passedModel]); }; Get["tasks/{id}"] = parameters => { Dictionary <string, object> passedModel = new Dictionary <string, object>() { }; Task targetTask = Task.Find(parameters.id); List <Category> taskCategories = targetTask.GetCategories(); List <Category> allCategories = Category.GetAll(); passedModel.Add("task", targetTask); passedModel.Add("taskCategories", taskCategories); passedModel.Add("allCategories", allCategories); return(View["task.cshtml", passedModel]); }; Delete["tasks/{id}"] = parameters => { Task targetTask = Task.Find(parameters.id); targetTask.Delete(); Dictionary <string, object> passedModel = new Dictionary <string, object>() { }; passedModel["categories"] = Category.GetAll(); passedModel["tasks"] = Task.GetAll(); return(View["index.cshtml", passedModel]); }; Patch["/tasks/{id}"] = parameters => { string newName = Request.Form["new-task-name"]; string newDate = Request.Form["new-task-date"]; Task.Find(parameters.id).Update(newName, newDate); Dictionary <string, object> passedModel = new Dictionary <string, object>() { }; passedModel["categories"] = Category.GetAll(); passedModel["tasks"] = Task.GetAll(); return(View["index.cshtml", passedModel]); }; Get["categories/{id}"] = parameters => { Dictionary <string, object> passedModel = new Dictionary <string, object>() { }; Category targetCategory = Category.Find(parameters.id); List <Task> categoryTasks = targetCategory.GetTasks(); List <Task> allTasks = Task.GetAll(); passedModel.Add("category", targetCategory); passedModel.Add("categoryTasks", categoryTasks); passedModel.Add("allTasks", allTasks); return(View["category.cshtml", passedModel]); }; Delete["categories/{id}"] = parameters => { Category targetCategory = Category.Find(parameters.id); targetCategory.Delete(); Dictionary <string, object> passedModel = new Dictionary <string, object>() { }; passedModel["categories"] = Category.GetAll(); passedModel["tasks"] = Task.GetAll(); return(View["index.cshtml", passedModel]); }; Patch["/categories/{id}"] = parameters => { string newName = Request.Form["new-category-name"]; Category.Find(parameters.id).Update(newName); Dictionary <string, object> passedModel = new Dictionary <string, object>() { }; passedModel["categories"] = Category.GetAll(); passedModel["tasks"] = Task.GetAll(); return(View["index.cshtml", passedModel]); }; Post["task/add_category"] = _ => { Category category = Category.Find(Request.Form["category-id"]); Task task = Task.Find(Request.Form["task-id"]); task.AddCategory(category); Dictionary <string, object> passedModel = new Dictionary <string, object>() { }; passedModel["categories"] = Category.GetAll(); passedModel["tasks"] = Task.GetAll(); return(View["index.cshtml", passedModel]); }; Post["category/add_task"] = _ => { Category category = Category.Find(Request.Form["category-id"]); Task task = Task.Find(Request.Form["task-id"]); category.AddTask(task); Dictionary <string, object> passedModel = new Dictionary <string, object>() { }; passedModel["categories"] = Category.GetAll(); passedModel["tasks"] = Task.GetAll(); return(View["index.cshtml", passedModel]); }; // // Get["/categories"] = _ => { // var allCategories = Category.GetAll(); // return View["categories.cshtml", allCategories]; // }; // Post["/categories"] = _ => { // var newCategory = new Category(Request.Form["category-name"]); // newCategory.Save(); // var allCategories = Category.GetAll(); // return View["categories.cshtml", allCategories]; // }; // // Get["/categories/new"] = _ => { // return View["category_form.cshtml"]; // }; // // Get["/categories/{id}"] = parameters => { // Dictionary<string, object> model = new Dictionary<string, object>(); // var selectedCategory = Category.Find(parameters.id); // var categoryTasks = selectedCategory.GetTasks(); // model.Add("category", selectedCategory); // model.Add("tasks", categoryTasks); // return View["category.cshtml", model]; // }; // // Get["/categories/{id}/tasks/new"] = parameters => { // Dictionary<string, object> model = new Dictionary<string, object>(); // Category selectedCategory = Category.Find(parameters.id); // List<Task> allTasks = selectedCategory.GetTasks(); // model.Add("category", selectedCategory); // model.Add("tasks", allTasks); // return View["category_tasks_form.cshtml", model]; // }; // // Post["/delete/task/{categoryId}/{taskId}"] = parameters => { // Task targetTask = Task.Find(parameters.taskId); // targetTask.Delete(); // Dictionary<string, object> model = new Dictionary<string, object>(); // var selectedCategory = Category.Find(parameters.categoryId); // var categoryTasks = selectedCategory.GetTasks(); // model.Add("category", selectedCategory); // model.Add("tasks", categoryTasks); // return View["category.cshtml", model]; // }; // // Post["/delete/category/{categoryId}"] = parameters => { // Category targetCategory = Category.Find(parameters.categoryId); // targetCategory.Delete(); // List<Category> allCategories = Category.GetAll(); // return View["categories.cshtml", allCategories]; // }; // // Post["/tasks"] = _ => { // Dictionary<string, object> model = new Dictionary<string, object>(); // Category selectedCategory = Category.Find(Request.Form["category-id"]); // string taskDescription = Request.Form["task-description"]; // int newCategoryId = int.Parse(Request.Form["category-id"]); // string newDate = Request.Form["date"]; // Task newTask = new Task(taskDescription, newCategoryId, newDate); // newTask.Save(); // List<Task> categoryTasks = selectedCategory.GetTasks(); // model.Add("tasks", categoryTasks); // model.Add("category", selectedCategory); // return View["category.cshtml", model]; // }; }