Esempio n. 1
0
        public void Test_SaveAssignsIdToObject()
        {
            //Arrange
            firstIngredient.Save();

            //Act
            Ingredient testIngredient = Ingredient.GetAllIngredients()[0];

            int result = firstIngredient.GetIngredientId();
            int testId = testIngredient.GetIngredientId();

            //Assert
            Assert.Equal(testId, result);
        }
Esempio n. 2
0
        public void AddIngredient(Ingredient newIngredient)
        {
            SqlConnection conn = DB.Connection();

            conn.Open();

            SqlCommand cmd = new SqlCommand("INSERT INTO ingredients_recipes (recipes_id, ingredients_id) VALUES (@RecipeId, @IngredientId);", conn);

            SqlParameter ingredientIdParameter = new SqlParameter("@IngredientId", newIngredient.GetIngredientId());

            cmd.Parameters.Add(ingredientIdParameter);

            SqlParameter recipeIdParameter = new SqlParameter("@RecipeId", this.GetRecipeId());

            cmd.Parameters.Add(recipeIdParameter);

            cmd.ExecuteNonQuery();

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