public void TestCreate_ShouldReturnValidPizzaObject() { // Setup Fixture var _pizzaRepo = new InMemoryRepository <Pizza>(); var _sizeRepo = new InMemoryRepository <Size>(); _sizeRepo.Add(new Size() { Description = "Familiar", Price = 21m }); var _pizzaService = new PizzaAppService(_pizzaRepo); var expected = new Pizza() { Id = 1, Name = "Big Ozzi", Size = _sizeRepo.Get(1), Toppings = new List <Topping>() { new Topping { Name = "Cheese", Price = 3.5m } } }; // Execute SUT var actual = _pizzaService.Create(expected.Name, expected.Size, expected.Toppings); // Verify Outcomes Assert.Equal(1, _pizzaRepo.Count()); ArePizzasSame(expected, actual); }
public ActionResult Create(PizzaCreateViewModel model) { //Creating some harcoded toppings var toppings = new List <Topping>() { new Topping() { Name = "Cheddar Cheese", Price = 3.5m }, new Topping() { Name = "Avocado", Price = 3m }, }; if (ModelState.IsValid) { var size = _context.Sizes.Find(model.SizeId); _pizzaService.Create(model.Name, size, toppings); return(RedirectToAction("Index")); } model.Sizes = new SelectList(_context.Sizes, "Id", "Description"); return(View(model)); }