private void AddRecipesToContext(List <Recipe> recipes) { foreach (var recipe in recipes) { RecipeManagerContextHelper.AddRecipe(_recipeManagerContext, recipe); } }
public void UpdateRecipe_ChangesRecipeToExpected() { var recipe = new Recipe { Id = 1, IsPublic = true, IsShared = true, }; RecipeManagerContextHelper.AddRecipe(_recipeManagerContext, recipe); RecipeManagerContextHelper.DetachAllEntities(_recipeManagerContext); var expectedRecipe = new Recipe { Id = 1, ChangedDate = DateTime.Now, CreatedDate = DateTime.Now, Description = "description of recipe", Ingredients = new List <Ingredient>(), Instructions = new List <Instruction>(), IsPublic = true, IsShared = true, SharedWith = new List <RecipeUser>(), Name = "recipe name" }; _recipeRepository.UpdateRecipe(expectedRecipe, true); var result = _recipeRepository.GetRecipeById(expectedRecipe.Id); Assert.AreEqual(expectedRecipe, result); }
public void GetRecipesForUser_ReturnsExpected() { var user = new User { Id = 2 }; RecipeManagerContextHelper.AddUser(_recipeManagerContext, user); var expectedRecipes = new List <Recipe> { new Recipe { Id = 1, UserId = "2", IsPublic = true, }, new Recipe { Id = 45, IsShared = true, SharedWith = new List <RecipeUser>() } }; expectedRecipes.Last().SharedWith.Add(new RecipeUser { User = user, Recipe = expectedRecipes.Last() }); AddRecipesToContext(expectedRecipes); var result = _recipeRepository.GetRecipesForUser("2"); AssertEachRecipeExists(expectedRecipes, result); }
public void FavoriteRecipe_DoesNotAddUserIfAlreadyAdded() { var user = new User { Id = 2 }; RecipeManagerContextHelper.AddUser(_recipeManagerContext, user); var recipe = new Recipe { Id = 1, IsPublic = true, IsShared = true, SharedWith = new List <RecipeUser>() }; recipe.SharedWith.Add(new RecipeUser { User = user, Recipe = recipe }); RecipeManagerContextHelper.AddRecipe(_recipeManagerContext, recipe); _recipeRepository.FavoriteRecipe(recipe.Id, user.Id.ToString(), true); var result = _recipeRepository.GetRecipeById(recipe.Id); Assert.AreEqual(recipe.SharedWith.First().Id, result.SharedWith.First().Id); Assert.AreEqual(recipe.IsShared, result.IsShared); }
public void GetRating_ReturnsExpected() { var expectedRate = new Rating { UserId = "1", RecipeId = 1 }; RecipeManagerContextHelper.AddRating(_recipeManagerContext, expectedRate); var result = _rateRepository.Get(expectedRate.UserId, expectedRate.RecipeId); Assert.AreEqual(expectedRate, result); }
public void GetUser_ReturnsExpected() { var expectedUser = new User { Id = 1, AuthId = "authO|43124214321" }; RecipeManagerContextHelper.AddUser(_recipeManagerContext, expectedUser); var result = _userRepository.GetByAuthId(expectedUser.AuthId); Assert.AreEqual(expectedUser, result); }
public void DeleteRecipe_RemovesExpectedRecipe() { var recipe = new Recipe { Id = 1, IsPublic = true, IsShared = true, }; RecipeManagerContextHelper.AddRecipe(_recipeManagerContext, recipe); RecipeManagerContextHelper.DetachAllEntities(_recipeManagerContext); _recipeRepository.DeleteRecipe(recipe, true); var result = _recipeRepository.GetRecipeById(recipe.Id); Assert.IsNull(result); }
public void FavoriteRecipe_AddsUserToSharedWith() { var user = new User { Id = 2 }; RecipeManagerContextHelper.AddUser(_recipeManagerContext, user); var recipe = new Recipe { Id = 1, IsPublic = true, IsShared = false, SharedWith = null }; var expectedRecipe = new Recipe { Id = 1, IsPublic = true, IsShared = true, SharedWith = new List <RecipeUser>() }; expectedRecipe.SharedWith.Add(new RecipeUser { User = user, Recipe = expectedRecipe }); RecipeManagerContextHelper.AddRecipe(_recipeManagerContext, recipe); _recipeRepository.FavoriteRecipe(recipe.Id, user.Id.ToString(), true); var result = _recipeRepository.GetRecipeById(recipe.Id); Assert.AreEqual(expectedRecipe.SharedWith.First().User.Id, result.SharedWith.First().User.Id); Assert.AreEqual(expectedRecipe.SharedWith.First().Recipe.Id, result.SharedWith.First().Recipe.Id); Assert.AreEqual(expectedRecipe.IsShared, result.IsShared); }
public void UnFavoriteRecipe_RemovesUserFromSharedWith() { var user = new User { Id = 2 }; RecipeManagerContextHelper.AddUser(_recipeManagerContext, user); var recipe = new Recipe { Id = 1, IsPublic = true, IsShared = true, SharedWith = new List <RecipeUser>() }; recipe.SharedWith.Add(new RecipeUser { User = user, Recipe = recipe }); var expectedRecipe = new Recipe { Id = 1, IsPublic = true, IsShared = false, SharedWith = new List <RecipeUser>() }; RecipeManagerContextHelper.AddRecipe(_recipeManagerContext, recipe); _recipeRepository.UnFavoriteRecipe(recipe.Id, user.Id.ToString(), true); var result = _recipeRepository.GetRecipeById(recipe.Id); Assert.AreEqual(expectedRecipe.SharedWith.Count, result.SharedWith.Count); Assert.AreEqual(expectedRecipe.IsShared, result.IsShared); }
public void GetAll_ReturnsExpected() { var expectedRates = new List <Rating> { new Rating { UserId = "1", RecipeId = 1, }, new Rating { UserId = "2", RecipeId = 2, } }; RecipeManagerContextHelper.AddRating(_recipeManagerContext, expectedRates.First()); RecipeManagerContextHelper.AddRating(_recipeManagerContext, expectedRates.Last()); var result = _rateRepository.GetAll(); Assert.AreEqual(expectedRates, result); }
public void GetRecipe_ReturnsExpected() { var expectedRecipe = new Recipe { Id = 1, ChangedDate = DateTime.Now, CreatedDate = DateTime.Now, TimeToCook = 10, Description = "description of recipe", Ingredients = new List <Ingredient> { new Ingredient { Id = 1, Value = "Cheese" } }, Instructions = new List <Instruction> { new Instruction { Id = 1, Value = "Add Cheese" } }, IsPublic = true, IsShared = true, SharedWith = new List <RecipeUser>(), Name = "recipe name" }; RecipeManagerContextHelper.AddRecipe(_recipeManagerContext, expectedRecipe); var result = _recipeRepository.GetRecipeById(expectedRecipe.Id); AssertRecipeCorrect(expectedRecipe, result); }
public void SetUp() { _recipeManagerContext = RecipeManagerContextHelper.CreateTestContext(); _recipeRepository = new RecipeRepository(_recipeManagerContext); }