Example #1
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);
        }
Example #2
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);
        }