public void Can_Add_Ingredient_To_Pantry() { var mockIngredientsRepos = new Moq.Mock <IIngredientsRepository>(); var ingredients = new System.Collections.Generic.List <Ingredient> { new Ingredient { IngredientID = 14, Name = "Milk" }, new Ingredient { IngredientID = 27, Name = "Eggs" } }; mockIngredientsRepos.Setup(x => x.Ingredients) .Returns(ingredients.AsQueryable()); var pantry = new Pantry(); var controller = new PantryController(mockIngredientsRepos.Object); RedirectToRouteResult result = controller.AddToPantry(pantry, 27, "someReturnUrl"); Assert.AreEqual(1, pantry.Lines.Count); Assert.AreEqual("Eggs", pantry.Lines[0].Ingredient.Name); Assert.AreEqual(1, pantry.Lines[0].Quantity); // Проверить, что посетитель перенаправлен на экран отображения кладовой Assert.AreEqual("Index", result.RouteValues["action"]); Assert.AreEqual("someReturnUrl", result.RouteValues["returnUrl"]); }
public void Summary_Action_Renders_Default_View_With_Pantry() { Pantry pantry = new Pantry(); PantryController controller = new PantryController(null); ViewResult result = controller.Summary(pantry); Assert.IsEmpty(result.ViewName); Assert.AreSame(pantry, result.ViewData.Model); }
public void Index_Action_Renders_Default_View_With_Pantry_And_Return_Url() { Pantry pantry = new Pantry(); PantryController controller = new PantryController(null); ViewResult result = controller.Index(pantry, "myReturnUrl"); Assert.IsEmpty(result.ViewName); // Визуализировать представление по умолчанию Assert.AreSame(pantry, result.ViewData.Model); Assert.AreEqual("myReturnUrl", result.ViewData["returnUrl"]); Assert.AreEqual("Pantry", result.ViewData["CurrentCategory"]); }
public HomeController() { _query = new Query(); DataGenerator.DataGenerator.GenerateAndInsertData(_query, 20, 10, 50); _recipeInventory = new RecipeInventory(_query); _shoppingInventory = new ShoppingListInventory(_query); _pantry = new MyPantry(_query); _recipeController = new RecipeController(_recipeInventory, _pantry); _pantryController = new PantryController(_pantry); _shoppingListController = new ShoppingListController(_shoppingInventory, _pantry, _recipeInventory); _statsFormController = new StatsFormController(_query); _launchRecipeManager = _recipeController.LaunchRecipeForm; _launchPantryManager = _pantryController.LaunchPantryForm; _launchShoppingListManager = _shoppingListController.LaunchShoppingListForm; _launchStatsFormManager = _statsFormController.LaunchStatsForm; }