public virtual void runShouldNotifyCustomer()
        {
            Membership membershipSilver = new Membership("membership-silver", null);
            Membership membershipGold   = new Membership("membership-gold", membershipSilver);

            LineItem[] lineItems = new LineItem[] { new LineItem(membershipGold.Sku, "gold", new ProductCategory[] { ProductCategory.Membership }) };
            //Customer customer = spy(typeof(Customer));
            var customer = new Mock <Customer>().Object;
            //when(customer.hasMembership(membershipSilver)).thenReturn(true);

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

            MembershipRepository repo = new Mock <MembershipRepository>().Object;
            //when(repo.findBySku(membershipGold.Sku)).thenReturn(membershipGold);

            NotificationService notificationService = new Mock <NotificationService>().Object;

            PaymentHandler sut = new MembershipUpgradeHandler(repo, notificationService);

            sut.run(payment);

            notificationService.notify(customer, membershipGold);
            //verify(notificationService, times(1)).notify(customer, membershipGold);
        }
        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);
        }
        public virtual void runShouldNotGenerateAgentCommissionIfItemsInvalid()
        {
            LineItem[] lineItems = new LineItem[] { new LineItem("item", "item", new ProductCategory[] { ProductCategory.Membership, ProductCategory.Virtual }) };
            var        customer  = new Mock <Customer>().Object;
            Agent      agent     = new Mock <Agent>().Object;
            Order      order     = new Order(customer, lineItems, agent);
            Payment    payment   = new Payment(order);

            PaymentHandler sut = new AgentCommissionHandler();

            sut.run(payment);

            agent.generateCommission(order);
        }
        public virtual void runShouldDoNothingIfNoMembershipsInOrder()
        {
            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);

            MembershipRepository service             = new Mock <MembershipRepository>().Object;
            NotificationService  notificationService = new Mock <NotificationService>().Object;
            Membership           membership          = new Membership("item1", null);
            PaymentHandler       sut = new MembershipActivateHandler(service, notificationService);

            sut.run(payment);

            customer.addMembership(membership, notificationService);
        }
        public virtual void runShouldGenerateAgentCommissionIfPhysicalItemInOrder()
        {
            LineItem[] lineItems = new LineItem[]
            {
                new LineItem("item", "item", new ProductCategory[] { ProductCategory.Physical }),
                new LineItem("membership", "membership", new ProductCategory[] { ProductCategory.Membership })
            };
            var     customer = new Mock <Customer>().Object;
            Agent   agent    = new Mock <Agent>().Object;
            Order   order    = new Order(customer, lineItems, agent);
            Payment payment  = new Payment(order);

            PaymentHandler sut = new AgentCommissionHandler();

            sut.run(payment);

            //verify(agent, times(1)).generateCommission(any());
            agent.generateCommission(order);
        }
        public virtual void runShouldNotifyCustomer()
        {
            LineItem[] lineItems = new LineItem[] { new LineItem("item1", "item1", new ProductCategory[] { ProductCategory.Membership }) };
            var        customer  = new Mock <Customer>().Object;
            Order      order     = new Order(customer, lineItems, null);
            Payment    payment   = new Payment(order);

            MembershipRepository repo       = new Mock <MembershipRepository>().Object;
            Membership           membership = new Membership("item1", null);
            //when(repo.findBySku("item1")).thenReturn(membership);

            NotificationService notificationService = new Mock <NotificationService>().Object;

            PaymentHandler sut = new MembershipActivateHandler(repo, notificationService);

            sut.run(payment);

            notificationService.notify(customer, membership);
            //verify(notificationService, times(1)).notify(customer, membership);
        }
        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 runShouldGenerateAgentCommissionOnceIfMultipleBooksInOrder()
        {
            LineItem[] lineItems = new LineItem[]
            {
                new LineItem("book1", "book1", new ProductCategory[] { ProductCategory.Books }),
                new LineItem("book2", "book2", new ProductCategory[] { ProductCategory.Books }),
                new LineItem("book3", "book3", new ProductCategory[] { ProductCategory.Books })
            };
            var     customer = new Mock <Customer>().Object;
            Agent   agent    = new Mock <Agent>().Object;
            Order   order    = new Order(customer, lineItems, agent);
            Payment payment  = new Payment(order);

            PaymentHandler sut = new AgentCommissionHandler();

            sut.run(payment);

            //verify(agent, times(1)).generateCommission(any());
            agent.generateCommission(order);
        }
        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);
        }