Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to order processing system !");

            var order = new OrderDto
            {
                ProductType = ProductType.Membership,
                Amount      = 100,
                Agent       = new AgentDto
                {
                    FirstName = "Rahul",
                    LastName  = "Dravid",
                    Email     = "*****@*****.**"
                }
            };

            var orderStatus = OrderStatus.Pending;

            Console.WriteLine($"Order is received for item { order.ProductType}");
            Console.WriteLine($"***************Processing starts****************");

            var processor = new PhysicalProductProcessor(new ConsolePrinter());

            processor.SetNext(new BookProcessor(new ConsolePrinter(), new PaymentManager()))
            .SetNext(new MembershipProcessor(new MembershipManager()))
            .SetNext(new UpgradeMembershipProcessor(new MembershipManager(), new EmailHandler()));

            orderStatus = processor.Process(order);

            Console.WriteLine($"The order status is : {orderStatus}");

            Console.WriteLine($"***************Processing ends****************");
        }
Esempio n. 2
0
        public void PhysicalProductProcessor_Process_ShouldProcessTheOrder_WhenOrderIsForPhysicalProduct()
        {
            var processor = new PhysicalProductProcessor(new ConsolePrinter());

            var order = new OrderDto
            {
                ProductType = ProductType.Physical,
                Amount      = 100,
                Agent       = new AgentDto
                {
                    FirstName = "Rahul",
                    LastName  = "Dravid",
                    Email     = "*****@*****.**"
                }
            };

            var result = processor.Process(order);

            Assert.AreEqual(OrderStatus.Success, result);
        }
Esempio n. 3
0
        public void PhysicalProductProcessor_Process_ShouldPrintShippingSlip_WhenOrderIsValid()
        {
            var printerMock = new Mock <IPrinter>();

            printerMock.Setup(a => a.Print(It.IsAny <string>()));

            var processor = new PhysicalProductProcessor(printerMock.Object);

            var order = new OrderDto
            {
                ProductType = ProductType.Physical,
                Amount      = 100,
                Agent       = new AgentDto
                {
                    FirstName = "Rahul",
                    LastName  = "Dravid",
                    Email     = "*****@*****.**"
                }
            };

            var result = processor.Process(order);

            printerMock.Verify(a => a.Print(It.IsAny <string>()), Times.Once);
        }