public IHttpActionResult GetMyFavorites([FromUri] string id)
        {
            UserRecipeService userRecipeService = CreateUserRecipeService();
            var userRecipe = userRecipeService.GetMyFavoritesByUserId(id);

            return(Ok(userRecipe));
        }
        private UserRecipeService CreateUserRecipeService()
        {
            var userId            = Guid.Parse(User.Identity.GetUserId());
            var userRecipeService = new UserRecipeService(userId);

            return(userRecipeService);
        }
Exemple #3
0
        public void GetAllRecipes_WithSomeRecipes_ShouldReturnAll()
        {
            //Arrange
            this.DbContext.Recipes.Add(new Recipe()
            {
                Id = 1, Title = "First recipe"
            });
            this.DbContext.Recipes.Add(new Recipe()
            {
                Id = 2, Title = "Second recipe"
            });
            this.DbContext.Recipes.Add(new Recipe()
            {
                Id = 3, Title = "Third recipe"
            });

            this.DbContext.SaveChanges();

            var service = new UserRecipeService(this.DbContext, this.Mapper, null);

            //Act
            var recipes = service.GetAllRecipes();

            //Assert
            Assert.IsNotNull(recipes);
            Assert.AreEqual(3, recipes.Count());
            CollectionAssert.AreEqual(new[] { 1, 2, 3 }, recipes.Select(c => c.Id).ToArray());
        }
Exemple #4
0
        public void GetRecipe_WithNonExistingId_ReturnsNull()
        {
            //Arrange
            this.DbContext.Recipes.Add(new Recipe()
            {
                Id = 1, Title = "First recipe"
            });
            this.DbContext.SaveChanges();

            var service = new UserRecipeService(this.DbContext, this.Mapper, null);

            //Act
            var recipe = service.GetRecipe(200);

            //Assert
            Assert.IsNull(recipe);
        }
Exemple #5
0
        public void CreateRecipe_WithModelAndUser_AddsRecipeToDb()
        {
            //Arrange
            var userId = Guid.NewGuid().ToString();
            var model  = new RecipeCreationBindingModel()
            {
                Id           = 1,
                Title        = "SomeRecipe",
                Instructions = "IntructionsIntructionsIntructionsIntructionsIntructions",
                CategoryId   = 1
            };
            var service = new UserRecipeService(this.DbContext, this.Mapper, null);

            //Act
            service.CreateRecipe(model, userId);

            //Assert
            Assert.AreEqual(1, this.DbContext.Recipes.Count());
        }
Exemple #6
0
        public void GetRecipe_WithExistingId_ReturnsRecipe()
        {
            //Arrange
            this.DbContext.Recipes.Add(new Recipe()
            {
                Id = 1, Title = "First recipe"
            });
            this.DbContext.SaveChanges();

            var service = new UserRecipeService(this.DbContext, this.Mapper, null);

            //Act
            var recipe = service.GetRecipe(1);

            //Assert
            Assert.IsNotNull(recipe);
            Assert.AreEqual(1, recipe.Id);
            Assert.AreEqual("First recipe", recipe.Title);
        }