public void Test_Delete_DeletesCategoryFromDatabase()
        {
            //Arrange
              string name1 = "Home stuff";
              Category testCategory1 = new Category(name1);
              testCategory1.Save();

              string name2 = "Work stuff";
              Category testCategory2 = new Category(name2);
              testCategory2.Save();
              DateTime fakeTime = new DateTime(2016, 1, 1);

              Task testTask1 = new Task("Mow the lawn", testCategory1.GetId(),fakeTime);
              testTask1.Save();
              DateTime fakeTime1 = new DateTime(2016, 1, 1);

              Task testTask2 = new Task("Send emails", testCategory2.GetId(),fakeTime1);
              testTask2.Save();

              //Act
              testCategory1.Delete();
              List<Category> resultCategories = Category.GetAll();
              List<Category> testCategoryList = new List<Category> {testCategory2};

              List<Task> resultTasks = Task.GetAll();
              List<Task> testTaskList = new List<Task> {testTask2};

              //Assert
              Assert.Equal(testCategoryList, resultCategories);
              Assert.Equal(testTaskList, resultTasks);
        }
Пример #2
0
        public static Task Find(int id)
        {
            SqlConnection conn = DB.Connection();
            conn.Open();

            SqlCommand cmd = new SqlCommand("SELECT * FROM tasks WHERE id = @TaskId;", conn);
            SqlParameter taskIdParameter = new SqlParameter();
            taskIdParameter.ParameterName = "@TaskId";
            taskIdParameter.Value = id.ToString();
            cmd.Parameters.Add(taskIdParameter);
            SqlDataReader rdr = cmd.ExecuteReader();

            int foundTaskId = 0;
            string foundTaskDescription = null;
            while(rdr.Read())
            {
              foundTaskId = rdr.GetInt32(0);
              foundTaskDescription = rdr.GetString(1);
            }
            Task foundTask = new Task(foundTaskDescription, foundTaskId);

            if (rdr != null)
            {
              rdr.Close();
            }
            if (conn != null)
            {
              conn.Close();
            }

            return foundTask;
        }
Пример #3
0
    public static List<Task> GetAll()
    {
      List<Task> AllTasks = new List<Task>{};

      SqlConnection conn = DB.Connection();
      SqlDataReader rdr = null;
      conn.Open();

      SqlCommand cmd = new SqlCommand("SELECT * FROM tasks", conn);
      rdr = cmd.ExecuteReader();

      while(rdr.Read())
      {
        int taskId = rdr.GetInt32(0);
        string taskDescription = rdr.GetString(1);
        int taskCategoryId = rdr.GetInt32(2);
        Task newTask = new Task(taskDescription, taskCategoryId, taskId);
        AllTasks.Add(newTask);
      }
      if (rdr != null)
      {
        rdr.Close();
      }
      if (conn != null)
      {
        conn.Close();
      }
      return AllTasks;
    }
Пример #4
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"];
     // };
 }
        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];
            };
        }
Пример #6
0
    public void Test_EqualOverrideTrueForSameDescription()
    {
      //Arrange, Act
      Task firstTask = new Task("Mow the lawn");
      Task secondTask = new Task("Mow the lawn");

      //Assert
      Assert.Equal(firstTask, secondTask);
    }
Пример #7
0
        public void Test_Equal_ReturnsTrueIfDescriptionsAreTheSame()
        {
            //Arrange, Act
              Task firstTask = new Task("Mow the lawn");
              Task secondTask = new Task("Mow the lawn");

              //Assert
              Assert.Equal(firstTask, secondTask);
        }
Пример #8
0
        public void Test_Equal_ReturnsTrueIfDescriptionsAreTheSame()
        {
            //Arrange, Act
              DateTime fakeTime = new DateTime(2016, 1, 1);
              Task firstTask = new Task("Mow the lawn", 1, fakeTime);
              Task secondTask = new Task("Mow the lawn", 1, fakeTime);

              //Assert
              Assert.Equal(firstTask, secondTask);
        }
Пример #9
0
    public void Test_FindFindsTaskInDatabase()
    {
      //Arrange
      Task testTask = new Task("Mow the lawn");
      testTask.Save();

      //Act
      Task foundTask = Task.Find(testTask.GetId());

      //Assert
      Assert.Equal(testTask, foundTask);
    }
Пример #10
0
    public void Test_Save()
    {
      //Arrange
      Task testTask = new Task("Mow the lawn");
      testTask.Save();

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

      //Assert
      Assert.Equal(testList, result);
    }
