示例#1
0
        public void RenderTheRightViewWithTheCorrectModel_SearchIngredientViewModelAndNoModelErrorsAndCorrectContent()
        {
            //Arrange
            Guid       ingredientId = Guid.NewGuid();
            Ingredient ingredient   = new Ingredient()
            {
                Id = ingredientId, Name = "IngredientName", PricePerMeasuringUnit = 12.60m, QuantityInMeasuringUnit = 0
            };
            IEnumerable <Ingredient> ingredients = new List <Ingredient>()
            {
                ingredient
            };
            var inredientsServiceMock = new Mock <IIngredientsService>();

            inredientsServiceMock.Setup(x => x.GetAllIngredients()).Returns(ingredients);
            var foodCategoriesServiceMock = new Mock <IFoodCategoriesService>();
            var recipesServiceMock        = new Mock <IRecipesService>();
            var mappingServiceMock        = new Mock <IMappingService>();
            var searchModel = new SearchIngredientViewModel();

            searchModel.Ingredients = ingredients.Select(x => new IngredientViewModel()
            {
                Name = x.Name
            });
            var controller = new IngredientsController(inredientsServiceMock.Object, foodCategoriesServiceMock.Object, recipesServiceMock.Object, mappingServiceMock.Object);

            controller.Index();

            //Act & Assert
            controller.WithCallTo(x => x.Index())
            .ShouldRenderView("Index")
            .WithModel <SearchIngredientViewModel>(
                viewModel => Assert.AreEqual(ingredients.ToList()[0].Name, searchModel.Ingredients.ToList()[0].Name))
            .AndNoModelErrors();
        }
        public void Index_ReturnsViewResult_True()
        {
            IngredientsController controller = new IngredientsController();
            ViewResult            indexView  = controller.Index() as ViewResult;

            Assert.IsInstanceOfType(indexView, typeof(ViewResult));
        }
        public void Index_HasCorrectModelType_IngredientList()
        {
            IngredientsController controller = new IngredientsController();
            ViewResult            indexView  = controller.Index() as ViewResult;
            var result = indexView.ViewData.Model;

            Assert.IsInstanceOfType(result, typeof(List <Ingredient>));
        }
示例#4
0
        public void coltrolla_Ingredients_IndexTest()
        {
            // Arrange
            IngredientsController controller = new IngredientsController();

            // Act
            ViewResult result = controller.Index() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
示例#5
0
        public async Task Returns_correct_ingredients()
        {
            //Arrange
            var mockLogger = new Mock <ILogger <IngredientsController> >();

            var controller = new IngredientsController(_context, mockLogger.Object);

            //Act
            var result = await controller.Index();

            //Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <IEnumerable <Ingredient> >(
                viewResult.ViewData.Model);

            Assert.Equal(3, model.Count());
        }