public void RedirectToActionIndex_WithTheCorrectModel__WhenModelStateIsValid()
        {
            //Arrange
            var dailyMenusServiceMock = new Mock <IDailyMenuService>();
            var recipesServiceMock    = new Mock <IRecipesService>();
            var mappingServiceMock    = new Mock <IMappingService>();

            var       controller = new DailyMenusController(recipesServiceMock.Object, dailyMenusServiceMock.Object, mappingServiceMock.Object);
            Guid      id         = Guid.NewGuid();
            DateTime  date       = DateTime.Today;
            DayOfWeek dayOfWeek  = date.DayOfWeek;
            var       recipeId   = Guid.Empty;
            var       recipesIds = new List <Guid>()
            {
                recipeId
            };

            DailyMenu dailyMenu = new DailyMenu()
            {
                Id        = id,
                Date      = date,
                DayOfWeek = dayOfWeek
            };

            DailyMenuViewModel dailyMenuViewModel = new DailyMenuViewModel()
            {
                Id        = dailyMenu.Id,
                Date      = dailyMenu.Date,
                DayOfWeek = dailyMenu.DayOfWeek
            };
            var selectedMenu = dailyMenuViewModel;
            var allMenus     = new AddDailyMenuViewModel();
            var dailyMenus   = new List <DailyMenu>();

            dailyMenusServiceMock.Setup(x => x.GetDailyMenuById(id)).Returns(dailyMenu);
            dailyMenusServiceMock.Setup(x => x.GetAllDailyMenus()).Returns(dailyMenus);
            mappingServiceMock.Setup(x => x.Map <DailyMenuViewModel>(dailyMenu)).Returns(dailyMenuViewModel);
            mappingServiceMock.Setup(x => x.Map <AddDailyMenuViewModel>(dailyMenus)).Returns(allMenus);
            var model = new EditDailyMenuViewModel()
            {
                Id           = id,
                SelectedDate = DateTime.Today,
                SelectedDailyMenuViewModel       = selectedMenu,
                DailyMenuViewModelWithAllRecipes = allMenus
            };

            //Act & Assert
            controller.WithCallTo(x => x.EditDailyMenu(id))
            .ShouldRenderView("EditDailyMenu");

            //Act & Assert
            controller.WithCallTo(x => x.EditDailyMenu(id, date, recipesIds))
            .ShouldRedirectTo(x => x.Index());
        }
Example #2
0
        public void RedirectToActionIndex__WhenDailyMenuIsSuccessfullyDeleted()
        {
            //Arrange
            var dailyMenusServiceMock = new Mock <IDailyMenuService>();
            var recipesServiceMock    = new Mock <IRecipesService>();
            var mappingServiceMock    = new Mock <IMappingService>();

            var       controller = new DailyMenusController(recipesServiceMock.Object, dailyMenusServiceMock.Object, mappingServiceMock.Object);
            var       id         = Guid.NewGuid();
            DateTime  date       = DateTime.Today;
            DayOfWeek dayOfWeek  = date.DayOfWeek;

            DailyMenu dailyMenu = new DailyMenu()
            {
                Id        = id,
                Date      = date,
                DayOfWeek = dayOfWeek
            };

            dailyMenusServiceMock.Setup(x => x.GetDailyMenuById(id)).Returns(dailyMenu);
            dailyMenusServiceMock.Setup(x => x.DeleteDailyMenu(dailyMenu));

            //Act & Assert
            controller.WithCallTo(x => x.DeleteDailyMenuConfirm(id))
            .ShouldRedirectTo(x => x.Index());
        }
        public void RenderTheRightView_AddDailyMenu_WhenModelStateIsNotValid()
        {
            //Arrange
            var dailyMenusServiceMock = new Mock <IDailyMenuService>();
            var recipesServiceMock    = new Mock <IRecipesService>();
            var mappingServiceMock    = new Mock <IMappingService>();

            var controller = new DailyMenusController(recipesServiceMock.Object, dailyMenusServiceMock.Object, mappingServiceMock.Object);

            var date       = DateTime.Today;
            var recipeId   = Guid.Empty;
            var recipesIds = new List <Guid>()
            {
                recipeId
            };
            var model = new { date, recipesIds };

            var validationContext = new ValidationContext(model, null, null);
            var validationResults = new List <ValidationResult>();

            Validator.TryValidateObject(model, validationContext, validationResults, true);
            foreach (var validationResult in validationResults)
            {
                controller.ModelState.AddModelError(validationResult.MemberNames.First(), validationResult.ErrorMessage);
            }

            //Act & Assert
            controller.WithCallTo(x => x.AddDailyMenu())
            .ShouldRenderView("AddDailyMenu");
        }