Пример #11
0
        public void Test_Find_FindsTaskInDatabase()
        {
            //Arrange
              DateTime fakeTime = new DateTime(2016, 1, 1);
              Task testTask = new Task("Mow the lawn", 1, fakeTime);
              testTask.Save();

              //Act
              Task foundTask = Task.Find(testTask.GetId());

              //Assert
              Assert.Equal(testTask, foundTask);
        }
Пример #12
0
        public HomeModule()
        {
          //Index
            Get["/"] = _ => {
              List<Category> AllCategories = Category.GetAll();
              return View["index.cshtml", AllCategories];
            };
            //Get: Lists
            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["category-id"]);
              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];
            };
        }
Пример #13
0
    public void Test_SaveAssignsIdToObject()
    {
      //Arrange
      Task testTask = new Task("Mow the lawn");
      testTask.Save();

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

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

      //Assert
      Assert.Equal(testId, result);
    }
Пример #14
0
        public void Test_Complete_CompletesTaskWhenDone()
        {
            //Arrange
              string testDescription = "Mow the lawn";
              DateTime? taskDate = new DateTime(2016, 7, 12);
              Task testTask = new Task(testDescription, taskDate);
              testTask.Save();

              //Act
              testTask.Complete();
              bool result = testTask.IsDone();

              //Assert
              Assert.Equal(true, result);
        }
Пример #15
0
        public void Test_Save_AssignsIdToObject()
        {
            //Arrange
              DateTime fakeTime = new DateTime(2016, 1, 1);
              Task testTask = new Task("Mow the lawn", 1, fakeTime);

              //Act
              testTask.Save();
              Task savedTask = Task.GetAll()[0];

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

              //Assert
              Assert.Equal(testId, result);
        }
Пример #16
0
        public void Test_AddCategory_AddsCategoryToTask()
        {
            //Arrange
              Task testTask = new Task("Mow the lawn", new DateTime(2016, 2, 2), false);
              testTask.Save();

              Category testCategory = new Category("Home stuff");
              testCategory.Save();

              //Act
              testTask.AddCategory(testCategory);

              List<Category> result = testTask.GetCategories();
              List<Category> testList = new List<Category>{testCategory};

              //Assert
              Assert.Equal(testList, result);
        }
Пример #17
0
        public void Test18_GetCategories_ReturnsAllTaskCategories()
        {
            DateTime testTime = new DateTime(2016, 1, 1);

              Task testTask = new Task("Mow the lawn",testTime);
              testTask.Save();

              Category testCategory1 = new Category("Home Stuff");
              testCategory1.Save();

              Category testCategory2 = new Category("Work Stuff");
              testCategory2.Save();

              testTask.AddCategory(testCategory1);
              List<Category> result = testTask.GetCategories();
              List<Category> testList= new List<Category>{testCategory1};

              Assert.Equal(testList,result);
        }
Пример #18
0
 public HomeModule()
 {
     Get["/"] = _ => {
         return View["index.cshtml"];
     };
     Post["/task_added"] = _ => {
       var NewTask = new Task (Request.Form["new-task"]);
       NewTask.Save();
       return View["task_added.cshtml", NewTask];
     };
     Get["/view_all_tasks"] = _ => {
       var AllTasks = Task.ListOfTasks;
       return View["view_all_tasks.cshtml", AllTasks];
     };
     Post["/tasks_cleared"] = _ => {
       Task.DeleteAll();
       return View["tasks_cleared.cshtml"];
     };
 }
Пример #19
0
        public void Test_Delete_DeletesCategoryAssociationsFromDatabase()
        {
            //Arrange
              Task testTask = new Task("Mow the lawn", false);
              testTask.Save();

              string testName = "Home stuff";
              Category testCategory = new Category(testName);
              testCategory.Save();

              //Act
              testCategory.AddTask(testTask);
              testCategory.Delete();

              List<Category> resultTaskCategories = testTask.GetCategories();
              List<Category> testTaskCategories = new List<Category> {};

              //Assert
              Assert.Equal(testTaskCategories, resultTaskCategories);
        }
Пример #20
0
        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);
        }
Пример #21
0
 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"];
     };
 }
Пример #22
0
        public void Test_AddTask_AddsTaskToCategory()
        {
            //Arrange
              Category testCategory = new Category("Household chores");
              testCategory.Save();

              Task testTask = new Task("Mow the lawn", false);
              testTask.Save();

              Task testTask2 = new Task("Water the garden", false);
              testTask2.Save();

              //Act
              testCategory.AddTask(testTask);
              testCategory.AddTask(testTask2);

              List<Task> result = testCategory.GetTasks();
              List<Task> testList = new List<Task>{testTask, testTask2};

              //Assert
              Assert.Equal(testList, result);
        }
