Пример #1
0
        public async Task Execution_should_fail_when_order_is_associated_with_items_that_have_been_shipped_state_based_async()
        {
            var order = new Order()
            {
                OrderDate = DateTime.Now
            };
            var orderRepo = new OrderRepository(Mock.Of <ICustomerDataProxy>(), Mock.Of <IOrderItemDataProxy>());

            orderRepo.Clear();
            order = await orderRepo.InsertAsync(order);

            var orderItemRepo = new OrderItemRepository();

            orderItemRepo.Clear();
            await orderItemRepo.InsertAsync(new OrderItem()
            {
                OrderID = order.ID, OrderStatusID = OrderStatusConstants.PENDING_STATUS
            });

            2.Times(async() => await orderItemRepo.InsertAsync(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  = await command.ExecuteAsync();

            result.Success.ShouldBe(false);
            result.Errors.Count().ShouldBe(2);
        }
 public DeleteOrderTransaction(DeleteOrderCommand cmd) : base(cmd.CorrelationId
                                                              , new DeleteOrderActivity()
                                                              //, new UnHoldInventoryActivity()
                                                              )
 {
     SetState(CONSTANTS.TRANSACTIONS.EntryCommand, cmd);
 }
Пример #3
0
        public async Task DeleteOrderCommandHandler_DeletesExistingOrder()
        {
            //Arrange
            var order = new AllMarkt.Entities.Order
            {
                DeliveryAddress = "Test Address",
                AWB             = "Test AWB"
            };

            AllMarktContextIM.Orders.Add(order);
            await AllMarktContextIM.SaveChangesAsync();

            var existingOrder      = AllMarktContextIM.Orders.First();
            var deleteOrderCommand = new DeleteOrderCommand
            {
                Id = existingOrder.Id
            };

            //Act
            await _deleteOrderCommandHandler.Handle(deleteOrderCommand, CancellationToken.None);

            //Assert
            AllMarktContextIM.Orders
            .Should().NotContain(x => x.Id == existingOrder.Id);
        }
Пример #4
0
 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");
     }
 }
Пример #5
0
        public async Task <ActionResult> DeleteOrder(Guid id)
        {
            var getOrderQuery = new GetOrderQuery(id);
            var order         = await Mediator.Send(getOrderQuery);

            if (order == null)
            {
                return(NotFound("Order not found"));
            }

            Guid clientId       = order.ClientId ?? new Guid();
            var  getClientQuery = new ContactDetailsQuery(clientId);
            var  client         = await Mediator.Send(getClientQuery);

            if (client == null)
            {
                return(NotFound("There is no client assigned to the order."));
            }

            if (client.Status == "Invoice")
            {
                return(BadRequest("You can't delete an order which is waiting for finalization. Downgrade client's status first."));
            }

            var deleteOrderCommand = new DeleteOrderCommand(client, order);
            await Mediator.Send(deleteOrderCommand);

            return(NoContent());
        }
Пример #6
0
        public void Handle(DeleteOrderCommand command)
        {
            Order item = Get <Order>(command.Id, command.ExpectedVersion);

            item.Delete();
            _session.Commit();
        }
Пример #7
0
        public async Task Execution_deletes_order_and_associated_order_items_state_based_async()
        {
            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();
            await orderItemRepo.InsertAsync(new OrderItem { OrderID = order.ID, OrderStatusID = OrderStatusConstants.PENDING_STATUS });

            await orderItemRepo.InsertAsync(new OrderItem { OrderID = order.ID, OrderStatusID = OrderStatusConstants.SUBMITTED_STATUS });

            await orderItemRepo.InsertAsync(new OrderItem { OrderID = order.ID, OrderStatusID = OrderStatusConstants.BACK_ORDERED_STATE });

            await orderItemRepo.InsertAsync(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());
            await command.ExecuteAsync();

            orderRepo.GetAll().ShouldBeEmpty();
            orderItemRepo.GetAll().Count().ShouldBe(1);
        }
Пример #8
0
        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);
        }
Пример #9
0
        public async Task <IdResponse> HandleAsync(DeleteOrderCommand cmd, CancellationToken ct)
        {
            var order = await _orderRepository.GetById(cmd.id);

            var result = _orderRepository.DeleteByT(order);

            return(new IdResponse(cmd.id));
        }
Пример #10
0
        // *******************************************************************************************************************************
        #region -  DeleteOrder  -

        public async Task <string> DeleteOrderAsync(DeleteOrderCommand cmd)
        {
            var tran    = new DeleteOrderTransaction(cmd);
            var ctl     = ControllerFactory.CreateForTcc(tran);
            var msgCode = await ctl.RunAsync().ConfigureAwait(false);

            return(msgCode);
        }
