public void Test_DueDate_GetSortedList()
        {
            //Arrange
            Task firstTask  = new Task("Mow the lawn", 1, "2017-03-02");
            Task secondTask = new Task("Walk the dog", 1, "2017-05-02");
            Task thirdTask  = new Task("Wash dishes", 1, "2017-03-12");

            firstTask.Save();
            secondTask.Save();
            thirdTask.Save();


            //Act
            List <Task> allTaskList = new List <Task> {
                firstTask, secondTask, thirdTask
            };

            foreach (Task task in allTaskList)
            {
                Console.WriteLine(task.GetDescription());
            }
            List <Task> expectedList = new List <Task> {
                firstTask, thirdTask, secondTask
            };
            List <Task> testList = Task.GetSortedList();

            //Assert
            Assert.Equal(testList, expectedList);
        }
        public List <Task> GetSortedCategoryTasks()
        {
            List <Task> sortedList      = Task.GetSortedList();
            List <Task> finalSortedList = new List <Task> {
            };

            foreach (Task task in sortedList)
            {
                if (task.GetCategoryId() == this.GetId())
                {
                    finalSortedList.Add(task);
                }
            }
            return(finalSortedList);
        }
Esempio n. 3
0
        public HomeModule()
        {
            Get["/"] = _ => {
                List <Category> AllCategories = Category.GetAll();
                return(View["index.cshtml", AllCategories]);
            };

            Get["/tasks"] = _ => {
                List <Task> AllTasks = Task.GetAll();
                return(View["tasks.cshtml", AllTasks]);
            };

            Get["/categories"] = _ => {
                List <Category> AllCategories = Category.GetAll();
                return(View["categories.cshtml", AllCategories]);
            };

            Get["/categories/new"] = _ => {
                return(View["categories_form.cshtml"]);
            };

            Post["/tasks/sort"] = _ => {
                // List<Task> AllTasks = Task.GetAll();
                List <Task> AllSortedTasks = Task.GetSortedList();
                return(View["tasks.cshtml", AllSortedTasks]);
            };

            Post["/categories/{id}/tasks/sort"] = parameters => {
                Dictionary <string, object> model  = new Dictionary <string, object>();
                var         SelectedCategory       = Category.Find(parameters.id);
                List <Task> AllSortedCategoryTasks = SelectedCategory.GetSortedCategoryTasks();
                model.Add("category", SelectedCategory);
                model.Add("tasks", AllSortedCategoryTasks);
                return(View["category.cshtml", model]);
            };

            Post["/categories/new"] = _ => {
                Category newCategory = new Category(Request.Form["category-name"]);
                newCategory.Save();
                return(View["success.cshtml"]);
            };
            Get["/tasks/new"] = _ => {
                List <Category> AllCategories = Category.GetAll();
                return(View["tasks_form.cshtml", AllCategories]);
            };
            Post["/tasks/new"] = _ => {
                Task newTask = new Task(Request.Form["task-description"], Request.Form["category-id"], Request.Form["task-due-date"]);
                newTask.Save();
                return(View["success.cshtml"]);
            };
            Post["/tasks/delete"] = _ => {
                Task.DeleteAll();
                return(View["cleared.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]);
            };
        }