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); }
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); } }
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); 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(); } }