Exemple #1
0
        public static async void Populate(DatabaseContext s)
        {
            var categoryRepo = new IngredientsCategoryRepository(s);
            IEnumerable <IngredientCategory> categories = GetDefaultCategories();

            foreach (var ingredientCategory in categories)
            {
                await categoryRepo.Add(ingredientCategory);
            }
            var fridgeRepos    = new FridgeRepository(s);
            var ingredientRepo = new IngredientsRepository(s, categoryRepo, fridgeRepos);
            var recipeRepo     = new RecipesRepository(s, fridgeRepos, ingredientRepo);

            Ingredient i1   = Ingredient.Create(categories.First().Id, "i1", "cup", 0.9);
            Ingredient i2   = Ingredient.Create(categories.First().Id, "i2", "piece", 1.9);
            Ingredient i3   = Ingredient.Create(categories.First().Id, "i3", "slice", 0.5);
            Ingredient i4   = Ingredient.Create(categories.First().Id, "i3", "cup", 30);
            User       user = User.Create("xx", true, "*****@*****.**", "sh", "sdsbdk", "sureal");

            var userRepo = new UsersRepository(s);
            await userRepo.Add(user);

            await ingredientRepo.Add(i1);

            await ingredientRepo.Add(i2);

            await ingredientRepo.Add(i3);

            await ingredientRepo.Add(i4);

            Recipe recipe1 = Recipe.Create(user.Id, "r1", "reteta", RecipeStatusType.Approved, 10, 1, KitchenType.Asian);
            Recipe recipe2 = Recipe.Create(user.Id, "r2", "reteta2", RecipeStatusType.Approved, 15, 2, KitchenType.Unspecified);
            await recipeRepo.Add(recipe1);

            await recipeRepo.Add(recipe2);

            await recipeRepo.UpdateAllCosts();

            await fridgeRepos.Add(PairItem.Create(i1.Id, recipe1.Id, 2));

            await fridgeRepos.Add(PairItem.Create(i2.Id, recipe1.Id, 4));

            await fridgeRepos.Add(PairItem.Create(i3.Id, recipe1.Id, 1));

            await fridgeRepos.Add(PairItem.Create(i1.Id, recipe2.Id, 3));
        }
        public ActionResult Create([Bind(Include = "Id,Name,Quantity,Receipts_Id")] Ingredient ingredient)
        {
            if (ModelState.IsValid)
            {
                IngredientRepo.Add(ingredient);
                return(RedirectToAction("Index"));
            }

            return(View(ingredient));
        }
Exemple #3
0
        public void Exists_Should_Work_Ok()
        {
            RunOnDatabase(async s =>
            {
                DestroyDatabase();
                // Arrange
                var fridgeRepo    = new FridgeRepository(s);
                var ingredCatRepo = new IngredientsCategoryRepository(s);
                var ingredRepo    = new IngredientsRepository(s, ingredCatRepo, fridgeRepo);
                IEnumerable <IngredientCategory> categories = GetDefaultCategories();
                // Act
                foreach (var ingredientCategory in categories)
                {
                    await ingredCatRepo.Add(ingredientCategory);
                }
                await ingredRepo.Add(Ingredient.Create(ingredCatRepo.GetAll().Result.First().Id, "onion", "piece", 1.2));

                // Assert
                Boolean bool1 = ingredRepo.Exists("onion").Result;
                Boolean bool2 = ingredRepo.Exists("onion", "piece").Result;
                Boolean bool3 = ingredRepo.Exists("onion", "slice").Result;
                Assert.IsTrue(bool1 && bool2 && !bool3);
            });
        }
Exemple #4
0
 public void Add(Ingredient ingredient)
 {
     _repo.Add(ingredient);
 }