コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: Category.cs プロジェクト: jiwonk42/to-do-list-join
 public override bool Equals(System.Object otherCategory)
 {
     if (!(otherCategory is Category))
     {
         return(false);
     }
     else
     {
         Category newCategory        = (Category)otherCategory;
         bool     descritionEquality = this.GetDescription() == newCategory.GetDescription();
         bool     idEquality         = this.GetId() == newCategory.GetId();
         return(descritionEquality && idEquality);
     }
 }
コード例 #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);
     }
 }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);

              SqlParameter categoryIdParameter = new SqlParameter();
              categoryIdParameter.ParameterName = "@CategoryId";
              categoryIdParameter.Value = newCategory.GetId();
              cmd.Parameters.Add(categoryIdParameter);

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

              cmd.ExecuteNonQuery();

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