public void FilterByIngredients() { Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>(); mock.Setup(r => r.RecipeRepository.Get(null, null, "")).Returns(new Recipe[] { new Recipe { RecipeId = 1, RecipeName = "Recipe1", IsVegetarian = true, Ingredients = "beef, chicken" }, new Recipe { RecipeId = 2, RecipeName = "Recipe2", IsVegetarian = false, Ingredients = "peppers, chicken" }, new Recipe { RecipeId = 3, RecipeName = "Recipe3", IsVegetarian = false }, new Recipe { RecipeId = 4, RecipeName = "Recipe4", IsVegetarian = true } }); // Arrange RecipeController target = new RecipeController(mock.Object); // Act - get the model from the controller var result = ((IEnumerable <Recipe>)target.Index(null, 0, 0, false, "peppers").Model).ToArray(); // Assert Assert.AreEqual(result.Length, 1); Assert.AreEqual(result[0].RecipeId, 2); }
public void GetVegetarianRecipes() { // Arrange Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>(); mock.Setup(r => r.RecipeRepository.Get(null, null, "")).Returns(new Recipe[] { new Recipe { RecipeId = 1, RecipeName = "Recipe1", IsVegetarian = true }, new Recipe { RecipeId = 2, RecipeName = "Recipe2", IsVegetarian = false }, new Recipe { RecipeId = 3, RecipeName = "Recipe3", IsVegetarian = false }, new Recipe { RecipeId = 4, RecipeName = "Recipe4", IsVegetarian = true } }); // Arrange RecipeController target = new RecipeController(mock.Object); // Act - get the model from the controller var isVegetarian = true; var result = ((IEnumerable <Recipe>)target.Index(null, 0, 0, isVegetarian).Model).ToArray(); // Assert Assert.AreEqual(result.Length, 2); Assert.AreEqual(result[0].IsVegetarian, true); Assert.AreEqual(result[1].IsVegetarian, true); }
public void GetAllRecipes_Test() { //Arrange mockRepo.Setup(repo => repo.Recipe.FindAll()).Returns(AllRecipes()); //Act var controllerActionResult = recipeController.Index(); //Assert Assert.NotNull(controllerActionResult); }
public void Index() { // Arrange RecipeController controller = new RecipeController(); // Act ViewResult result = controller.Index() as ViewResult; // Assert Assert.IsNotNull(result); }
public void Index_ReturnIfTrue_View() { //arrange RecipeController controller = new RecipeController(); //act IActionResult indexView = controller.Index(); ViewResult result = indexView as ViewResult; //assert Assert.IsInstanceOfType(result, typeof(ViewResult)); }
public void BeforeAll() { // Set up dependencies for controller this._recipesFromProvider = Builder<Recipe>.CreateListOfSize(10).Build(); var recipeProvider = MockRepository.GenerateStub<IRepository<Recipe,string>>(); recipeProvider.Stub(p => p.Get()).Return(this._recipesFromProvider); this._categoriesFromProvider = Builder<Category>.CreateListOfSize(20).Build(); var categoryProvider = MockRepository.GenerateStub<IRepository<Category,string>>(); categoryProvider.Stub(p => p.Get()).Return(this._categoriesFromProvider); var controller = new RecipeController(recipeProvider, categoryProvider, new AutoMapperMapper<Recipe, RecipeViewModel>(), new AutoMapperMapper<RecipeViewModel, Recipe>(), new AutoMapperMapper<Category, CategoryViewModel>(), MockRepository.GenerateStub<IImageProvider>(), MockRepository.GenerateStub<IFileProvider>(), MockRepository.GenerateStub<IFeatureUsageNotifier>() ); this._viewResult = controller.Index(string.Empty); this._viewModel = this._viewResult.Model as RecipeIndexViewModel; }