コード例 #1
0
        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());
        }
コード例 #2
0
        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");
        }
コード例 #3
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);
        }
コード例 #4
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();
        }