Exemple #1
0
 private void AddRecipesToContext(List <Recipe> recipes)
 {
     foreach (var recipe in recipes)
     {
         RecipeManagerContextHelper.AddRecipe(_recipeManagerContext, recipe);
     }
 }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        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);
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        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);
        }
Exemple #9
0
        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);
        }
Exemple #10
0
        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);
        }
Exemple #11
0
        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);
        }
Exemple #12
0
 public void SetUp()
 {
     _recipeManagerContext = RecipeManagerContextHelper.CreateTestContext();
     _recipeRepository     = new RecipeRepository(_recipeManagerContext);
 }