public void Execution_deletes_order_and_associated_order_items_state_based() { var order = new Order() { OrderDate = DateTime.Now }; var orderRepo = new OrderRepository(Mock.Of <ICustomerDataProxy>(), Mock.Of <IOrderItemDataProxy>()); orderRepo.Clear(); order = orderRepo.Insert(order); var orderItemRepo = new OrderItemRepository(); orderItemRepo.Clear(); orderItemRepo.Insert(new OrderItem { OrderID = order.ID, OrderStatusID = OrderStatusConstants.PENDING_STATUS }); orderItemRepo.Insert(new OrderItem { OrderID = order.ID, OrderStatusID = OrderStatusConstants.SUBMITTED_STATUS }); orderItemRepo.Insert(new OrderItem { OrderID = order.ID, OrderStatusID = OrderStatusConstants.BACK_ORDERED_STATE }); orderItemRepo.Insert(new OrderItem { OrderID = 2, OrderStatusID = OrderStatusConstants.PENDING_STATUS }); var orderItemService = new OrderItemService(orderItemRepo, Mock.Of <IProductDataProxy>(), Mock.Of <IInventoryItemDataProxy>(), new TransactionContextStub()); var command = new DeleteOrderCommand(order.ID, orderRepo, orderItemService, new TransactionContextStub()); command.Execute(); orderRepo.GetAll().ShouldBeEmpty(); orderItemRepo.GetAll().Count().ShouldBe(1); }
public void Execution_should_fail_when_order_is_associated_with_items_that_have_been_shipped_state_based() { var order = new Order() { OrderDate = DateTime.Now }; var orderRepo = new OrderRepository(Mock.Of <ICustomerDataProxy>(), Mock.Of <IOrderItemDataProxy>()); orderRepo.Clear(); order = orderRepo.Insert(order); var orderItemRepo = new OrderItemRepository(); orderItemRepo.Clear(); orderItemRepo.Insert(new OrderItem() { OrderID = order.ID, OrderStatusID = OrderStatusConstants.PENDING_STATUS }); 2.Times(() => orderItemRepo.Insert(new OrderItem() { OrderID = order.ID, OrderStatusID = OrderStatusConstants.SHIPPED_STATUS })); var orderItemService = new OrderItemService(orderItemRepo, Mock.Of <IProductDataProxy>(), Mock.Of <IInventoryItemDataProxy>(), Mock.Of <ITransactionContext>()); var command = new DeleteOrderCommand(order.ID, orderRepo, orderItemService, new TransactionContextStub()); var result = command.Execute(); result.Success.ShouldBe(false); result.Errors.Count().ShouldBe(2); }
private void button_DeleteBeverage_Click(object sender, EventArgs e) { try { int BeverID = MenuDAO.Instance.GetIdFromSelectedTextbox(textBox_BeverageSelected.Text); int IDBill = BillInforDAO.Instance.getIDBillInfor(); ICommand deleteOrder = new DeleteOrderCommand(orderDa, BeverID, IDBill); deleteOrder.Execute(); /*orderDa.DeleteBeverageFromOrder(BeverID, IDBill);*/ if (listView_Order.Items.Count <= 1) { listView_Order.Items.Clear(); textBox_TotalPrice.Text = "0"; BillInforDAO.Instance.DeleteBill(); } else { listView_Order.Items.Clear(); textBox_TotalPrice.Clear(); LoadOrderList(); } } catch { MessageBox.Show("Hãy chọn đồ uống cần xóa"); } }
public void Execution_should_fail_when_order_id_is_not_supplied() { var command = new DeleteOrderCommand(0, Mock.Of <IOrderDataProxy>(), Mock.Of <IOrderItemService>(), Mock.Of <ITransactionContext>()); var result = command.Execute(); result.Success.ShouldBe(false); result.Errors.Count().ShouldBe(1); }
public void Execution_deletes_order_and_associated_order_items() { var orders = new List <Order>() { new Order { ID = 1 } }; var orderItems = new List <OrderItem> { new OrderItem { ID = 1, OrderID = 1, OrderStatusID = OrderStatusConstants.PENDING_STATUS }, new OrderItem { ID = 2, OrderID = 1, OrderStatusID = OrderStatusConstants.SUBMITTED_STATUS }, new OrderItem { ID = 3, OrderID = 1, OrderStatusID = OrderStatusConstants.BACK_ORDERED_STATE }, new OrderItem { ID = 4, OrderID = 2, OrderStatusID = OrderStatusConstants.BACK_ORDERED_STATE } }; var deletedOrderItemIds = new List <long>(); var orderID = 1; var orderDataProxy = new Mock <IOrderDataProxy>(); orderDataProxy.Setup(p => p.Delete(orderID)).Callback((long id) => orders.Remove(id)); var orderItemDataProxy = new Mock <IOrderItemDataProxy>(); orderItemDataProxy.Setup(p => p.GetByOrder(It.IsAny <long>())) .Returns((long i) => orderItems.Where(item => item.OrderID == i)); orderItemDataProxy.Setup(p => p.GetByID(It.IsAny <long>())) .Returns((long i) => orderItems.First(oi => oi.ID == i)); orderItemDataProxy.Setup(p => p.Delete(It.IsAny <long>())).Callback((long id) => deletedOrderItemIds.Add(id)); var command = new DeleteOrderCommand ( orderID, orderDataProxy.Object, new OrderItemService ( orderItemDataProxy.Object, Mock.Of <IProductDataProxy>(), Mock.Of <IInventoryItemDataProxy>(), Mock.Of <ITransactionContext>() ), new TransactionContextStub() ); var result = command.Execute(); result.Success.ShouldBe(true); orders.Count().ShouldBe(0); deletedOrderItemIds.ShouldBe(new long[] { 1, 2, 3 }); }
public void Execution_should_fail_when_order_is_associated_with_items_that_have_been_shipped() { var orderItems = new[] { new OrderItem() { ID = 1, OrderStatusID = OrderStatusConstants.PENDING_STATUS }, new OrderItem() { ID = 2, OrderStatusID = OrderStatusConstants.SHIPPED_STATUS }, new OrderItem() { ID = 3, OrderStatusID = OrderStatusConstants.SHIPPED_STATUS } }; var orderID = 1; var orderItemDataProxy = new Mock <IOrderItemDataProxy>(); orderItemDataProxy.Setup(p => p.GetByOrder(It.IsAny <long>())) .Returns(orderItems); orderItemDataProxy.Setup(p => p.GetByID(It.IsAny <long>())) .Returns((long i) => orderItems.First(oi => oi.ID == i)); var command = new DeleteOrderCommand ( orderID, Mock.Of <IOrderDataProxy>(), new OrderItemService ( orderItemDataProxy.Object, Mock.Of <IProductDataProxy>(), Mock.Of <IInventoryItemDataProxy>(), Mock.Of <ITransactionContext>() ), Mock.Of <ITransactionContext>() ); var result = command.Execute(); result.Success.ShouldBe(false); result.Errors.Count().ShouldBe(2); }
public void Delete(string id) { var order = _orderRepository.GetById(id).Result; if (order == null) { AddNotification("Pedido", "Nenhum pedido com este código pode ser encontrado!"); return; } if (order.ApprovedItens > 0 || order.ApprovedValue > 0) { AddNotification("Pedido", "Exclusão cancelada! O pedido já foi aprovado."); return; } if (Valid) { var itemCmd = new DeleteItemCommand(_itemRepository, _itemValidator); foreach (var item in order.Items) { itemCmd.Execute(item); AddNotifications(itemCmd); } } if (Valid) { var orderCmd = new DeleteOrderCommand(_orderRepository); orderCmd.Execute(order); AddNotifications(orderCmd); } if (Valid) { _context.SaveChanges(); } }