Exemplo n.º 1
0
        public void LookupByTitleTest()
        {
            Ingredient a    = new Ingredient("name1", "description1", 123, "gr");
            Ingredient b    = new Ingredient("name2", "description2", 456, "kg");
            Recipe     food = new Recipe(
                "kabab",
                "charkh karde",
                new Ingredient[] { a },
                3,
                "irani",
                new string[] { "irani", "kabab" }
                );
            Recipe food1 = new Recipe(
                "joje",
                "kabab karde",
                new Ingredient[] { b },
                2,
                "irani",
                new string[] { "irani", "joje" }
                );
            RecipeBook book = new RecipeBook("recipeBook", 2);

            book.Add(food);
            book.Add(food1);
            Assert.AreEqual(food, book.LookupByTitle(food.Title));
        }
Exemplo n.º 2
0
        public void AddTest()
        {
            Ingredient a    = new Ingredient("name1", "description1", 123, "gr");
            Ingredient b    = new Ingredient("name2", "description2", 456, "kg");
            Recipe     food = new Recipe(
                "kabab",
                "charkh karde",
                new Ingredient[] { a },
                3,
                "irani",
                new string[] { "irani", "kabab" }
                );
            Recipe food1 = new Recipe(
                "joje",
                "kabab karde",
                new Ingredient[] { b },
                2,
                "irani",
                new string[] { "irani", "joje" }
                );
            RecipeBook book = new RecipeBook("recipeBook", 1);

            Assert.IsTrue(book.Add(food));
            Assert.IsFalse(book.Add(food1));
        }
Exemplo n.º 3
0
        public void LookupByCuisineTest()
        {
            Ingredient a    = new Ingredient("name1", "description1", 123, "gr");
            Ingredient b    = new Ingredient("name2", "description2", 456, "kg");
            Recipe     food = new Recipe(
                "kabab",
                "charkh karde",
                new Ingredient[] { a },
                3,
                "irani",
                new string[] { "irani", "kabab" }
                );
            Recipe food1 = new Recipe(
                "joje",
                "kabab karde",
                new Ingredient[] { b },
                2,
                "irani",
                new string[] { "irani", "joje" }
                );
            RecipeBook book = new RecipeBook("recipeBook", 2);

            book.Add(food);
            book.Add(food1);
            Assert.IsTrue(new Recipe[] { food, food1 }.SequenceEqual(book.LookupByCuisine("irani")));
        }
Exemplo n.º 4
0
        public void RemoveByKeywordTest()
        {
            RecipeBook        recipeBook = new RecipeBook("reBook", 2);
            Ingredient        ing        = new Ingredient("name", "desc", 2.5, "kg");
            Ingredient        ing1       = new Ingredient("name1", "desc1", 21.5, "kg");
            List <Ingredient> ings2      = new List <Ingredient>();

            ings2.Add(ing);
            ings2.Add(ing1);
            Recipe recipe = new Recipe("title", "instructions", ings2, 3, "cuisine", new string[] { "title", "iranian" });

            recipeBook.Add(recipe);
            recipeBook.Add(recipe);
            using (StreamWriter writer = new StreamWriter(@"reader5.txt"))
            {
                var a = Console.Out;
                Console.SetOut(writer);
                Console.WriteLine("title");
                Console.SetOut(a);
            }
            using (StreamReader reader = new StreamReader(@"reader5.txt"))
            {
                Console.SetIn(reader);
                Recipe[] recipeKeyword = Program.RemoveByKeyword(recipeBook);
                for (int i = 0; i < recipeKeyword.Length && recipeKeyword[i] != null; i++)
                {
                    Assert.AreEqual(recipeKeyword[i].Title, "title");
                }
            }
        }
Exemplo n.º 5
0
        public void DeserializeTest()
        {
            Ingredient ing;

            ing = new Ingredient("name", "desc", 6.0, "kg");
            List <Ingredient> ings = new List <Ingredient>();

            ings.Add(ing);
            Recipe recipetest;
            Recipe recipetest2;

            recipetest = new Recipe("recipetitle", "use with water", ings, 1, "iranian", new string[] { "iran", "food" });
            recipetest.IngredientCount = 1;
            RecipeBook reBook;

            reBook = new RecipeBook("rebook", 1);
            reBook.Add(recipetest);
            using (StreamWriter writer = new StreamWriter(@"recipse.txt"))
            {
                recipetest.Serialize(writer, @"ing3.txt");
            }
            using (StreamReader reader = new StreamReader(@"recipse.txt"))
            {
                recipetest2 = Recipe.Deserialize(reader, @"recipse.txt", @"ing3.txt");
            }
            //Assert.AreEqual(recipetest.Cuisine, recipetest2.Cuisine);
        }
Exemplo n.º 6
0
        public void RemoveByTitleTest()
        {
            RecipeBook        recipeBook = new RecipeBook("reBook", 2);
            Ingredient        ing        = new Ingredient("name", "desc", 2.5, "kg");
            List <Ingredient> ings2      = new List <Ingredient>();

            ings2.Add(ing);
            Recipe recipe = new Recipe("title", "instructions", ings2, 3, "cuisine", new string[] { "keywords", "iranian" });

            recipeBook.Add(recipe);
            using (StreamWriter writer = new StreamWriter(@"reader4.txt"))
            {
                var a = Console.Out;
                Console.SetOut(writer);
                Console.WriteLine("title");
                Console.SetOut(a);
            }

            using (StreamReader reader = new StreamReader(@"reader4.txt"))
            {
                Console.SetIn(reader);
                Recipe recipeTitle = Program.RemoveByTitle(recipeBook);
                Assert.AreEqual(recipeTitle.Title, "title");
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// creates a new recipe
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnNew_Click(object sender, RoutedEventArgs e)
        {
            RecipeForm frm = new RecipeForm();

            frm.ShowDialog();
            recipes.Add(frm.recipes);
            recipeBook.Add(recipes[i]);
            i++;
            if (!WindowsIsOpen("Add_Recipe"))
            {
                ListBoxReset();
            }
        }
Exemplo n.º 8
0
        public void LoadRecipesTest()
        {
            RecipeBook        recipeBook  = new RecipeBook("reBook", 1);
            RecipeBook        recipeBook1 = new RecipeBook("reBook1", 1);
            Ingredient        ing         = new Ingredient("name", "desc", 2.5, "kg");
            List <Ingredient> ings2       = new List <Ingredient>();

            ings2.Add(ing);
            Recipe recipe = new Recipe("title", "instructions", ings2, 3, "cuisine", new string[] { "keywords", "iranian" });

            recipeBook.Add(recipe);
            Assert.IsFalse(Program.LoadRecipes(ref recipeBook1, @"asdasd.txt", @"dsadsa.txt"));
            recipeBook.Save(@"recipe.txt", @"ingredient.txt");
            Assert.IsTrue(Program.LoadRecipes(ref recipeBook1, @"recipe.txt", @"ingredient.txt"));
        }
Exemplo n.º 9
0
 public void AddTest()
 {
     Assert.IsTrue(recipeBook.Add(recipe));
     recipeBook.Add(recipe);
     Assert.IsTrue(recipeBook.Add(recipe));
 }