public void controlla_Ingredients_CreateTest() { // Arrange IngredientsController controller = new IngredientsController(); //Act //rilancio la creazione dell'ingrediente che ha come descrizione "ingredientFotTestCreate" Ingredients ingredientFotTestCreate = new Ingredients() { Description = "ingredientFotTestCreate", Quantity = 1000 }; ActionResult result = controller.Create(ingredientFotTestCreate); var idingredientFotTestCreate = from s in db.Ingredients .Where(x => x.Description.Equals("ingredientFotTestCreate")) select s.ID; // Assert //mi aspetto, che la selzione in base alla descrizione mi restituisca un ID Assert.IsNotNull(idingredientFotTestCreate.FirstOrDefault()); }
protected override void Given() { _controller = new IngredientsController { Session = Session }; }
public void Setup() { _ingredientsController = new IngredientsController(_ingredientsService.Object); }
public IngredientsControllerTests() { db = new RecipeBookContext(); controller = new IngredientsController(db); }
public IngredientsControllerTests() { Controller = new IngredientsController(DbContext); }
private IngredientsController GetIngredientsController(MockIngredientService mockService) { var controller = new IngredientsController(mockService.Object); return(controller); }
/// <summary> /// Set the reference for the Ingredients controller /// </summary> /// <param name="_ingredientsController"></param> public void SetIngredientsController(IngredientsController _ingredientsController) { I.ingredientsCtrl = _ingredientsController; }
public void RenderTheRightView_EditIngredient_WhenValidGuidIdIsPassed() { //Arrange var foodCategoriesModels = new List <FoodCategoryViewModel>() { new FoodCategoryViewModel() { Id = Guid.NewGuid(), Name = "Tomatos", FoodType = FoodType.Vegetable, MeasuringUnit = MeasuringUnitType.Kg } }; var recipesModels = new List <RecipeViewModel>() { new RecipeViewModel() { Id = Guid.NewGuid(), Title = "Tomato Salad", DishType = DishType.Salad, Describtion = "Some describtion", Instruction = "These are the instructions" } }; var foodCategories = new List <FoodCategory>() { new FoodCategory() { Id = Guid.NewGuid(), Name = "Tomatos", FoodType = FoodType.Vegetable, MeasuringUnit = MeasuringUnitType.Kg } }; var recipes = new List <Recipe>() { new Recipe() { Id = Guid.NewGuid(), Title = "Tomato Salad", DishType = DishType.Salad, Describtion = "Some describtion", Instruction = "These are the instructions" } }; var ingredientsServiceMock = new Mock <IIngredientsService>(); var foodCategoriesServiceMock = new Mock <IFoodCategoriesService>(); foodCategoriesServiceMock.Setup(x => x.GetAllFoodCategories()).Returns(foodCategories); var recipesServiceMock = new Mock <IRecipesService>(); recipesServiceMock.Setup(x => x.GetAllRecipes()).Returns(recipes); var mappingServiceMock = new Mock <IMappingService>(); var controller = new IngredientsController(ingredientsServiceMock.Object, foodCategoriesServiceMock.Object, recipesServiceMock.Object, mappingServiceMock.Object); var id = Guid.NewGuid(); var name = "Tomato"; var foodcategoryId = Guid.NewGuid(); var recipeId = Guid.NewGuid(); var ingredient = new Ingredient() { Id = id, Name = name, FoodCategoryId = foodcategoryId, RecipeId = recipeId }; ingredientsServiceMock.Setup(x => x.GetIngredientById(id)).Returns(ingredient); var model = new IngredientViewModel(); model.FoodCategoryId = ingredient.FoodCategoryId; model.Name = ingredient.Name; model.RecipeId = ingredient.RecipeId; model.Id = ingredient.Id; model.FoodCategories = foodCategoriesModels; model.Recipes = recipesModels; mappingServiceMock.Setup(x => x.Map <IngredientViewModel>(ingredient)).Returns(model); //Act & Assert controller.WithCallTo(x => x.EditIngredient(id)) .ShouldRenderView("EditIngredient") .WithModel(model); }