Пример #23
0
        public List<Task> GetTasks()
        {
            SqlConnection conn = DB.Connection();
              conn.Open();

              SqlCommand cmd = new SqlCommand("SELECT tasks.* FROM categories JOIN categories_tasks ON (categories.id = categories_tasks.category_id) JOIN tasks ON (categories_tasks.task_id = tasks.id) WHERE categories.id = @CategoryId;", conn);
              SqlParameter categoryIdParameter = new SqlParameter();
              categoryIdParameter.ParameterName = "@CategoryId";
              categoryIdParameter.Value = this.GetId().ToString();
              cmd.Parameters.Add(categoryIdParameter);

              SqlDataReader rdr = cmd.ExecuteReader();

              List<Task> tasks = new List<Task>{};
              while(rdr.Read())
              {
            int taskId = rdr.GetInt32(0);
            string taskDescription = rdr.GetString(1);
            DateTime fakeTime = rdr.GetDateTime(2);
            Task newTask = new Task(taskDescription,fakeTime, taskId);
            tasks.Add(newTask);
              }

              if (rdr != null)
              {
            rdr.Close();
              }

              if(conn != null)
              {
              conn.Close();
              }
            return tasks;
        }
Пример #24
0
        public void AddTask(Task newTask)
        {
            SqlConnection conn = DB.Connection();
              conn.Open();

              SqlCommand cmd = new SqlCommand("INSERT INTO categories_tasks(category_id,task_id) VALUES(@CategoryId,@TaskId);",conn);
              SqlParameter categoryIdParameter = new SqlParameter();
              categoryIdParameter.ParameterName = "@categoryId";
              categoryIdParameter.Value=this.GetId();
              cmd.Parameters.Add(categoryIdParameter);

              SqlParameter taskIdParameter = new SqlParameter();
              taskIdParameter.ParameterName="@TaskId";
              taskIdParameter.Value=newTask.GetId();
              cmd.Parameters.Add(taskIdParameter);

              cmd.ExecuteNonQuery();
              if(conn != null)
              {
            conn.Close();
              }
        }
Пример #25
0
    public void Test_Update_UpdatesTaskInDatabase()
    {
      //Arrange
      string description = "Mow the lawn";
      Task testTask = new Task(description);
      testTask.Save();
      string newDescription = "Walk the dog";

      //Act
      testTask.Update(newDescription);
      string result = testTask.GetDescription();

      //Assert
      Assert.Equal(newDescription, result);
    }
        public void Test_Delete_DeletesCategoryAssociationsFromDatabase()
        {
            //Arrange
              DateTime testTime = new DateTime(2016, 1, 1);

              Task testTask = new Task("Mow the lawn",testTime);
              testTask.Save();

              string testName = "Home stuff";
              Category testCategory = new Category(testName);
              testCategory.Save();

              //Act
              testCategory.AddTask(testTask);
              testCategory.Delete();

              List<Category> resultTaskCategories = testTask.GetCategories();
              List<Category> testTaskCategories = new List<Category> {};
              List<Task> resultsTasks= Task.GetAll();
              List<Task> testTasks= new List<Task>{testTask};

              //Assert
              Assert.Equal(testTaskCategories, resultTaskCategories);
              Assert.Equal(testTasks, resultsTasks);
        }
        public void Test_GetTasks_ReturnAllCategoryTasks()
        {
            Category testCategory = new Category("Househould chores");
              testCategory.Save();
              DateTime testTime = new DateTime(2016, 1, 1);

              Task testTask1= new Task("Mow the lawn",testTime);
              testTask1.Save();

              Task testTask2 = new Task("Buy plane ticket",testTime);
              testTask2.Save();

              testCategory.AddTask(testTask1);
              List<Task> savedTasks = testCategory.GetTasks();
              List<Task> testList= new List<Task>{testTask1};
              Assert.Equal(testList,savedTasks);
        }
Пример #28
0
    public void Test_GetCategories_ReturnsAllTaskCategories()
    {
      //Arrange
      Task testTask = new Task("Mow the lawn");
      testTask.Save();

      Category testCategory1 = new Category("Home stuff");
      testCategory1.Save();

      Category testCategory2 = new Category("Work stuff");
      testCategory2.Save();

      //Act
      testTask.AddCategory(testCategory1);
      List<Category> result = testTask.GetCategories();
      List<Category> testList = new List<Category> {testCategory1};

      //Assert
      Assert.Equal(testList, result);
    }
Пример #29
0
    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);
    }
Пример #30
0
        public void Test_Save_SavesToDatabase()
        {
            //Arrange
              DateTime? taskDate = new DateTime(2016, 7, 12);
              Task testTask = new Task("Mow the lawn", taskDate);

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

              //Assert
              Assert.Equal(testList, result);
        }