Beispiel #1
0
        public void Test_Update_ReturnsComplete_list()
        {
            //Arrange
            Task testTask = new Task("Mow the lawn", "01-02-2017", false);

            testTask.Save();
            Task testTask2 = new Task("Take out garbage", "01-02-2017", false);

            testTask2.Save();

            //Act
            testTask.MarkComplete();
            List <Task> resultResult = new List <Task> {
                testTask
            };
            List <Task> testResult = Task.CompletedTasks();

            foreach (Task task in resultResult)
            {
                Console.WriteLine("result: " + task.GetDescription() + ", " + task.GetId() + ", " + task.GetCompleted());
            }
            foreach (Task task in testResult)
            {
                Console.WriteLine("test: " + task.GetDescription() + ", " + task.GetId() + ", " + task.GetCompleted());
            }

            Assert.Equal(resultResult, testResult);
        }
Beispiel #2
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["/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["dueDate"], Request.Form["completed"]);
                newTask.Save();
                return(View["success.cshtml"]);
            };
            Post["/tasks/delete"] = _ => {
                Task.DeleteAll();
                return(View["index.cshtml"]);
            };
            Get["tasks/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Task            SelectedTask      = Task.Find(parameters.id);
                List <Category> TaskCategories    = SelectedTask.GetCategories();
                List <Category> AllCategories     = Category.GetAll();
                model.Add("task", SelectedTask);
                model.Add("taskCategories", TaskCategories);
                model.Add("allCategories", AllCategories);
                return(View["task.cshtml", model]);
            };

            Get["/categories/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var         SelectedCategory      = Category.Find(parameters.id);
                var         CategoryTasks         = SelectedCategory.GetTasks();
                List <Task> AllTasks = Task.GetAll();
                model.Add("category", SelectedCategory);
                model.Add("tasks", CategoryTasks);
                model.Add("allTasks", AllTasks);
                return(View["category.cshtml", model]);
            };

            Post["/task/add_category"] = _ => {
                Category category = Category.Find(Request.Form["category-id"]);
                Task     task     = Task.Find(Request.Form["task-id"]);
                task.AddCategory(category);
                return(View["success.cshtml"]);
            };
            Post["/category/add_task"] = _ => {
                Category category = Category.Find(Request.Form["category-id"]);
                Task     task     = Task.Find(Request.Form["task-id"]);
                category.AddTask(task);
                return(View["success.cshtml"]);
            };

            Get["tasks/completed"] = _ => {
                List <Task> updatedTasks = Task.CompletedTasks();
                return(View["completed_tasks.cshtml", updatedTasks]);
            };

            Get["tasks/update/{id}"] = _ => {
                List <Task> updatedTasks = Task.CompletedTasks();
                return(View["completed_tasks.cshtml", updatedTasks]);
            };

            Patch["tasks/update/{id}"] = parameters => {
                Task completedTask = Task.Find(parameters.id);
                completedTask.MarkComplete();
                List <Task> updatedTasks = Task.CompletedTasks();
                return(View["completed_tasks.cshtml", updatedTasks]);
            };

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