Example #4
0
        public void RenderTheRightView()
        {
            //Arrange
            var dailyMenusServiceMock = new Mock <IDailyMenuService>();
            var recipesServiceMock    = new Mock <IRecipesService>();
            var mappingServiceMock    = new Mock <IMappingService>();

            var controller = new DailyMenusController(recipesServiceMock.Object, dailyMenusServiceMock.Object, mappingServiceMock.Object);

            //Act & Assert
            controller.WithCallTo(x => x.Index())
            .ShouldRenderView("Index");
        }
Example #5
0
        public void DeleteDailyMenu_Should_RedirectToErrorPage_When_IdGuidIsNotValid()
        {
            var dailyMenusServiceMock = new Mock <IDailyMenuService>();
            var recipesServiceMock    = new Mock <IRecipesService>();
            var mappingServiceMock    = new Mock <IMappingService>();

            var  controller = new DailyMenusController(recipesServiceMock.Object, dailyMenusServiceMock.Object, mappingServiceMock.Object);
            Guid id         = Guid.Empty;

            //Act & Assert
            controller.WithCallTo(x => x.DeleteDailyMenu(id))
            .ShouldRenderView("404.html");
        }
Example #6
0
        public void RenderTheRightView_DeleteDailyMeni()
        {
            //Arrange
            var dailyMenusServiceMock = new Mock <IDailyMenuService>();
            var recipesServiceMock    = new Mock <IRecipesService>();
            var mappingServiceMock    = new Mock <IMappingService>();

            var controller = new DailyMenusController(recipesServiceMock.Object, dailyMenusServiceMock.Object, mappingServiceMock.Object);
            var id         = Guid.NewGuid();

            //Act & Assert
            controller.WithCallTo(x => x.DeleteDailyMenu(id))
            .ShouldRenderView("DeleteDailyMenu");
        }
Example #7
0
        public void RenderTheRightViewWithTheCorrectModel_SearchDailyMenuViewModelAndNoModelErrors()
        {
            //Arrange
            var dailyMenusServiceMock = new Mock <IDailyMenuService>();
            var recipesServiceMock    = new Mock <IRecipesService>();
            var mappingServiceMock    = new Mock <IMappingService>();

            var controller = new DailyMenusController(recipesServiceMock.Object, dailyMenusServiceMock.Object, mappingServiceMock.Object);

            //Act & Assert
            controller.WithCallTo(x => x.Index())
            .ShouldRenderView("Index")
            .WithModel <SearchDailyMenuViewModel>()
            .AndNoModelErrors();
        }
Example #8
0
        public void RenderTheRightView_DeleteDailyMenu__WhenDailyMenuWasNotFoundInDatabase()
        {
            //Arrange
            var dailyMenusServiceMock = new Mock <IDailyMenuService>();
            var recipesServiceMock    = new Mock <IRecipesService>();
            var mappingServiceMock    = new Mock <IMappingService>();

            var controller = new DailyMenusController(recipesServiceMock.Object, dailyMenusServiceMock.Object, mappingServiceMock.Object);
            var id         = Guid.NewGuid();

            dailyMenusServiceMock.Setup(x => x.GetDailyMenuById(id)).Returns <DailyMenu>(null);

            //Act & Assert
            controller.WithCallTo(x => x.DeleteDailyMenu(id))
            .ShouldRenderView("DeleteDailyMenu");
        }
