Beispiel #1
0
        public void Test_SaveAssignsIdToObject()
        {
            //Arrange
            firstRecipe.Save();

            //Act
            Recipe testRecipe = Recipe.GetAllRecipes()[0];

            int result = firstRecipe.GetRecipeId();
            int testId = testRecipe.GetRecipeId();

            //Assert
            Assert.Equal(testId, result);
        }
Beispiel #2
0
        public void AddRecipe(Recipe newRecipe)
        {
            SqlConnection conn = DB.Connection();

            conn.Open();

            SqlCommand cmd = new SqlCommand("INSERT INTO categories_recipes (categories_id, recipes_id) VALUES (@CategoryId, @RecipeId);", conn);

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

            cmd.Parameters.Add(recipeIdParameter);

            SqlParameter categoryIdParameter = new SqlParameter("@CategoryId", this.GetCategoryId());

            cmd.Parameters.Add(categoryIdParameter);

            cmd.ExecuteNonQuery();

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