Пример #1
0
        private void AddIngredient()
        {
            string name     = CLIHelper.GetString("What is the ingredient");
            string quantity = CLIHelper.GetString($"How much of {name}");
            int    recipeId = CLIHelper.GetInteger("Which recipe is it for");

            Ingredient i = new Ingredient();

            i.Name     = name;
            i.Quantity = quantity;
            i.RecipeId = recipeId;

            IngredientDAL dal = new IngredientDAL(connectionString);

            dal.AddIngredient(i);

            Console.WriteLine("SUCCESS");

            Console.ReadLine();
        }
Пример #2
0
        public void AddIngredientToExistingRecipe()
        {
            // Arrange
            // - Add a Recipe so that we can add ingredients
            //      - Write SQL code to Insert FAKE RECIPE
            int recipeId;

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand("INSERT INTO recipe VALUES ('Fake Recipe', 'Fake Instructions', 'Fake Description', 0);", conn);
                cmd.ExecuteNonQuery();

                //      - Get new recipe Id with SELECT SCOPE_IDENTITY()
                cmd      = new SqlCommand("SELECT CAST(SCOPE_IDENTITY() as int);", conn);
                recipeId = Convert.ToInt32(cmd.ExecuteScalar());
            }
            // - Create an ingredient to add
            Ingredient i = new Ingredient();

            i.Name     = "FAKE INGREDIENT";
            i.Quantity = "FAKE QUANTITY";
            i.RecipeId = recipeId;

            // - Create the ingredient DAL
            IngredientDAL dal = new IngredientDAL(connectionString);

            // Act
            // - Call AddIngredient in the IngredientDAL
            bool output = dal.AddIngredient(i);


            // Assert
            // - Validate we received TRUE from AddIngredient
            Assert.IsTrue(output);
        }