Exemple #1
0
        public void Test_Find_FindsCategoryInDatabase()
        {
            //Arrange
            Category firstCategory = new Category("Salmon");

            firstCategory.Save();

            //Act
            Category result = Category.Find(firstCategory.GetId());

            //Assert
            Assert.Equal(firstCategory, result);
        }
Exemple #2
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     styleEquality = this.GetStyle() == newCategory.GetStyle();
         return(idEquality && styleEquality);
     }
 }
Exemple #3
0
        public void Test_SaveAssignsIdToObject()
        {
            //Arrange
            Category firstCategory = new Category("Curry");

            firstCategory.Save();

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

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

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

            conn.Open();

            SqlCommand cmd = new SqlCommand("INSERT INTO cookbook (recipe_id, category_id) VALUES (@RecipeId, @CategoryId)", conn);

            SqlParameter recipeIdParameter   = new SqlParameter("@RecipeId", this.GetId());
            SqlParameter categoryIdParameter = new SqlParameter("@CategoryId", newCategory.GetId());

            cmd.Parameters.Add(recipeIdParameter);
            cmd.Parameters.Add(categoryIdParameter);

            cmd.ExecuteNonQuery();

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