public RecipeController( RecipesRepository recipesRepository, ILogger <RecipeController> logger) { _recipesRepository = recipesRepository; _logger = logger; }
public void PostRecipe_Adds_NewRecipe() { var recipe = new Recipe() { Description = "Test description 1", Id = 1, Name = "Test Recipe Name 1", UserId = "user1" }; var dbOptions = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking) .Options; var someOptions = Options.Create(new OperationalStoreOptions()); using (var context = new ApplicationDbContext(dbOptions, someOptions)) { var recipesRepository = new RecipesRepository(context); recipesRepository.PostRecipe(recipe); }; using (var context = new ApplicationDbContext(dbOptions, someOptions)) { Assert.AreEqual(1, context.Recipes.Count()); Assert.IsTrue(context.Recipes.Contains(recipe)); } }
//Klikniecie w jeden z elementow listy private void ListViewItemClicked(object sender, SelectionChangedEventArgs e) { //listView.SelectedIndex return selected index number FIRST IS 0. None is -1 var recipeWindow = new RecipeWindow(); //Imports data from repository for future use var repositoryInstance = new RecipesRepository(); var repo = repositoryInstance.Retrieve(); try { recipeWindow.Title = repo[listView.SelectedIndex].Nazwa; //Populates the new window fields recipeWindow.recipeNameTextBlock.Text = repo[listView.SelectedIndex].Nazwa; recipeWindow.recipeDescriptionTextBlock.Text = repo[listView.SelectedIndex].Przepis; recipeWindow.recipeDateTextBlock.Text = repo[listView.SelectedIndex].Data.ToString(CultureInfo.InvariantCulture); recipeWindow.ingredientsListView.DataContext = repo[listView.SelectedIndex].Ings; recipeWindow.Show(); recipeWindow.Activate(); } catch (ArgumentException) { } }
static Unit() { _context = new MyAppDbContext("Recipes"); ProductsRepository = new ProductsRepository(_context); RecipesRepository = new RecipesRepository(_context); DishesRepository = new DishesRepository(_context); }
public RecipesService() { _repo = new RecipesRepository(); _Userv = new UserService(); _Ingserv = new IngredientsService(); _Catserv = new CategoryService(); }
public RecipesController( IMapper mapper, RecipesRepository repo) { _mapper = mapper; _repo = repo; }
public async Task SetUp() { _cosmosDbRepositoryTestContext = new CosmosDbRepositoryTestContext(); await _cosmosDbRepositoryTestContext.SetUpAsync(); _repository = new RecipesRepository(Options.Create(_cosmosDbRepositoryTestContext.GetCosmosConfiguration())); }
public App(string dbPath) { InitializeComponent(); RecipesRepo = new RecipesRepository(dbPath); MainPage = new MainPage(); }
public void CreateRecipePutsSomethingInTheDatabase() { var repo = new RecipesRepository(_connectionString); repo.Create("Pineapple on a stick", RecipeType.Desserts); var results = repo.GetAllRecipes(); Assert.That(results.Count, Is.EqualTo(1)); }
public void ReturnsNoUserRecipesWithUnmatchedTag() { var ctx = GetContextWithData(); RecipesRepository recipesRepository = new RecipesRepository(ctx); Assert.Equal(0, recipesRepository.GetAllUserRecipes(secondUserGuid, new List <Guid> { tag4.Id }).Count()); }
public void GetRecipes_Returns_UserRecipes() { var recipe1 = new Recipe() { Description = "Test description 1", Id = 1, Name = "Test Recipe Name 1", UserId = "user1" }; var recipe2 = new Recipe() { Description = "Test description 2", Id = 2, Name = "Test Recipe Name 2", UserId = "user2" }; var recipe3 = new Recipe() { Description = "Test description 3", Id = 3, Name = "Test Recipe Name 3", UserId = "user1" }; var dbOptions = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking) .Options; var someOptions = Options.Create(new OperationalStoreOptions()); using (var context = new ApplicationDbContext(dbOptions, someOptions)) { context.Recipes.Add(recipe1); context.Recipes.Add(recipe2); context.Recipes.Add(recipe3); context.SaveChanges(); } using (var context = new ApplicationDbContext(dbOptions, someOptions)) { var expectedList = new List <Recipe>() { recipe1, recipe2, recipe3 }; var recipesRepository = new RecipesRepository(context); var result = recipesRepository.GetRecipes(); Assert.AreEqual(3, context.Recipes.Count()); Assert.IsTrue(result.Any(r => r.Id == recipe1.Id)); Assert.IsTrue(result.Any(r => r.Id == recipe2.Id)); Assert.IsTrue(result.Any(r => r.Id == recipe3.Id)); }; }
public void ReturnsAllUserRecipesWithNoTags() { var ctx = GetContextWithData(); RecipesRepository recipesRepository = new RecipesRepository(ctx); List <Recipe> expectedList = new List <Recipe> { recipe2 }; recipesRepository.GetAllUserRecipes(secondUserGuid).ShouldBeEquivalentTo(expectedList); }
public void ReturnsOnlyOneRecipeWithFirstTag() { var ctx = GetContextWithData(); RecipesRepository recipesRepository = new RecipesRepository(ctx); List <Recipe> expectedList = new List <Recipe> { recipe1 }; recipesRepository.GetAllPublicPlusUserRecipes(firstUserGuid, new List <Guid> { tag1.Id }).ShouldBeEquivalentTo(expectedList); }
public void CheckIfRecipeRepositoryIsOkTest() { //Arrange var instance = new RecipesRepository(); var repo = instance.Retrieve(); var expected = true; //Act var actual = instance.CheckIfRecipeRepositoryIsOk(repo); //Assert Assert.AreEqual(actual, expected); }
public void CheckInvalidRecipeRepositoryIfFailedTest() { //Arrange var instance = new RecipesRepository(); var repo = instance.RetrieveBadValueRepo(); var expected = false; //Act var actual = instance.CheckIfRecipeRepositoryIsOk(repo); //Assert Assert.AreEqual(actual, expected); }
public void GetRecipe_Returns_ExistingRecipe() { var recipe1 = new Recipe() { Description = "Test description 1", Id = 1, Name = "Test Recipe Name 1", UserId = "user1" }; var recipe2 = new Recipe() { Description = "Test description 2", Id = 2, Name = "Test Recipe Name 2", UserId = "user2" }; var recipe3 = new Recipe() { Description = "Test description 3", Id = 3, Name = "Test Recipe Name 3", UserId = "user1" }; var dbOptions = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking) .Options; var someOptions = Options.Create(new OperationalStoreOptions()); using (var context = new ApplicationDbContext(dbOptions, someOptions)) { context.Recipes.Add(recipe1); context.Recipes.Add(recipe2); context.Recipes.Add(recipe3); context.SaveChanges(); } using (var context = new ApplicationDbContext(dbOptions, someOptions)) { var recipesRepository = new RecipesRepository(context); var result = recipesRepository.GetRecipe(2); Assert.AreEqual(recipe2.Id, result.Id); Assert.AreEqual(recipe2.Description, result.Description); Assert.AreEqual(recipe2.Name, result.Name); } }
public void ReturnsAllRecipesWithNoTags() { var ctx = GetContextWithData(); RecipesRepository recipesRepository = new RecipesRepository(ctx); List <Recipe> expectedList = ctx.Recipes.ToList(); SortByRecipeId(expectedList); List <Recipe> actualList = recipesRepository.GetAllPublicPlusUserRecipes(firstUserGuid).ToList(); SortByRecipeId(actualList); actualList.ShouldBeEquivalentTo(expectedList); }
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 Default_Recipes_Test() { RunOnDatabase(s => { DestroyDatabase(); // Arrange var fridgeRepo = new FridgeRepository(s); var ingredCatRepo = new IngredientsCategoryRepository(s); var ingredientRepo = new IngredientsRepository(s, ingredCatRepo, fridgeRepo); var repository = new RecipesRepository(s, fridgeRepo, ingredientRepo); // 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 GetRecipes_Returns_Empty_When_NoRecipes() { var dbOptions = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking) .Options; var someOptions = Options.Create(new OperationalStoreOptions()); using (var context = new ApplicationDbContext(dbOptions, someOptions)) { var recipesRepository = new RecipesRepository(context); var result = recipesRepository.GetRecipes(); Assert.AreEqual(0, context.Recipes.Count()); Assert.IsEmpty(result); }; }
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 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 ReturnsAllRecipesWithCommonTag() { var ctx = GetContextWithData(); RecipesRepository recipesRepository = new RecipesRepository(ctx); List <Recipe> expectedList = new List <Recipe> { recipe1, recipe2, recipe3 }; SortByRecipeId(expectedList); List <Recipe> actualList = recipesRepository.GetAllPublicPlusUserRecipes(firstUserGuid, new List <Guid> { tag2.Id }).ToList(); SortByRecipeId(actualList); actualList.ShouldBeEquivalentTo(expectedList); }
public void PutRecipe_Updates_Existing_Recipe() { var recipe2 = new Recipe() { Description = "Test description 1 - update", Id = 1, Name = "Test Recipe Name 1 - update", UserId = "user1" }; var dbOptions = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking) .Options; var someOptions = Options.Create(new OperationalStoreOptions()); using (var context = new ApplicationDbContext(dbOptions, someOptions)) { var recipe = new Recipe() { Description = "Test description 1", Id = 1, Name = "Test Recipe Name 1", UserId = "user1" }; context.Recipes.Add(recipe); context.SaveChangesAsync(); context.Entry(recipe).State = EntityState.Detached; var recipesRepository = new RecipesRepository(context); recipesRepository.PutRecipe(recipe2); }; using (var context = new ApplicationDbContext(dbOptions, someOptions)) { Assert.AreEqual(1, context.Recipes.Count()); } }
private void LoadRecipes_Click(object sender, RoutedEventArgs e) { //Makes it visible var path = "C:\\Users\\Roman\\Desktop\\C#\\WpfApp2\\WpfApp2\\Recipes\\recipesRepoFile.txt"; listView.Visibility = 0; var repo = new RecipesRepository(); var list = repo.Retrieve(); var valid = repo.CheckIfRecipeRepositoryIsOk(list); if (valid) { //populates the listview listView.DataContext = list; MessageBox.Show("Succesfully exported recipes from repository into listview"); } else if (new FileInfo(path).Length != 0) { MessageBox.Show("Can't import repository into listview because one of the field is invalid"); } }
public void DeleteRecipe_Deletes_Existing_Recipe() { var recipe1 = new Recipe() { Description = "Test description 1", Id = 1, Name = "Test Recipe Name 1", UserId = "user1" }; var recipe2 = new Recipe() { Description = "Test description 2", Id = 2, Name = "Test Recipe Name 2", UserId = "user2" }; var dbOptions = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking) .Options; var someOptions = Options.Create(new OperationalStoreOptions()); using (var context = new ApplicationDbContext(dbOptions, someOptions)) { context.Recipes.Add(recipe1); context.Recipes.Add(recipe2); context.SaveChanges(); var recipesRepository = new RecipesRepository(context); recipesRepository.DeleteRecipe(recipe2); }; using (var context = new ApplicationDbContext(dbOptions, someOptions)) { Assert.AreEqual(1, context.Recipes.Count()); Assert.IsTrue(context.Recipes.Contains(recipe1)); } }