Пример #11
0
        public async Task <ActionResult> DeleteOrder(int id)
        {
            var command = new DeleteOrderCommand {
                Id = id
            };
            await _mediator.Send(command);

            return(NoContent());
        }
Пример #12
0
        public OrderViewModel(IOrderRepository orderRepository, IEmployeeRepository employeeRepository)
        {
            AddOrderCommand      = new AddOrderCommand(this);
            DeleteOrderCommand   = new DeleteOrderCommand(this, orderRepository);
            SaveOrdersCommand    = new SaveOrdersCommand(this, orderRepository);
            RefreshOrdersCommand = new RefreshOrdersCommand(this, orderRepository, employeeRepository);

            RefreshOrdersCommand.Execute(null);
        }
Пример #13
0
            public void Handle(DeleteOrderCommand instance)
            {
                OrderAggregate orderAggregate = _unitOfWork
                                                .GetRepository <OrderAggregate>()
                                                .GetById(instance.EntityId);

                orderAggregate.Delete();
                _unitOfWork.GetRepository <OrderAggregate>().Add(orderAggregate);
            }
 public DeleteOrderCommandHandlerTest()
 {
     orderRepository = new Mock <IOrderRepository>();
     bus             = new Mock <IBus>();
     command         = new DeleteOrderCommand(orderId);
     commandHandler  = new DeleteOrderCommandHandler(orderRepository.Object, bus.Object);
     orderItems      = new List <OrderItem> {
         new OrderItem(), new OrderItem()
     };
 }
Пример #15
0
        public async Task <ActionResult <bool> > DeleteOrder(int id)
        {
            var command = new DeleteOrderCommand()
            {
                Id = id
            };
            bool status = await _mediator.Send(command);

            return(Ok(status));
        }
        public OrderMasterDetailsViewModel()
        {
            _catalog = new OrderCatalog();
            _orderItemViewModelSelected = new OrderItemViewModel(new Orders());

            _deleteCommand   = new DeleteOrderCommand(_catalog, this);
            _newOrderCommand = new NewOrderCommand(_catalog, this);
            _saveCommand     = new SaveOrderCommand(_catalog);
            _refreshCommand  = new RefreshOrderCommand(this, _catalog);
            _catalog.Load();
        }
        public async Task <IActionResult> DeleteAsync([FromRoute] long id)
        {
            var command = new DeleteOrderCommand
            {
                Id = id
            };

            var response = await _mediator.Send(command);

            return(Json(response));
        }
Пример #18
0
        public async Task <ActionResult <Order> > DeleteOrder(int id)
        {
            var command = new DeleteOrderCommand()
            {
                Id = id
            };

            var result = await _mediator.Send(command);

            return(result == null?BadRequest() : Ok(result));
        }
Пример #19
0
        public async Task Handle_GivenInvalidRequest_ShouldThrowNotFoundException()
        {
            // Arrange
            var command = new DeleteOrderCommand {
                Id = 133
            };
            var sut = new DeleteOrderCommandHandler(this.deletableEntityRepository);

            // Act & Assert
            await Should.ThrowAsync <NotFoundException>(sut.Handle(command, It.IsAny <CancellationToken>()));
        }
Пример #20
0
        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 async Task <bool> Handle(DeleteOrderCommand request, CancellationToken cancellationToken)
        {
            var existedOrder = await _orderRepository.GetByIdAsync(request.Id);

            if (existedOrder == null)
            {
                throw new Exception($"Order with id {request.Id} does not exist");
            }

            _orderRepository.Delete(existedOrder);
            return(await _orderRepository.SaveChangesAsync());
        }