Example #9
0
        public void RenderTheRightPartialView_DailyMenusGridPartial()
        {
            //Arrange
            IEnumerable <DailyMenu> dailyMenus = new List <DailyMenu>();
            var dailyMenusServiceMock          = new Mock <IDailyMenuService>();

            dailyMenusServiceMock.Setup(x => x.GetAllDailyMenus()).Returns(dailyMenus);
            var recipesServiceMock = new Mock <IRecipesService>();
            var mappingServiceMock = new Mock <IMappingService>();

            var    controller  = new DailyMenusController(recipesServiceMock.Object, dailyMenusServiceMock.Object, mappingServiceMock.Object);
            string recipeTitle = "Backed Potatoes";

            //Act & Assert
            controller.WithCallTo(x => x.Search(recipeTitle))
            .ShouldRenderPartialView("_DailyMenusGridPartial");
        }
        public void RenderTheRightView_EditDailyMenu_WhenValidGuidIdIsPassed()
        {
            //Arrange
            var dailyMenusServiceMock = new Mock <IDailyMenuService>();
            var recipesServiceMock    = new Mock <IRecipesService>();
            var mappingServiceMock    = new Mock <IMappingService>();

            var       controller = new DailyMenusController(recipesServiceMock.Object, dailyMenusServiceMock.Object, mappingServiceMock.Object);
            Guid      id         = Guid.NewGuid();
            DateTime  date       = DateTime.Today;
            DayOfWeek dayOfWeek  = date.DayOfWeek;

            DailyMenu dailyMenu = new DailyMenu()
            {
                Id        = id,
                Date      = date,
                DayOfWeek = dayOfWeek
            };

            DailyMenuViewModel dailyMenuViewModel = new DailyMenuViewModel()
            {
                Id        = dailyMenu.Id,
                Date      = dailyMenu.Date,
                DayOfWeek = dailyMenu.DayOfWeek
            };
            var selectedMenu = dailyMenuViewModel;
            var allMenus     = new AddDailyMenuViewModel();
            var dailyMenus   = new List <DailyMenu>();

            dailyMenusServiceMock.Setup(x => x.GetDailyMenuById(id)).Returns(dailyMenu);
            dailyMenusServiceMock.Setup(x => x.GetAllDailyMenus()).Returns(dailyMenus);
            mappingServiceMock.Setup(x => x.Map <DailyMenuViewModel>(dailyMenu)).Returns(dailyMenuViewModel);
            mappingServiceMock.Setup(x => x.Map <AddDailyMenuViewModel>(dailyMenus)).Returns(allMenus);
            var model = new EditDailyMenuViewModel()
            {
                Id           = id,
                SelectedDate = DateTime.Today,
                SelectedDailyMenuViewModel       = selectedMenu,
                DailyMenuViewModelWithAllRecipes = allMenus
            };

            //Act & Assert
            controller.WithCallTo(x => x.EditDailyMenu(id))
            .ShouldRenderView("EditDailyMenu");
        }
        public void RenderTheRightPartialView_AddMenu()
        {
            //Arrange
            var dailyMenusServiceMock = new Mock <IDailyMenuService>();
            var recipesServiceMock    = new Mock <IRecipesService>();
            var mappingServiceMock    = new Mock <IMappingService>();

            var controller = new DailyMenusController(recipesServiceMock.Object, dailyMenusServiceMock.Object, mappingServiceMock.Object);

            var model = new EditDailyMenuViewModel()
            {
                Id           = Guid.NewGuid(),
                SelectedDate = DateTime.Today,
                SelectedDailyMenuViewModel       = new DailyMenuViewModel(),
                DailyMenuViewModelWithAllRecipes = new AddDailyMenuViewModel()
            };

            //Act & Assert
            controller.WithCallTo(x => x.AddMenu(model))
            .ShouldRenderPartialView("_AddMenu");
        }
