public void AddsFridgeProduct() { FoodNetDbContext ctx = GetContextWithData(); FridgeRepository fridgeRepository = new FridgeRepository(ctx); int firstFridgeProductsCountBefore = ctx.FridgeProducts.Where(fp => fp.FridgeId.Equals(fridge1.Id)).Count(); fridgeRepository.AddProduct(fridge1Product1); int firstFridgeProductsCountAfter = ctx.FridgeProducts.Where(fp => fp.FridgeId.Equals(fridge1.Id)).Count(); Assert.Equal(firstFridgeProductsCountBefore + 1, firstFridgeProductsCountAfter); }
public void Default_Ingredients_Test() { RunOnDatabase(s => { DestroyDatabase(); // Arrange var fridgeRepo = new FridgeRepository(s); var ingredCatRepo = new IngredientsCategoryRepository(s); var repository = new IngredientsRepository(s, ingredCatRepo, fridgeRepo); // Act // Assert Assert.IsTrue(true); }); }
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 void GetByVotesNumber_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); var recipeRepo = new RecipesRepository(s, fridgeRepo, ingredRepo); // Act Populate(s); var res = await recipeRepo.GetByVotesNumber(4, recipeRepo.GetAll()); // Assert Assert.IsTrue(0 == res.ToList().Count); }); }
public void ContainsIngredient_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); var recipeRepo = new RecipesRepository(s, fridgeRepo, ingredRepo); // Act Populate(s); var res = await recipeRepo.ContainsIngredient(recipeRepo.GetByName("r1", recipeRepo.GetAll()).Result.First().Id, ingredRepo.GetByName("i1").Result.First().Id); // Assert Assert.IsTrue(res); }); }
public void GetByPreparationTime_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); var recipeRepo = new RecipesRepository(s, fridgeRepo, ingredRepo); // Act Populate(s); var res = await recipeRepo.GetByPrepatationTime(25, recipeRepo.GetAll()); // Assert Assert.AreEqual(1, res.ToList().Count); }); }
public void Given_Repository_When_Get_By_Ingredient_ShouldBe_Correct() { RunOnDatabase(async s => { DestroyDatabase(); // Arrange var fridgeRepos = new FridgeRepository(s); var categoryRepo = new IngredientsCategoryRepository(s); var ingredientRepo = new IngredientsRepository(s, categoryRepo, fridgeRepos); var recipeRepo = new RecipesRepository(s, fridgeRepos, ingredientRepo); // Act Populate(s); var data = await fridgeRepos.GetByIngredient(ingredientRepo.GetByName("i1").Result.First().Id); // Assert Assert.AreEqual(2, data.ToList().Count); }); }
public void Given_Repository_When_Delete_Then_ShouldBe_Correct() { RunOnDatabase(async s => { DestroyDatabase(); // Arrange var repository = new FridgeRepository(s); var pairItem = GetPairItems().First(); // Act await repository.Add(pairItem); var pairAdded = repository.Get(pairItem.IngredientId, pairItem.RecipieId).Result; await repository.Delete(pairAdded.IngredientId, pairAdded.RecipieId); // Assert var data = repository.GetAll(); Assert.AreEqual(0, data.Result.ToList().Count); }); }
public void GetByOnlyIngredients_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); var recipeRepo = new RecipesRepository(s, fridgeRepo, ingredRepo); // Act Populate(s); List <Ingredient> igToAdd = new List <Ingredient>(); igToAdd.Add(ingredRepo.GetByName("i1").Result.First()); var res = await recipeRepo.GetByOnlyIngredients(igToAdd, recipeRepo.GetAll()); // Assert Assert.AreEqual(1, res.ToList().Count); }); }
public void ExcludesIngredients_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); var recipeRepo = new RecipesRepository(s, fridgeRepo, ingredRepo); // Act Populate(s); List <Ingredient> igToAdd = new List <Ingredient>(); igToAdd.Add(ingredRepo.GetByName("i1").Result.First()); var res = await recipeRepo.ExcludesTheseIngredients(recipeRepo.GetByName("r1", recipeRepo.GetAll()).Result.First().Id, igToAdd); // Assert Assert.AreEqual(false, res); }); }
public void AddIngredientCustom_ShouldWork() { RunOnDatabase(async s => { DestroyDatabase(); // Arrange var fridgeRepo = new FridgeRepository(s); var ingredCatRepo = new IngredientsCategoryRepository(s); var ingredRepo = new IngredientsRepository(s, ingredCatRepo, fridgeRepo); var recipeRepo = new RecipesRepository(s, fridgeRepo, ingredRepo); IEnumerable <IngredientCategory> categories = GetDefaultCategories(); // Act Populate(s); int count = ingredRepo.GetAll().Result.Count(); await ingredRepo.AddIngredientCustom(recipeRepo.GetAll().Result.First().Id, "t", "ms", "new", 1, 1, 1); await ingredRepo.AddIngredientCustom(recipeRepo.GetAll().Result.First().Id, "First Category", "i3", "cup", 1, 1, 1); //await ingredRepo.AddIngredientCustom(recipeRepo.GetAll().Result.First().Id, "Another Category", "i3", "cup", 1, 1, 1); await ingredRepo.AddIngredientCustom(recipeRepo.GetAll().Result.First().Id, "asfasfasfasfy", "i5", "cup", 1, 1, 1); // Assert Assert.AreEqual(count + 3, ingredRepo.GetAll().Result.Count()); }); }
public void GetSpecificCategory_ShouldWork() { RunOnDatabase(async s => { DestroyDatabase(); // Arrange var fridgeRepo = new FridgeRepository(s); var ingredCatRepo = new IngredientsCategoryRepository(s); var ingredRepo = new IngredientsRepository(s, ingredCatRepo, fridgeRepo); var recipeRepo = new RecipesRepository(s, fridgeRepo, ingredRepo); IEnumerable <IngredientCategory> categories = GetDefaultCategories(); // Act Populate(s); await ingredRepo.AddIngredientCustom(recipeRepo.GetAll().Result.First().Id, "asfasfasfasfy", "cup", "i5", 1, 1, 1); await ingredRepo.AddIngredientCustom(recipeRepo.GetAll().Result.First().Id, "other-ingredients", "cup", "i6", 1, 1, 1); var res = await ingredRepo.GetSpecificCategory("i5"); var res2 = await ingredRepo.GetSpecificCategory("i6"); var res1 = await ingredRepo.GetSpecificCategory("null"); // Assert Assert.AreEqual(res, ingredCatRepo.GetByName("asfasfasfasfy").Result.Id); Assert.AreEqual(res2, null); Assert.AreEqual(null, res1); }); }
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); }); }
public void GetByFilter_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); var recipeRepo = new RecipesRepository(s, fridgeRepo, ingredRepo); // Act Populate(s); var filtru = new Filter(); //var res = await recipeRepo.GetByFilter(filtru); filtru.Name = "r1"; filtru.Cuisine = KitchenType.Asian; filtru.PreparationTime = 10; var res = await recipeRepo.GetByFilter(filtru); // Assert Assert.AreEqual(1, res.ToList().Count); }); }