public void Pending_order_should_not_be_processed_when_product_included_has_no_stock_available()
            {
                // Arrange
                var     orderId          = 9987;
                int     productId        = 1234;
                int     quantityOnHand   = 4;
                int     orderQuantity    = 5;
                decimal costPerItem      = 10.00m;
                int     reorderThreshold = 5;
                int     reorderAmount    = 5;

                var orderItem = new OrderItem(productId, orderQuantity, costPerItem);
                var order     = new Order(orderId, DateTime.Now, OrderStatus.Pending, new List <OrderItem>()
                {
                    orderItem
                });

                var product = new Product(productId, "test product", quantityOnHand, reorderThreshold, reorderAmount, 10);

                _productRepository = new Mock <IProductRepository>();
                _productRepository.Setup(x => x.GetById(It.Is <int>(p => p == productId))).Returns(product);
                _purchaseOrderRepository = new Mock <IPurchaseOrderRepository>();
                _purchaseOrderRepository.Setup(x => x.Add(It.IsAny <PurchaseOrder>()));

                _orderProcessingService = new OrderProcessingService(_productRepository.Object, _purchaseOrderRepository.Object, _domainEventDispatcher.Object);


                // Act
                _orderProcessingService.ProcessOrder(order);


                // Assert
                Assert.Equal(OrderStatus.Error_Unfulfillable, order.Status);
            }
Beispiel #2
0
        private static void ProcessAllOrders(IDictionary <Guid, IOrder> orders)
        {
            OrderProcessingService         orderProcessingService         = new OrderProcessingService();
            IOrderExecutionService         orderExecutionService          = new OrderExecutionService();
            MembershipProcessingStrategy   membershipProcessingStrategy   = new MembershipProcessingStrategy(orderExecutionService);
            ProductOrderProcessingStrategy productOrderProcessingStrategy = new ProductOrderProcessingStrategy(orderExecutionService);
            VideoRequestProcessingStrategy videoRquestProcessingStrategy  = new VideoRequestProcessingStrategy(orderExecutionService);

            Console.WriteLine("\n\t\t---------------------------------------------\n");
            Console.WriteLine("\n\t\t*********************************************\n");
            Console.WriteLine("\n\t\t* PROCESSING ALL THE PLACED ORDERS *\n");
            try
            {
                foreach (KeyValuePair <Guid, IOrder> kvp in orders)
                {
                    string name = kvp.Value.GetType().Name.ToUpper();
                    switch ((OrderType)Enum.Parse(typeof(OrderType), name))
                    {
                    case OrderType.MEMBERSHIP:
                        orderProcessingService.SetOrderProcessingStrategy(membershipProcessingStrategy);
                        orderProcessingService.ProcessOrder(kvp.Value);
                        break;

                    case OrderType.PRODUCT:
                        orderProcessingService.SetOrderProcessingStrategy(productOrderProcessingStrategy);
                        orderProcessingService.ProcessOrder(kvp.Value);
                        break;

                    case OrderType.VIDEO:
                        orderProcessingService.SetOrderProcessingStrategy(videoRquestProcessingStrategy);
                        orderProcessingService.ProcessOrder(kvp.Value);
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine("\n\t\t*********************************************\n");
            Console.WriteLine("\n\t\t---------------------------------------------\n");
            Console.WriteLine("\n\t\t* ALL ORDERS HAS BEEN PROCESSED *\n");
        }
Beispiel #3
0
        static void Main()
        {
            Console.WriteLine("Enter your product type (Book/Membership/Video/Other):");
            string productType = Console.ReadLine().Trim();

            Console.WriteLine("\nEnter your product name:");
            string productName = Console.ReadLine().Trim();

            Product processedProduct = OrderProcessingService.ProcessOrder(ServiceHelper.GetProductType(productType), productName);

            Console.WriteLine($"\n\n\nProduct Name:\n{processedProduct.ItemName}");
            Console.WriteLine("\nOperations Performed:");

            foreach (string processedOperation in processedProduct.ProcessingOperations)
            {
                Console.WriteLine($"{processedOperation}");
            }

            Console.WriteLine("\n\n\n\n");
        }