예제 #1
0
 public HomeModule()
 {
     Get["/"] = _ => {
         return(View["index.cshtml"]);
     };
     Get["/tasks"] = _ => {
         var AllTasks = Task.All();
         return(View["tasks.cshtml", AllTasks]);
     };
     Get["/tasks/new"] = _ => {
         return(View["task_form.cshtml"]);
     };
     Post["/tasks"] = _ => {
         var NewTask  = new Task(Request.Form["new-task"]);
         var AllTasks = Task.All();
         return(View["tasks.cshtml", AllTasks]);
     };
     Get["/tasks/{id}"] = parameters => {
         var task = Task.Find(parameters.id);
         return(View["/task.cshtml", task]);
     };
     // Post["/tasks/clear"] = _ => {
     //   Task.DeleteAll();
     //   return View["tasks_cleared.cshtml"];
     // };
 }
예제 #2
0
        public void Test_EmptyAtFirst()
        {
            //Arrange, Act
            int result = Task.All().Count;

            //Assert
            Assert.Equal(0, result);
        }
예제 #3
0
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            };
            Get["/tasks"] = _ => {
                var AllTasks = Task.All();
                return(View["tasks.cshtml", AllTasks]);
            };
            Get["/tasks/new"] = _ => {
                return(View["task_form.cshtml"]);
            };
            Get["/tasks/{id}"] = parameters => {
                var SelectedTask = Task.Find(parameters.id);
                return(View["/task.cshtml", SelectedTask]);
            };
            Get["/categories"] = _ => {
                var AllCategories = Category.All();
                return(View["categories.cshtml", AllCategories]);
            };
            Get["/categories/new"] = _ => {
                return(View["category_form.cshtml"]);
            };
            Post["/categories"] = _ => {
                var NewCategory   = new Category(Request.Form["category-name"]);
                var AllCategories = Category.All();
                return(View["categories.cshtml", AllCategories]);
            };
            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["/tasks"] = _ => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Category    SelectedCategory      = Category.Find(Request.Form["category-id"]);
                List <Task> CategoryTasks         = SelectedCategory.GetTasks();
                string      TaskDescription       = Request.Form["task-description"];
                Task        NewTask = new Task(TaskDescription);
                CategoryTasks.Add(NewTask);

                model.Add("tasks", CategoryTasks);
                model.Add("category", SelectedCategory);

                return(View["/category.cshtml", model]);
            };
        }
예제 #4
0
        public void Test_SaveAssignsIdToObject()
        {
            //Arrange
            Task testTask = new Task("Mow the lawn");

            testTask.Save();

            //Act
            Task savedTask = Task.All()[0];

            int result = savedTask.GetId();
            int testId = testTask.GetId();

            //Assert
            Assert.Equal(testId, result);
        }
예제 #5
0
        public void Test_Save()
        {
            //Arrange
            Task testTask = new Task("Mow the lawn");

            testTask.Save();

            //Act
            List <Task> result   = Task.All();
            List <Task> testList = new List <Task> {
                testTask
            };

            //Assert
            Assert.Equal(testList, result);
        }
 public HomeModule()
 {
     Get["/"] = _ => {
         return(View["index.cshtml"]);
     };
     Get["/tasks"] = _ => {
         List <Task> AllTasks = Task.All();
         return(View["tasks.cshtml", AllTasks]);
     };
     Get["/tasks/new"] = _ => {
         return(View["tasks_form.cshtml"]);
     };
     Post["/tasks/new"] = _ => {
         Task newTask = new Task(Request.Form["task-description"]);
         newTask.Save();
         return(View["success.cshtml"]);
     };
     // Post["/tasks/delete"] = _ => {
     //   Task.DeleteAll();
     //   return View["cleared.cshtml"];
     // };
 }