public void CreateOrder(Order order) { order.OrderPlaced = DateTime.Now; db.orders.Add(order); foreach (var item in shoppinCartRepo.ViewShoppingCart()) { DrinkOrder drinkOrder = new DrinkOrder { DrinkId = item.Drink.DrinkId, OrderId = order.OrderId, Amount = item.amount, Price = item.Drink.Price * item.amount }; db.drinkOrders.Add(drinkOrder); } if (db.SaveChanges() < 0) { foreach (var item in shoppinCartRepo.ViewShoppingCart()) { item.Drink.Stock += item.amount; } db.SaveChanges(); } }
public void CommandModeTest() { Console.WriteLine("======== 命令模式測試 ========="); //開店準備 Chef chef = new Chef(); Bartender bartender = new Bartender(); Order dishOrder = new DishOrder(chef); Order drinkOrder = new DrinkOrder(bartender); Waitress cuteGirl = new Waitress(); //開始營業 客戶點餐 cuteGirl.SetOrder(dishOrder); cuteGirl.SetOrder(dishOrder); cuteGirl.SetOrder(drinkOrder); cuteGirl.SetOrder(drinkOrder); //飲料還沒賣完 cuteGirl.SetOrder(drinkOrder); Console.WriteLine("===== 客人取消熱炒測試 ====="); //取消一份熱炒 cuteGirl.CancelOrder(dishOrder); //熱炒又可以賣了 cuteGirl.SetOrder(dishOrder); Console.WriteLine("=== 點餐完成 通知廚房 ==="); cuteGirl.NotifyKitchen(); Console.WriteLine("=== 熱炒庫存不足測試 ==="); cuteGirl.SetOrder(dishOrder); Assert.AreEqual(1, 1); }
public ActionResult SaveOrder(OrderIndexVM orderIndexVM) { //saves to the table var order = new Order { CustomerID = orderIndexVM.CustomerID, LocationID = orderIndexVM.LocationID, Total = GetTotal(orderIndexVM.DrinkOrders) }; order = _orderBL.AddOrder(order); foreach (var item in orderIndexVM.DrinkOrders) { if (item.Quantity > 0) { var drinkOrder = new DrinkOrder { DrinkId = item.DrinkId, OrderId = order.OrderID, Quantity = item.Quantity }; _orderBL.AddDrinkOrder(drinkOrder); } var inventory = _inventoryBL.GetInventoryByLocationIDAndDrinkID(order.LocationID, item.DrinkId); if (inventory != null) { inventory.Quantity -= item.Quantity; _inventoryBL.UpdateInventory(inventory); } } return(RedirectToAction("Index", "Home")); }
public bool EditDrinkOrder(DrinkOrder order) { using (SqlConnection conn = new SqlConnection(_connectionString)) { var sql = @"UPDATE DrinkOrder SET Comment = @Comment, DrinkId = @DrinkId, OrderId = @OrderId, Quantity = @Quantity WHERE DrinkOrderId = @DrinkOrderId"; try { conn.Execute(sql, new { @Comment = order.Comment, @DrinkId = order.DrinkId, @OrderId = order.OrderId, @Quantity = order.Quantity, @DrinkOrderId = order.DrinkOrderId }); } catch (Exception) { return(false); } } return(true); }
public void Post_To_Empty_List_Successfully_Adds_Item() { //Arrange DbContextOptions <ShoppingListContext> options = new TestHelper().GetShoppingListContextOptions(); var expectedObject = new DrinkOrder { Name = "Pepsi", Quantity = 1 }; var expectedResult = new CreatedResult("", expectedObject); using (var context = new ShoppingListContext(options)) { IShoppingListRepository mockRepo = new ShoppingListRepository(context); var controller = new ShoppingListController(mockRepo); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); //Act var result = controller.Post(expectedObject) as CreatedResult; //Assert Assert.IsNotNull(result); Assert.AreEqual(201, result.StatusCode); //Can't effectively mock HttpRequest, and don't really want to go down that rabbit hole so just check //it's not null. Assert.IsNotNull(result.Location); Assert.AreEqual(result.Value, expectedResult.Value); } }
// adds customer to this seat public void addCustomer(GameObject newCustomer, DrinkOrder order, Transform location) { // make sure we don't already have a customer if (customer != null) { return; } arrived = false; customerOrder = order; // get location of customer for this seat Transform customerPlacement = this.gameObject.transform.GetChild(1).transform; customer = (GameObject)Instantiate(newCustomer, location.position, Quaternion.identity); customer.transform.position += new Vector3(3f, 3f, 3f); customer.GetComponent <MoveAgent>().spawnLocation = location; // disable billboard while customer is walking customer.transform.Find("NewCustomerOrderUI").gameObject.SetActive(false); // hide text that shows added score customer.transform.GetChild(1).GetComponent <TextMesh>().text = ""; // set customer's destination to this seat customer.GetComponent <MoveAgent>().SetDestination(customerPlacement.position); }
public static void Run() { // Builder Pattern // - a director object which enforces a specific process uses builders // - these builders implement the builder abstraction that the director depends on // - these builders enable variations in details of each step in the process enforced by the director var coffeeMaker = new CoffeeMaker(); var americano = new AmericanoBuilder(); var latte = new LatteBuilder(); var flavoredlatte = new FlavoredLatteBuilder(); var ventiIcedAmericanoOrder = new DrinkOrder(iced: true, DrinkSize.Venti, americano); var tallIcedLatteOrder = new DrinkOrder(iced: true, DrinkSize.Tall, latte); var grandeHotFlavoredLatteOrder = new DrinkOrder(iced: false, DrinkSize.Grande, flavoredlatte); coffeeMaker.AcceptOrder(ventiIcedAmericanoOrder); coffeeMaker.BuildCoffee(); var ventiIcedAmericano = coffeeMaker.GetCoffee(); Console.WriteLine(ventiIcedAmericano.Description); coffeeMaker.AcceptOrder(tallIcedLatteOrder); coffeeMaker.BuildCoffee(); var tallIcedLatte = coffeeMaker.GetCoffee(); Console.WriteLine(tallIcedLatte.Description); coffeeMaker.AcceptOrder(grandeHotFlavoredLatteOrder); coffeeMaker.BuildCoffee(); var grandeHotFlavoredLatte = coffeeMaker.GetCoffee(); Console.WriteLine(grandeHotFlavoredLatte.Description); }
public void AcceptOrder(DrinkOrder drinkOrder) { _coffeeBuilder = drinkOrder.Drink; _coffeeBuilder.StartCoffee(drinkOrder.DrinkSize, drinkOrder.Iced); _coffeeBuilder.MapSizeToShots(); _coffeeBuilder.MapSizeToPumps(); }
public DrinkOrder Update(DrinkOrder update) { var drink = _appDbContext.DrinkOrders.Attach(update); drink.State = Microsoft.EntityFrameworkCore.EntityState.Modified; _appDbContext.SaveChanges(); return(update); }
public ActionResult DeleteConfirmed(int id) { DrinkOrder drinkOrder = db.DrinkOrders.Find(id); db.DrinkOrders.Remove(drinkOrder); db.SaveChanges(); return(RedirectToAction("Index")); }
public void AddDrinkOrder() { LogFns.DebugWriteLine("Adding new DrinkOrder: " + DrinkName); var drinkOrder = new DrinkOrder {DrinkName = DrinkName}; DrinkOrders.Add(drinkOrder); SelectedDrinkOrder = drinkOrder; ReadyForNewDrink(); }
public void AddDrinkOrder() { var drink = new DrinkOrder { DrinkName = DrinkName }; DrinkOrders.Add(drink); SelectedDrinkOrder = drink; }
public ActionResult Edit([Bind(Include = "OrderId,Completed,CustomerName,Alcohol,Mixer")] DrinkOrder drinkOrder) { if (ModelState.IsValid) { db.Entry(drinkOrder).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(drinkOrder)); }
public ObjectResult Put([FromBody] DrinkOrder drinkOrder) { var result = _shoppingListRepository.Update(drinkOrder); if (result == null) { return(new NotFoundObjectResult($"Drink: {drinkOrder.Name} not found on the shopping list.")); } return(new OkObjectResult(result)); }
public ActionResult Create([Bind(Include = "OrderId,Completed,CustomerName,Alcohol,Mixer")] DrinkOrder drinkOrder) { if (ModelState.IsValid) { db.DrinkOrders.Add(drinkOrder); db.SaveChanges(); return(RedirectToAction("Index", "Home")); } return(View(drinkOrder)); }
public void GetDrinkCode_Should_Call_GetCode_Of_Drink() { // GIVEN var drink = Substitute.For <IDrink>(); IDrinkOrder drinkOrder = new DrinkOrder(drink); // WHEN drinkOrder.GetDrinkCode(); // THEN drink.Received().GetCode(); }
/// <summary> /// If entity already exists, return nothing. Otherwise return the inserted entity. /// </summary> /// <param name="entity"></param> /// <returns></returns> public DrinkOrder Insert(DrinkOrder entity) { DrinkOrder drinkOrder = _context.shoppingList.AsNoTracking().FirstOrDefault(x => x.Name == entity.Name); if (drinkOrder != null) { return(null); } _context.shoppingList.Add(entity); _context.SaveChanges(); return(entity); }
public static GameAction OrderDrinkWithoutFailure(Entity entity, DrinkOrder drinkOrder, Conversation conversation, int orderTimeoutInMins = 20) { var orderDrink = new ParallelUntilAllCompleteAction("OrderDrink"); orderDrink.Add(new ReportSuccessDecorator(new ConversationAction(conversation))); var waitForDrink = new ConditionalActionSequence("WaitForDrink"); waitForDrink.Add(new StartDrinkOrderAction(drinkOrder)); waitForDrink.Add(CommonActions.WaitForDrinkWithoutFailure(entity, drinkOrder, orderTimeoutInMins)); orderDrink.Add(waitForDrink); return(orderDrink); }
public void FillPanel(DrinkOrder order) { var drink = order.Drink; drinkImage.sprite = drink.drinkSprite; var orbSprites = GetOrbSprites(drink); for (int i = 0; i < orbImages.Length; i++) { orbImages[i].sprite = orbSprites[i]; } text.text = drink.drinkPrice.ToString("C2"); }
public void GetDrinkCode_Should_Return_Sugar_Qty_From_Drink(int expectedSugarQty) { // arange var drink = new Mock <IHotDrink>(); drink.Setup(x => x.SugarQty).Returns(expectedSugarQty); // act var DrinkOrder = new DrinkOrder(drink.Object); // assert Assert.Equal(expectedSugarQty, DrinkOrder.GetDrinkSugarQty()); }
public void GetDrinkCode_Should_Return_Code_From_Drink(string expectedDrinkCode) { // arange var drink = new Mock <IDrink>(); drink.SetupGet(x => x.Code).Returns(expectedDrinkCode); // act var DrinkOrder = new DrinkOrder(drink.Object); // assert Assert.Equal(expectedDrinkCode, DrinkOrder.GetDrinkCode()); }
// GET: DrinkOrders/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DrinkOrder drinkOrder = db.DrinkOrders.Find(id); if (drinkOrder == null) { return(HttpNotFound()); } return(View(drinkOrder)); }
public void AddCommand_should_Add_Order_ToReport() { // arrange IRepository repo = new Repository(); IDrink coffee = new Coffee(); IDrinkOrder drinkOrder = new DrinkOrder(coffee); // act repo.AddCommand(drinkOrder, DateTime.Now); var Report = repo.GetReport(); // assert Assert.NotEmpty(Report); }
public static ActionSequence OrderDrink(Entity entity, DrinkOrder drinkOrder, Conversation conversation, Conversation correctDrinkConversation = null, Conversation incorrectDrinkConversation = null, Dictionary <String, GameAction> otherDrinkActions = null, int orderTimeoutInMins = 40) { var wrapper = new ActionSequence("DrinkOrderThenClear"); var orderDrink = new ParallelUntilAllCompleteAction("OrderDrink"); orderDrink.Add(new ReportSuccessDecorator(new ConversationAction(conversation))); var waitForDrink = new ConditionalActionSequence("WaitForDrink"); waitForDrink.Add(new StartDrinkOrderAction(drinkOrder)); waitForDrink.Add(CommonActions.WaitForDrink(entity, drinkOrder.OrderedItem, drinkOrder, orderTimeoutInMins, correctDrinkConversation: correctDrinkConversation, incorrectDrinkConversation: incorrectDrinkConversation, otherDrinkActions: otherDrinkActions)); orderDrink.Add(waitForDrink); wrapper.Add(orderDrink); wrapper.Add(new ClearConversationAction()); return(wrapper); }
public void GetDrinkCode_Should_Return_Code_From_Drink(string expectedDrinkCode) { // GIVEN var drink = Substitute.For <IDrink>(); drink.GetCode().Returns(expectedDrinkCode); IDrinkOrder drinkOrder = new DrinkOrder(drink); // WHEN var drinkCode = drinkOrder.GetDrinkCode(); // THEN Check.That(drinkCode).IsEqualTo(expectedDrinkCode); }
public void GetSugarQuantity_Return_Sugar_Quantity_Of_HotDrink(int expectedSugarQuantity) { // GIVEN var drink = Substitute.For <IHotDrink>(); drink.GetSugarQuantity().Returns(expectedSugarQuantity); IDrinkOrder drinkOrder = new DrinkOrder(drink); // WHEN int sugarQuantity = drinkOrder.GetSugarQuantity(); // THEN Check.That(sugarQuantity).IsEqualTo(expectedSugarQuantity); }
public void GetPrice_Should_Return_Price_Of_Drink(double expectedPrice) { // GIVEN IDrink drink = Substitute.For <IDrink>(); drink.GetPrice().Returns(expectedPrice); IDrinkOrder drinkOrder = new DrinkOrder(drink); // WHEN double orderPrice = drinkOrder.GetPrice(); // THEN Check.That(orderPrice).IsEqualTo(expectedPrice); }
public IActionResult RemoveDrink(int id) { DrinkOrder order = data.DrinkOrders.Find(id); order.Active = false; data.Update(order); data.SaveChanges(); IEnumerable <DrinkOrder> orders = data.DrinkOrders.Where(o => o.Active == true); foreach (DrinkOrder drink in orders) { drink.OrderedDrink = data.Drinks.Find(drink.DrinkId); drink.Customization = data.Customizations.Find(drink.CustomizationId); } return(View("GetOrders", orders)); }
public ObjectResult Post([FromBody] DrinkOrder drinkOrder) { var result = _shoppingListRepository.Insert(drinkOrder); if (result == null) { var objectResult = new ObjectResult(Json($"Drink {drinkOrder.Name} already exists in the shopping list.")); objectResult.StatusCode = (int)HttpStatusCode.Conflict; return(objectResult); } string returnedUri = string.Format("{0}://{1}{2}/{3}", this.HttpContext.Request.Scheme, this.HttpContext.Request.Host, this.Request.Path, drinkOrder.Name); return(Created(returnedUri, drinkOrder)); }
public void AddDrinkOrder() { if (!CanAddDrinkOrder) { return; // for safety } if (DrinkOrders.Count == 10) { DrinkOrders.Clear(); // Reset at 10 drinks of any kind } var drink = new DrinkOrder(SelectedBeverage); DrinkOrders.Add(drink); SelectedDrinkOrder = drink; SetInebriationState(); ReadyForNewDrink(); }
public void AddCommand_should_Have_All_OrderDrink(int expectedLength) { // arrange IRepository repo = new Repository(); IDrink coffee = new Coffee(); IDrinkOrder drinkOrder1 = new DrinkOrder(coffee); IDrink Orange = new Coffee(); IDrinkOrder drinkOrder2 = new DrinkOrder(coffee); // act repo.AddCommand(drinkOrder1, DateTime.Now); repo.AddCommand(drinkOrder2, DateTime.Now); var Report = repo.GetReport(); // assert Assert.Equal(expectedLength, Report.Count); }