public virtual void runShouldNotGenerateForShippingWhenNoValidItemsAvailable()
        {
            LineItem[] lineItems = new LineItem[]
            {
                new LineItem("item1", "item1", new ProductCategory[] { ProductCategory.Membership }),
                new LineItem("item2", "item2", new ProductCategory[] { ProductCategory.Virtual })
            };

            var customer = new Mock <Customer>().Object;
            //customer.Setup(x => x..hasMembership(Membership)).Returns(true);

            Order   order   = new Order(customer, lineItems, null);
            Payment payment = new Payment(order);

            PackingSlipService packingSlipService = new  Mock <PackingSlipService>().Object;
            ShippingService    shippingService    = new Mock <ShippingService>().Object;
            RoyaltyService     royaltyService     = new Mock <RoyaltyService>().Object;

            PaymentHandler sut = new PackingSlipHandler(shippingService, royaltyService, packingSlipService);

            sut.run(payment);

            var slip = shippingService.generatePackingSlip(order);

            Assert.AreEqual(slip, null);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Payment purchaseOne   = new Payment(2.5m, "Book", 250);
            Payment purchaseTwo   = new Payment(10m, "Membership", 251);
            Payment purchaseThree = new Payment(17m, "Physical", 252);
            Payment purchaseFour  = new Payment(5.75m, "UpgradeMembership", 253);
            Payment purchaseFive  = new Payment(7.59m, "Video", 254);

            BasePaymentProcessing baseHandler              = new PackingSlipHandler();
            BasePaymentProcessing membershipHandler        = new MembershipHandler();
            BasePaymentProcessing upgradeMembershipHandler = new UpgradeMembershipHandler();
            BasePaymentProcessing duplicateSlipHandler     = new DuplicatePackingSlipHandler();
            BasePaymentProcessing commisionPaymentHandler  = new CommissionPaymentHandler();
            BasePaymentProcessing videoPaymentHandler      = new VideoPaymentHandler();

            baseHandler.SetNextHandler(duplicateSlipHandler);
            baseHandler.SetNextHandler(commisionPaymentHandler);
            duplicateSlipHandler.SetNextHandler(membershipHandler);
            membershipHandler.SetNextHandler(upgradeMembershipHandler);
            commisionPaymentHandler.SetNextHandler(videoPaymentHandler);

            //Calling chain of responsibility
            baseHandler.ProcessPayment(purchaseOne);
            membershipHandler.ProcessPayment(purchaseTwo);
            baseHandler.ProcessPayment(purchaseThree);
            membershipHandler.ProcessPayment(purchaseFour);
            baseHandler.ProcessPayment(purchaseFive);

            Console.ReadKey();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Payment purchaseOne = new Payment(2.5m, "Book", 253);
            BasePaymentProcessing baseHandler          = new PackingSlipHandler();
            BasePaymentProcessing membershipHandler    = new MembershipHandler();
            BasePaymentProcessing duplicateSlipHandler = new DuplicatePackingSlipHandler();

            baseHandler.SetNextHandler(duplicateSlipHandler);
            duplicateSlipHandler.SetNextHandler(membershipHandler);

            //Calling chain of responsibility
            baseHandler.ProcessPayment(purchaseOne);

            Console.ReadKey();
        }
        public virtual void runShouldGeneratePackingSlip()
        {
            LineItem[] lineItems = new LineItem[] { new LineItem("item1", "item1", new ProductCategory[] { ProductCategory.Physical }) };
            var        customer  = new Mock <Customer>().Object;
            Order      order     = new Order(customer, lineItems, null);
            Payment    payment   = new Payment(order);

            PackingSlipService packingSlipService = new Mock <PackingSlipService>().Object;
            ShippingService    shippingService    = new Mock <ShippingService>().Object;
            RoyaltyService     royaltyService     = new Mock <RoyaltyService>().Object;

            PaymentHandler sut = new PackingSlipHandler(shippingService, royaltyService, packingSlipService);

            sut.run(payment);

            //verify(packingSlipService, times(1)).generate(order);
            var pack = packingSlipService.generate(order);

            Assert.AreEqual(pack, null);
        }
        public virtual void runShouldAddFirstAidGiftWhenRequested()
        {
            LineItem[] lineItems = new LineItem[] { new LineItem("learning-to-ski", "Learning to Ski", new ProductCategory[] { ProductCategory.Videos }) };
            var        customer  = new Mock <Customer>().Object;
            Order      order     = new Order(customer, lineItems, null);
            Payment    payment   = new Payment(order);

            PackingSlipService packingSlipService = new Mock <PackingSlipService>().Object;
            ShippingService    shippingService    = new Mock <ShippingService>().Object;
            RoyaltyService     royaltyService     = new Mock <RoyaltyService>().Object;

            PaymentHandler sut = new PackingSlipHandler(shippingService, royaltyService, packingSlipService);

            sut.run(payment);

            string[] gifts = order.GiftSkus;
            Assert.IsNotNull(gifts);
            Assert.IsTrue(gifts.Length == 1);
            //Assert.IsTrue(Arrays.binarySearch(gifts, "first-aid") == 0);
        }
        public virtual void runShouldGenerateForRoyaltyWhenBooksAvailable()
        {
            LineItem[] lineItems = new LineItem[]
            {
                new LineItem("item1", "item1", new ProductCategory[] { ProductCategory.Books }),
                new LineItem("item2", "item2", new ProductCategory[] { ProductCategory.Membership })
            };
            var     customer = new Mock <Customer>().Object;
            Order   order    = new Order(customer, lineItems, null);
            Payment payment  = new Payment(order);

            PackingSlipService packingSlipService = new Mock <PackingSlipService>().Object;
            ShippingService    shippingService    = new Mock <ShippingService>().Object;
            RoyaltyService     royaltyService     = new Mock <RoyaltyService>().Object;

            PaymentHandler sut = new PackingSlipHandler(shippingService, royaltyService, packingSlipService);

            sut.run(payment);

            //verify(royaltyService, times(1)).generatePackingSlip(order);
            var slip = shippingService.generatePackingSlip(order);

            Assert.AreEqual(slip, null);
        }