Example #12
0
        public void RenderTheRightView_DetailsDailyMenu_WithModel_DailyMenuViewModel()
        {
            //Arrange
            var dailyMenusServiceMock = new Mock <IDailyMenuService>();
            var recipesServiceMock    = new Mock <IRecipesService>();
            var mappingServiceMock    = new Mock <IMappingService>();

            var       controller = new DailyMenusController(recipesServiceMock.Object, dailyMenusServiceMock.Object, mappingServiceMock.Object);
            Guid      id         = Guid.NewGuid();
            DateTime  date       = DateTime.Today;
            DayOfWeek dayOfWeek  = date.DayOfWeek;

            DailyMenu dailyMenu = new DailyMenu()
            {
                Id        = id,
                Date      = date,
                DayOfWeek = dayOfWeek
            };

            DailyMenuViewModel dailyMenuViewModel = new DailyMenuViewModel()
            {
                Id        = dailyMenu.Id,
                Date      = dailyMenu.Date,
                DayOfWeek = dailyMenu.DayOfWeek
            };
            var selectedMenu = dailyMenuViewModel;
            var allMenus     = new AddDailyMenuViewModel();
            var dailyMenus   = new List <DailyMenu>();

            dailyMenusServiceMock.Setup(x => x.GetDailyMenuById(id)).Returns(It.IsAny <DailyMenu>());
            dailyMenusServiceMock.Setup(x => x.GetAllDailyMenus()).Returns(dailyMenus);
            mappingServiceMock.Setup(x => x.Map <DailyMenuViewModel>(dailyMenu)).Returns(dailyMenuViewModel);

            dailyMenusServiceMock.Setup(x => x.GetDailyMenuById(id)).Returns(dailyMenu);

            //Act & Assert
            controller.WithCallTo(x => x.DetailsDailyMenu(id))
            .ShouldRenderView("DetailsDailyMenu")
            .WithModel(dailyMenuViewModel);
        }
        public void RedirectToActionIndex_WithTheCorrectModel__WhenModelStateIsValid()
        {
            //Arrange
            var dailyMenusServiceMock = new Mock <IDailyMenuService>();
            var recipesServiceMock    = new Mock <IRecipesService>();
            var mappingServiceMock    = new Mock <IMappingService>();

            var controller = new DailyMenusController(recipesServiceMock.Object, dailyMenusServiceMock.Object, mappingServiceMock.Object);

            var date       = DateTime.Today;
            var recipeId   = Guid.NewGuid();
            var recipesIds = new List <Guid>()
            {
                recipeId
            };

            dailyMenusServiceMock.Setup(x => x.AddDailyMenu(date, recipesIds));

            //Act & Assert
            controller.WithCallTo(x => x.AddDailyMenu(date, recipesIds))
            .ShouldRedirectTo(x => x.Index());
        }
        public void RenderTheRightPartialView_AddMenu_WithEditDailyMenuViewModel_AndNoModelErrors_AndCorrectContent()
        {
            //Arrange
            var dailyMenusServiceMock = new Mock <IDailyMenuService>();
            var recipesServiceMock    = new Mock <IRecipesService>();
            var mappingServiceMock    = new Mock <IMappingService>();

            var controller = new DailyMenusController(recipesServiceMock.Object, dailyMenusServiceMock.Object, mappingServiceMock.Object);

            Guid recipeId = Guid.NewGuid();
            IEnumerable <Guid> recipesIds = new List <Guid>()
            {
                recipeId
            };
            DateTime date        = new DateTime(2017, 5, 5);
            Guid     dailyMenuId = Guid.NewGuid();

            var ingredientId            = Guid.NewGuid();
            var name                    = "IngredientName";
            var foodcategoryId          = Guid.NewGuid();
            var quantityInMeasuringUnit = 0.200;
            var pricePerMeasuringUnit   = 1.29m;

            var ingredientViewModel = new IngredientViewModel()
            {
                Id                      = ingredientId,
                Name                    = name,
                FoodCategoryId          = foodcategoryId,
                QuantityInMeasuringUnit = quantityInMeasuringUnit,
                PricePerMeasuringUnit   = pricePerMeasuringUnit
            };

            var title        = "Title Of A New Recipe";
            var describtion  = "This is a decsribtion";
            var instructions = "Instructions of the recipe";
            var dishType     = DishType.MainDish;

            var recipeViewModel = new RecipeViewModel()
            {
                Title       = title,
                Describtion = describtion,
                Instruction = instructions,
                DishType    = dishType,
                Ingredients = new List <IngredientViewModel>()
                {
                    ingredientViewModel
                }
            };

            var dailyMenuGuid     = Guid.NewGuid();
            var addDailyMenuModel = new AddDailyMenuViewModel()
            {
                Date   = date,
                Salads = new List <RecipeViewModel>()
                {
                    recipeViewModel
                }
            };

            var model = new EditDailyMenuViewModel()
            {
                Id           = Guid.NewGuid(),
                SelectedDate = DateTime.Today,
                SelectedDailyMenuViewModel       = new DailyMenuViewModel(),
                DailyMenuViewModelWithAllRecipes = addDailyMenuModel
            };

            //Act & Assert
            controller.WithCallTo(x => x.AddMenu(model))
            .ShouldRenderPartialView("_AddMenu")
            .WithModel <EditDailyMenuViewModel>(
                viewModel => Assert.AreEqual(model.DailyMenuViewModelWithAllRecipes.Date, date))
            .AndNoModelErrors();
        }
