public void Test_Find_FindsCategoryInDatabase()
    {
      //Arrange
      Category testCategory = new Category("Household chores");
      testCategory.Save();

      //Act
      Category foundCategory = Category.Find(testCategory.GetId());

      //Assert
      Assert.Equal(testCategory, foundCategory);
    }
Exemplo n.º 2
0
        public void Test_GetTasks_RetrievesAllTasksWithCategory()
        {
            Category testCategory = new Category("Household chores");

            testCategory.Save();

            Task firstTask = new Task("Mow the lawn", testCategory.GetId(), "01-01-2017");

            firstTask.Save();
            Task secondTask = new Task("Do the dishes", testCategory.GetId(), "01-01-2017");

            secondTask.Save();


            List <Task> testTaskList = new List <Task> {
                firstTask, secondTask
            };
            List <Task> resultTaskList = testCategory.GetTasks();

            Assert.Equal(testTaskList, resultTaskList);
        }
Exemplo n.º 3
0
 public override bool Equals(System.Object otherCategory)
 {
     if (!(otherCategory is Category))
     {
         return(false);
     }
     else
     {
         Category newCategory  = (Category)otherCategory;
         bool     idEquality   = this.GetId() == newCategory.GetId();
         bool     nameEquality = this.GetName() == newCategory.GetName();
         return(idEquality && nameEquality);
     }
 }
    public void Test_Save_AssignsIdToCategoryObject()
    {
      //Arrange
      Category testCategory = new Category("Household chores");
      testCategory.Save();

      //Act
      Category savedCategory = Category.GetAll()[0];

      int result = savedCategory.GetId();
      int testId = testCategory.GetId();

      //Assert
      Assert.Equal(testId, result);
    }
        public void AddCategory(Category newCategory)
        {
            SqlConnection conn = DB.Connection();

            conn.Open();

            SqlCommand cmd = new SqlCommand("INSERT INTO categories_tasks (category_id, task_id) VALUES (@CategoryId, @TaskId);", conn);

            cmd.Parameters.Add(new SqlParameter("@CategoryId", newCategory.GetId()));
            cmd.Parameters.Add(new SqlParameter("@TaskId", this.GetId()));

            cmd.ExecuteNonQuery();

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