Beispiel #1
0
        public void Test_FindFindsRecipeInDatabase()
        {
            //Arrange
            Recipe firstRecipe = new Recipe("Salmon", "Salmon", "Boil", "3");

            firstRecipe.Save();

            //Act
            Recipe result = Recipe.Find(firstRecipe.GetId());

            //Assert
            Assert.Equal(firstRecipe, result);
        }
Beispiel #2
0
        public void Test_SaveAssignsIdToObject()
        {
            //Arrange
            Recipe firstRecipe = new Recipe("Salmon", "Salmon", "Boil", "3");

            firstRecipe.Save();

            //Act
            Recipe savedRecipe = Recipe.GetAll()[0];

            int result = savedRecipe.GetId();
            int testId = firstRecipe.GetId();

            //Assert
            Assert.Equal(testId, result);
        }
Beispiel #3
0
 public override bool Equals(System.Object otherRecipe)
 {
     if (!(otherRecipe is Recipe))
     {
         return(false);
     }
     else
     {
         Recipe newRecipe            = (Recipe)otherRecipe;
         bool   idEquality           = this.GetId() == newRecipe.GetId();
         bool   nameEquality         = this.GetName() == newRecipe.GetName();
         bool   ingredientsEquality  = this.GetIngredients() == newRecipe.GetIngredients();
         bool   instructionsEquality = this.GetInstructions() == newRecipe.GetInstructions();
         bool   ratingEquality       = this.GetRating() == newRecipe.GetRating();
         return(idEquality && nameEquality && ingredientsEquality && instructionsEquality && ratingEquality);
     }
 }
Beispiel #4
0
        public void AddRecipe(Recipe newRecipe)
        {
            SqlConnection conn = DB.Connection();

            conn.Open();

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

            SqlParameter idRecipeParam   = new SqlParameter("@RecipeId", newRecipe.GetId());
            SqlParameter idCategoryParam = new SqlParameter("@CategoryId", this.GetId());

            cmd.Parameters.Add(idRecipeParam);
            cmd.Parameters.Add(idCategoryParam);

            cmd.ExecuteNonQuery();

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