Пример #1
0
        public async Task <IActionResult> SearchRecipe(SearchRecipeViewModel viewModel)
        {
            if (viewModel.RecipeType == "Fara restrictii")
            {
                viewModel.RecipeType = "Normal";
            }
            var results = await _searchRecipeService.SearchRecipeAsync(viewModel.SearchTerm, viewModel.RecipeType);

            return(View(new SearchRecipeViewModel
            {
                SearchTerm = viewModel.SearchTerm,
                Results = results,
            }));
        }
Пример #2
0
        public ActionResult Index()
        {
            var recipes = this.recipesService.GetAllRecipes()
                          .Select(this.mappingService.Map <RecipeViewModel>)
                          .ToList();

            var searchModel = new SearchRecipeViewModel();

            if (recipes != null)
            {
                searchModel.Recipes      = recipes;
                searchModel.PageSize     = gridPageSize;
                searchModel.TotalRecords = recipes.Count();
            }

            return(this.View(searchModel));
        }
Пример #3
0
        public ActionResult Search(string title)
        {
            var recipes = this.recipesService.GetAllRecipes()
                          .Where(x => x.Title.ToLower().Contains(title.ToLower()))
                          .Select(this.mappingService.Map <RecipeViewModel>)
                          .ToList();

            var searchModel = new SearchRecipeViewModel();

            if (recipes != null)
            {
                searchModel.Recipes      = recipes;
                searchModel.PageSize     = gridPageSize;
                searchModel.TotalRecords = recipes.Count();
            }

            return(this.PartialView("_RecipesGridPartial", searchModel));
        }
Пример #4
0
        public void RenderTheRightPartialViewWithTheCorrectModel_SearchRecipeViewModelAndNoModelErrorsAndCorrectContent()
        {
            //Arrange
            var        inredientsServiceMock     = new Mock <IIngredientsService>();
            var        foodCategoriesServiceMock = new Mock <IFoodCategoriesService>();
            var        recipesServiceMock        = new Mock <IRecipesService>();
            var        mappingServiceMock        = new Mock <IMappingService>();
            var        controller   = new RecipesController(recipesServiceMock.Object, inredientsServiceMock.Object, foodCategoriesServiceMock.Object, mappingServiceMock.Object);
            Guid       ingredientId = Guid.NewGuid();
            Ingredient ingredient   = new Ingredient()
            {
                Id = ingredientId, Name = "IngredientName", PricePerMeasuringUnit = 12.60m, QuantityInMeasuringUnit = 0
            };
            List <Ingredient> ingredients = new List <Ingredient>()
            {
                ingredient
            };

            inredientsServiceMock.Setup(x => x.GetAllIngredients()).Returns(ingredients);

            List <string> ingredientNames = new List <string>()
            {
                "Tomato"
            };
            List <double> ingredientQuantities = new List <double>()
            {
                1.200
            };
            List <decimal> ingredientPrices = new List <decimal>()
            {
                4.80m
            };
            List <Guid> foodCategories = new List <Guid>()
            {
                Guid.NewGuid()
            };

            Guid   recipeId       = Guid.NewGuid();
            Guid   foodCategoryId = Guid.NewGuid();
            Recipe recipe         = new Recipe()
            {
                Id          = recipeId,
                Title       = "Title Of A New Recipe",
                Describtion = "This is a decsribtion",
                Instruction = "Instructions of the recipe",
                DishType    = DishType.MainDish,
                Ingredients = ingredients
            };

            var recipes = new List <RecipeViewModel>()
            {
                new RecipeViewModel()
                {
                    Title       = recipe.Title,
                    Describtion = recipe.Describtion,
                    Ingredients = new List <IngredientViewModel>()
                    {
                        new IngredientViewModel()
                        {
                            Name           = ingredient.Name,
                            RecipeId       = recipeId,
                            FoodCategoryId = foodCategoryId
                        }
                    },
                    DishType    = recipe.DishType,
                    Instruction = recipe.Instruction
                }
            };


            var searchModel = new SearchRecipeViewModel()
            {
                PageSize     = 5,
                TotalRecords = recipes.Count,
                Recipes      = recipes
            };

            string title = "Title Of A New Recipe";

            //Act & Assert
            controller.WithCallTo(x => x.Search(title))
            .ShouldRenderPartialView("_RecipesGridPartial")
            .WithModel <SearchRecipeViewModel>(
                viewModel => Assert.AreEqual(recipes.ToList()[0].Title, searchModel.Recipes.ToList()[0].Title))
            .AndNoModelErrors();
        }