Example #15
0
        public void RenderTheRightPartialViewWithTheCorrectModel_SearchDailyMenuViewModelAndNoModelErrorsAndCorrectContent()
        {
            //Arrange
            IEnumerable <DailyMenu> dailyMenus = new List <DailyMenu>();
            var dailyMenusServiceMock          = new Mock <IDailyMenuService>();

            dailyMenusServiceMock.Setup(x => x.GetAllDailyMenus()).Returns(dailyMenus);
            var recipesServiceMock = new Mock <IRecipesService>();
            var mappingServiceMock = new Mock <IMappingService>();

            var controller = new DailyMenusController(recipesServiceMock.Object, dailyMenusServiceMock.Object, mappingServiceMock.Object);

            Guid recipeId = Guid.NewGuid();
            IEnumerable <Guid> recipesIds = new List <Guid>()
            {
                recipeId
            };
            DateTime date = new DateTime(2017, 5, 5);

            Guid dailyMenuId = Guid.NewGuid();

            var ingredients = new List <Ingredient>()
            {
                new Ingredient()
                {
                    Id                      = Guid.NewGuid(),
                    Name                    = "IngredientName",
                    FoodCategoryId          = Guid.NewGuid(),
                    RecipeId                = recipeId,
                    QuantityInMeasuringUnit = 0.200,
                    PricePerMeasuringUnit   = 1.29m
                }
            };

            var 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 <Recipe>()
            {
                recipe
            };

            DailyMenu dailyMenu = new DailyMenu()
            {
                Id        = dailyMenuId,
                Date      = date,
                DayOfWeek = date.DayOfWeek,
                Recipes   = recipes
            };

            var dailyMenuGuid  = Guid.NewGuid();
            var dailyMenuModel = new DailyMenuViewModel()
            {
                Id     = dailyMenuGuid,
                Date   = date,
                Salads = new List <RecipeViewModel>()
            };

            var dailyMenusModelCollection = new List <DailyMenuViewModel>()
            {
                dailyMenuModel
            };

            var searchModel = new SearchDailyMenuViewModel()
            {
                PageSize     = 5,
                TotalRecords = recipes.Count,
                DailyMenus   = dailyMenusModelCollection
            };
            string recipeTitle = "Backed Potatoes";

            //Act & Assert
            controller.WithCallTo(x => x.Search(recipeTitle))
            .ShouldRenderPartialView("_DailyMenusGridPartial")
            .WithModel <SearchDailyMenuViewModel>(
                viewModel => Assert.AreEqual(dailyMenusModelCollection[0].Date, searchModel.DailyMenus.ToList()[0].Date))
            .AndNoModelErrors();
        }