Пример #22
0
 public IActionResult Delete([FromBody] DeleteOrderCommand command)
 {
     try
     {
         var status = _orderService.Delete(command);
         return(Ok(status));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Пример #23
0
        public async Task DeleteAsync(DeleteOrderCommand command)
        {
            var order = await _context.Orders.FirstOrDefaultAsync(x => x.Id == command.Id);

            if (order == null)
            {
                throw new GfsException(ErrorCode.OrderNotFound, _dictionary.OrderNotFound);
            }

            _context.Remove(order);

            await _context.SaveChangesAsync();
        }
Пример #24
0
        public async Task DeleteOrder_NonExistentOrder_NotFoundException()
        {
            // Arrange
            var command = new DeleteOrderCommand(Guid.NewGuid());

            fixture.OrderRepositoryMock.Setup(foo => foo.GetAsync(command.OrderId)).ReturnsAsync((Order)null);

            // Act
            await Assert.ThrowsAsync <NotFoundException>(async() => await fixture.Instance.Send(command));

            // Assert
            fixture.OrderRepositoryMock.Verify(m => m.DeleteAsync(command.OrderId), Times.Never());
        }
Пример #25
0
        public async Task <ActionResult <bool> > DeleteOrder(Guid id)
        {
            var deleteOrderCommand = new DeleteOrderCommand(id);

            _logger.LogInformation(
                "----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
                nameof(deleteOrderCommand),
                nameof(deleteOrderCommand.Id),
                deleteOrderCommand.Id,
                deleteOrderCommand);

            return(await _mediator.Send(new DeleteOrderCommand(id)));
        }
        /// <summary>
        /// Logically delete an existing instance of the <see cref="Entities.OrderEntity"/>
        /// </summary>
        public IServiceResponse DeleteOrder(IServiceRequestWithData <Cqrs.Authentication.ISingleSignOnToken, Entities.OrderEntity> serviceRequest)
        {
            AuthenticationTokenHelper.SetAuthenticationToken(serviceRequest.AuthenticationToken);
            CorrelationIdHelper.SetCorrelationId(serviceRequest.CorrelationId);
            UnitOfWorkService.SetCommitter(this);
            Entities.OrderEntity item = serviceRequest.Data;

            var locatedItem = OrderRepository.Load(item.Rsn, false);

            if (locatedItem == null)
            {
                return(CompleteResponse(new ServiceResponseWithResultData <Entities.OrderEntity> {
                    State = ServiceResponseStateType.FailedValidation
                }));
            }

            if (locatedItem.IsLogicallyDeleted)
            {
                return(CompleteResponse(new ServiceResponseWithResultData <Entities.OrderEntity> {
                    State = ServiceResponseStateType.FailedValidation
                }));
            }

            var command = new DeleteOrderCommand(item.Rsn);
            ServiceResponseStateType?serviceResponseStateType = null;

            OnDeleteOrder(serviceRequest, ref command, locatedItem, ref serviceResponseStateType);
            if (serviceResponseStateType != null && serviceResponseStateType != ServiceResponseStateType.Succeeded)
            {
                return(CompleteResponse(new ServiceResponseWithResultData <Entities.OrderEntity> {
                    State = serviceResponseStateType.Value
                }));
            }

            CommandSender.Send(command);
            OnDeletedOrder(serviceRequest, ref command, locatedItem, ref serviceResponseStateType);
            if (serviceResponseStateType != null && serviceResponseStateType != ServiceResponseStateType.Succeeded)
            {
                return(CompleteResponse(new ServiceResponseWithResultData <Entities.OrderEntity> {
                    State = serviceResponseStateType.Value
                }));
            }

            UnitOfWorkService.Commit(this);
            return(CompleteResponse(new ServiceResponse()));
        }
Пример #27
0
        public async Task Handle_GivenInvalidRequest_ShouldThrowFailedEntityAlreadyDeletedException()
        {
            // Arrange
            var command = new DeleteOrderCommand {
                Id = 2
            };
            var sut = new DeleteOrderCommandHandler(this.deletableEntityRepository);

            var order = await this.deletableEntityRepository
                        .GetByIdWithDeletedAsync(1);

            this.deletableEntityRepository.Delete(order);
            await this.deletableEntityRepository.SaveChangesAsync();

            // Act & Assert
            await Should.ThrowAsync <EntityAlreadyDeletedException>(sut.Handle(command, It.IsAny <CancellationToken>()));
        }
Пример #28
0
        public async Task DeleteOrder_ValidData_Success()
        {
            // Arrange
            var command = new DeleteOrderCommand(Guid.NewGuid());
            var order   = new Order
            {
                Id     = command.OrderId,
                Status = OrderStatus.Validation
            };

            fixture.OrderRepositoryMock.Setup(foo => foo.GetAsync(order.Id)).ReturnsAsync(order);

            // Act
            await fixture.Instance.Send(command);

            // Assert
            fixture.OrderRepositoryMock.Verify(m => m.DeleteAsync(order.Id), Times.Once());
        }
Пример #29
0
        public async Task <IActionResult> Delete([FromBody] DeleteOrderCommand command)
        {
            _logger.LogInformation(
                "----- Sending command: {CommandName}: ({@Command})",
                typeof(DeleteOrderCommand).Name,
                command);

            var result = await _mediator.Send(command);

            if (result)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
Пример #30
0
        public async Task <IActionResult> Delete(int id)
        {
            OrderReadDto result;

            try
            {
                var query = new DeleteOrderCommand(id);
                result = await _mediator.Send(query);
            }
            catch (Exception ex)
            {
                _logger.LogWarning($"Order with id {id} not deleted!");
                return(StatusCode(StatusCodes.Status400BadRequest, ex.Message));
            }

            _logger.LogInformation($"Order with id {id} deleted!");
            return(StatusCode(StatusCodes.Status200OK, result));
        }