public void TestAddTopping() { var pizza = new Pizza() { Name = "TestName" }; var topping = new Topping() { Name = "TestToppingName" }; var testPizzaEntity = new PizzaEntity() { Name = "TestName", Toppings = new List <ToppingEntity>() }; pizzaRepositoryMock.Setup(m => m.GetByName("TestName")) .Returns(testPizzaEntity); toppingServiceMock.Setup(m => m.GetByName("TestToppingName")) .Returns(topping); var result = sut.AddToppings(pizza, new List <Topping>() { topping }); Assert.AreEqual(1, result.Toppings.Count); }
public IActionResult PlaceOrder(OrderViewModel orderValues, string submit) { // To consider: Figure out how to post complex values //First, validate the topping count. int countToppings = orderValues.SelectToppings.Count(); //Debugging if (orderValues.SelectToppings.Count() > 5) { TempData["ToppingErrorCount"] = "Please select 5 toppings"; //Persist information. return(RedirectToAction("PlaceOrder")); } //If toppings validation is successful, then map values to Pizza. else if (submit.Equals("add")) { PizzaEntity tempPizza1 = mapPizzaValues(orderValues); TempData.Set("Pizza1", tempPizza1); return(RedirectToAction("PlaceOrder")); } else { PizzaEntity tempPizza1 = TempData.Get <PizzaEntity>("Pizza1"); PizzaEntity tempPizza2 = mapPizzaValues(orderValues); //OrderEntity submittedOrder = new OrderEntity(); //Create new order entity. // _db.Add(submittedOrder); //Save to database. // _db.SaveChangesAsync(); return(RedirectToAction("Index", "Home")); } }
//Focus: How to create & persist order information? public void CreateOrder() { User UserSelect = ValidateUser(); Location LocationSelect = SelectLocation(); Console.WriteLine("Welcome. Let's start by creating an order.\n" + "Type Add to add more pizzas. Type Finish to complete order."); OrderEntity order = new OrderEntity(); string input = Console.ReadLine(); while (input == "Add") { PizzaEntity tempPizza = new PizzaEntity(); //Step 1: What kind of pizza to order??? StorePizzaDefinition tempPizzaName = SelectPizzaType(); //Step 2: Make the pizza. Crust tempCrust = SelectCrust(); Size tempSize = SelectSize(); List <Topping> tempTopping = CreateToppingList(); //Step 3: Choose the quantity. Console.WriteLine("How many pizzas do you want?"); string QuantityChoice = Console.ReadLine(); //Step 4: Map the information into the pizza entity. tempPizza.Name = tempPizzaName.Name; tempPizza.Price = tempPizzaName.Price; tempPizza.Quantity = Int32.Parse(QuantityChoice); tempPizza.PizzaCrust = tempCrust; tempPizza.PizzaSize = tempSize; tempPizza.PizzaTopping = tempTopping; //Step 5: Add the pizza entity to order. order.PizzaList.Add(tempPizza); Console.WriteLine("Would you like to make another pizza?\n" + "As a reminder, type Add to add another pizza. Type Finish to complete order."); string UserDecision = Console.ReadLine(); if (UserDecision == "Finish") { break; } } //Final steps: Add user/location info to order and submit order. order.UserInfo = UserSelect; order.LocationIdentifier = LocationSelect; order.OrderDate = DateTime.Today; _db.OrderList.Add(order); _db.SaveChanges(); }
public void TestGetByName() { var testPizzaEntity = new PizzaEntity() { Name = "TestName", Toppings = new List <ToppingEntity>() }; pizzaRepositoryMock.Setup(m => m.GetByName("TestName")) .Returns(testPizzaEntity); var result = sut.GetByName("TestName"); Assert.AreEqual(testPizzaEntity.Name, result.Name); }
/// <summary> /// Adds Pizza entity. /// </summary> /// <param name="pizza"></param> public void Add(PizzaEntity pizza) { /* Executes query to insert Pizza informaiton to Pizza schema */ databaseConnection.Query <PizzaEntity>("INSERT INTO Pizza (Name) values (@Name)", new { Name = pizza.Name }); /* Inserts pizza topping items to PizzaTopping relational schema */ foreach (var topping in pizza.Toppings) { databaseConnection.Query <PizzaEntity>( "INSERT INTO PizzaTopping (PizzaName, ToppingName) values (@PizzaName, @ToppingName)", new { PizzaName = pizza.Name, ToppingName = topping.Name } ); } }
private PizzaEntity mapPizzaValues(OrderViewModel orderValues) { PizzaEntity tempPizza = new PizzaEntity(); //Map the values. Crust tempCrust = CrustList[orderValues.SelectCrust - 1]; Size tempSize = SizeList[orderValues.SelectSize - 1]; foreach (var topping in orderValues.SelectToppings) { Topping tempTopping = ToppingList[topping - 1]; tempPizza.PizzaTopping.Add(tempTopping); } tempPizza.PizzaCrust = tempCrust; tempPizza.PizzaSize = tempSize; return(tempPizza); }
public void TestAccessors() { var sut = new PizzaEntity(); var name = "test"; sut.Name = name; Assert.AreEqual(name, sut.Name); var topping = new ToppingEntity(); var toppings = new List <ToppingEntity> { topping }; sut.Toppings = toppings; Assert.AreEqual(toppings, sut.Toppings); }
/// <summary> /// Update Topping entities in stored Pizza entity. /// </summary> /// <param name="Pizza"></param> public void Update(PizzaEntity pizza) { /* Delete all current entries from PizzaTopping for an specific pizza item */ databaseConnection.Query <PizzaEntity>( "DELETE FROM PizzaTopping WHERE PizzaName = @Name;", new { Name = pizza.Name } ); foreach (var topping in pizza.Toppings) { databaseConnection.Query <PizzaEntity>( "INSERT INTO PizzaTopping (PizzaName, ToppingName) values (@PizzaName, @ToppingName)", new { PizzaName = pizza.Name, ToppingName = topping.Name } ); } }
public void TestGetAll() { var testPizzaEntity = new PizzaEntity() { Name = "TestName", Toppings = new List <ToppingEntity>() }; List <PizzaEntity> pizzaEntitiesList = new List <PizzaEntity>() { testPizzaEntity }; pizzaRepositoryMock.Setup(m => m.GetAll()) .Returns(pizzaEntitiesList); var result = sut.GetAll(); Assert.AreEqual(pizzaEntitiesList.Count, result.Count); }
/// <summary> /// Deletes Pizza entity. /// </summary> /// <param name="Pizza"></param> public void Delete(PizzaEntity pizza) { databaseConnection.Query <PizzaEntity>( "DELETE FROM Pizza WHERE Name = @Name; DELETE FROM PizzaTopping WHERE PizzaName = @Name;", new { Name = pizza.Name } ); }