Exemplo n.º 1
0
        public IHttpActionResult Post(int id, int qty, string username)
        {
            var item = _itemRepo.GetbyId(id);

            //Adds a cart if one doesnt exist for the user.
            _cartRepo.AddByUserName(username);

            var cart = _cartRepo.GetByUserName(username);

            if (item == null)
            {
                return(Ok(cart));
            }
            if (!item.IsEligibleForCart())
            {
                return(Ok(cart));
            }
            var cartItem    = CartItemFactory.Create(item, qty);
            var updatedCart = _cartRepo.UpdateSingleItem(username, cartItem);

            return(Ok(updatedCart));
        }
Exemplo n.º 2
0
        public void OrderTests_Test1()
        {
            var       createdCart = CartFactory.GetOrCreateCart(AnonShopperMsgHandler);
            const int index       = 0;
            var       product     = ProductFactory.GetProducts(AnonShopperMsgHandler, index, 13).Items.First();
            const int itemQty     = 1;
            var       item        = CartItemFactory.AddItemToCart(AnonShopperMsgHandler,
                                                                  new CartItem()
            {
                Product =
                    new Product
                {
                    ProductCode = product.ProductCode
                },
                Quantity = itemQty
            });
            var order = OrderFactory.CreateOrderFromCart(AnonShopperMsgHandler, createdCart.Id);

            Assert.AreEqual(order.Items.Count, itemQty, "The number of order items is not correct.");
            Assert.AreEqual(order.Items[0].Product.ProductCode, product.ProductCode, "The order item is not the same the shopper entered in the cart.");
            Assert.AreEqual(order.Status, "Created", "The order status is not correct.");
            Assert.IsTrue(order.PaymentStatus.Equals("Unpaid"));
            Assert.IsTrue(order.FulfillmentStatus.Equals("NotShipped"));
        }
 public ShoppingCart(IList<CartItem> items, CartItemFactory cart_item_factory)
 {
     this.items = items;
     this.cart_item_factory = cart_item_factory;
 }
Exemplo n.º 4
0
        public void OrderTests_Test4()
        {
            var       createdCart = CartFactory.GetOrCreateCart(AnonShopperMsgHandler);
            const int index       = 0;
            var       product     = ProductFactory.GetProducts(AnonShopperMsgHandler, index, 13).Items.First();
            const int itemQty     = 1;
            var       item        = CartItemFactory.AddItemToCart(AnonShopperMsgHandler,
                                                                  new CartItem
            {
                Product =
                    new Product
                {
                    ProductCode = product.ProductCode
                },
                Quantity = itemQty
            });
            var order   = OrderFactory.CreateOrderFromCart(AnonShopperMsgHandler, createdCart.Id);
            var billing = BillingInfoFactory.SetBillingInfo(AnonShopperMsgHandler, new BillingInfo()
            {
                PaymentType    = "Check",
                BillingContact = new Mozu.Api.Contracts.Core.Contact
                {
                    Address = new Address
                    {
                        Address1        = string.Format("{0} {1}", Generator.RandomString(8, Generator.RandomCharacterGroup.NumericOnly), Generator.RandomString(75, Generator.RandomCharacterGroup.AlphaNumericOnly)),
                        Address2        = Generator.RandomString(50, Generator.RandomCharacterGroup.AlphaNumericOnly),
                        Address3        = Generator.RandomString(20, Generator.RandomCharacterGroup.AlphaNumericOnly),
                        Address4        = Generator.RandomString(15, Generator.RandomCharacterGroup.AlphaNumericOnly),
                        CityOrTown      = Generator.RandomString(25, Generator.RandomCharacterGroup.AlphaOnly),
                        CountryCode     = "US",
                        PostalOrZipCode = "78713",
                        StateOrProvince = "TX"
                    },
                    CompanyOrOrganization = Generator.RandomString(50, Generator.RandomCharacterGroup.AlphaNumericOnly),
                    Email               = Generator.RandomEmailAddress(),
                    FirstName           = Generator.RandomString(15, Generator.RandomCharacterGroup.AlphaOnly),
                    MiddleNameOrInitial = Generator.RandomString(1, Generator.RandomCharacterGroup.AlphaOnly),
                    LastNameOrSurname   = Generator.RandomString(35, Generator.RandomCharacterGroup.AlphaOnly),
                    PhoneNumbers        = new Mozu.Api.Contracts.Core.Phone
                    {
                        Home = string.Format("{0}-{1}-{2}", Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                             Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                             Generator.RandomString(4, Generator.RandomCharacterGroup.NumericOnly)),
                        Mobile = string.Format("{0}-{1}-{2}", Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                               Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                               Generator.RandomString(4, Generator.RandomCharacterGroup.NumericOnly)),
                        Work = string.Format("{0}-{1}-{2}", Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                             Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                             Generator.RandomString(4, Generator.RandomCharacterGroup.NumericOnly))
                    }
                },
                IsSameBillingShippingAddress = true
            }, order.Id);

            var shipping = FulfillmentInfoFactory.SetFulFillmentInfo(AnonShopperMsgHandler, new FulfillmentInfo()
            {
                IsDestinationCommercial = false,
                FulfillmentContact      = new Mozu.Api.Contracts.Core.Contact
                {
                    Address = new Address
                    {
                        Address1        = string.Format("{0} {1}", Generator.RandomString(8, Generator.RandomCharacterGroup.NumericOnly), Generator.RandomString(75, Generator.RandomCharacterGroup.AlphaNumericOnly)),
                        Address2        = Generator.RandomString(50, Generator.RandomCharacterGroup.AlphaNumericOnly),
                        Address3        = Generator.RandomString(20, Generator.RandomCharacterGroup.AlphaNumericOnly),
                        Address4        = Generator.RandomString(15, Generator.RandomCharacterGroup.AlphaNumericOnly),
                        CityOrTown      = Generator.RandomString(25, Generator.RandomCharacterGroup.AlphaOnly),
                        CountryCode     = "US",
                        PostalOrZipCode = "78713",
                        StateOrProvince = "TX"
                    },
                    CompanyOrOrganization = Generator.RandomString(50, Generator.RandomCharacterGroup.AlphaNumericOnly),
                    Email               = Generator.RandomEmailAddress(),
                    FirstName           = Generator.RandomString(15, Generator.RandomCharacterGroup.AlphaOnly),
                    MiddleNameOrInitial = Generator.RandomString(1, Generator.RandomCharacterGroup.AlphaOnly),
                    LastNameOrSurname   = Generator.RandomString(35, Generator.RandomCharacterGroup.AlphaOnly),
                    PhoneNumbers        = new Mozu.Api.Contracts.Core.Phone
                    {
                        Home = string.Format("{0}-{1}-{2}", Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                             Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                             Generator.RandomString(4, Generator.RandomCharacterGroup.NumericOnly)),
                        Mobile = string.Format("{0}-{1}-{2}", Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                               Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                               Generator.RandomString(4, Generator.RandomCharacterGroup.NumericOnly)),
                        Work = string.Format("{0}-{1}-{2}", Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                             Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                             Generator.RandomString(4, Generator.RandomCharacterGroup.NumericOnly))
                    }
                },
                ShippingMethodCode = "CUSTOM_FLAT_RATE_PER_ORDER_EXACT_AMOUNT",
                ShippingMethodName = "Flat Rate"
            }, order.Id);
            var getOrderActions = OrderFactory.GetAvailableActions(ApiMsgHandler, order.Id);

            Assert.AreEqual(getOrderActions.Count, 1);
            Assert.IsTrue(getOrderActions[0].Equals("SubmitOrder"));
            var status = OrderFactory.PerformOrderAction(AnonShopperMsgHandler, new OrderAction()
            {
                ActionName = "SubmitOrder"
            }, order.Id);
            var getOrder          = OrderFactory.GetOrder(ApiMsgHandler, order.Id);
            var getPaymentActions = PaymentFactory.GetAvailablePaymentActions(ApiMsgHandler, order.Id, getOrder.Payments[0].Id);

            Assert.AreEqual(getPaymentActions.Count, 3);
            Assert.IsTrue(getPaymentActions[0].Equals("ApplyCheck") || getPaymentActions[0].Equals("VoidPayment") || getPaymentActions[0].Equals("DeclinePayment"));
            Assert.IsTrue(getPaymentActions[1].Equals("ApplyCheck") || getPaymentActions[1].Equals("VoidPayment") || getPaymentActions[1].Equals("DeclinePayment"));
            Assert.IsTrue(getPaymentActions[2].Equals("ApplyCheck") || getPaymentActions[2].Equals("VoidPayment") || getPaymentActions[2].Equals("DeclinePayment"));
            var paymentAction = new PaymentAction()
            {
                ActionName  = "ApplyCheck",
                CheckNumber = "12345",
                Amount      = Convert.ToDecimal(getOrder.Total)
            };
            var orderPayment1 = PaymentFactory.PerformPaymentAction(ApiMsgHandler, paymentAction, order.Id, getOrder.Payments[0].Id);

            Assert.AreEqual(orderPayment1.PaymentStatus, "Paid");
            Assert.AreEqual(orderPayment1.Payments[0].Status, "Collected");
            Assert.AreEqual(orderPayment1.Payments[0].AmountCollected, getOrder.Total);
            Assert.AreEqual(orderPayment1.Payments[0].Interactions.Count, 2);
            Assert.IsTrue(orderPayment1.Payments[0].Interactions[1].Status.Equals("Captured"));
            Assert.IsTrue(orderPayment1.Payments[0].Interactions[1].InteractionType.Equals("ApplyCheck"));
            Assert.IsTrue(orderPayment1.Payments[0].Interactions[1].CheckNumber.Equals("12345"));
            Assert.AreEqual(orderPayment1.Payments[0].Interactions[1].Amount, getOrder.Total);
        }
Exemplo n.º 5
0
        public void OrderTests_Test2()
        {
            var       createdCart = CartFactory.GetOrCreateCart(AnonShopperMsgHandler);
            const int index       = 0;
            var       product     = ProductFactory.GetProducts(AnonShopperMsgHandler, index, 13).Items.First();
            const int itemQty     = 3;
            var       item        = CartItemFactory.AddItemToCart(AnonShopperMsgHandler,
                                                                  new CartItem
            {
                Product =
                    new Product
                {
                    ProductCode = product.ProductCode
                },
                Quantity = itemQty
            });
            var getUserCart = CartFactory.GetUserCart(ApiMsgHandler, createdCart.UserId);
            var order       = OrderFactory.CreateOrderFromCart(AnonShopperMsgHandler, createdCart.Id);
            var billing     = BillingInfoFactory.SetBillingInfo(AnonShopperMsgHandler, new BillingInfo()
            {
                PaymentType    = "Check",
                BillingContact = new Mozu.Api.Contracts.Core.Contact
                {
                    Address = new Address
                    {
                        Address1        = string.Format("{0} {1}", Generator.RandomString(8, Generator.RandomCharacterGroup.NumericOnly), Generator.RandomString(75, Generator.RandomCharacterGroup.AlphaNumericOnly)),
                        Address2        = Generator.RandomString(50, Generator.RandomCharacterGroup.AlphaNumericOnly),
                        Address3        = Generator.RandomString(20, Generator.RandomCharacterGroup.AlphaNumericOnly),
                        Address4        = Generator.RandomString(15, Generator.RandomCharacterGroup.AlphaNumericOnly),
                        CityOrTown      = Generator.RandomString(25, Generator.RandomCharacterGroup.AlphaOnly),
                        CountryCode     = "US",
                        PostalOrZipCode = "78713",
                        StateOrProvince = "TX"
                    },
                    CompanyOrOrganization = Generator.RandomString(50, Generator.RandomCharacterGroup.AlphaNumericOnly),
                    Email               = Generator.RandomEmailAddress(),
                    FirstName           = Generator.RandomString(15, Generator.RandomCharacterGroup.AlphaOnly),
                    MiddleNameOrInitial = Generator.RandomString(1, Generator.RandomCharacterGroup.AlphaOnly),
                    LastNameOrSurname   = Generator.RandomString(35, Generator.RandomCharacterGroup.AlphaOnly),
                    PhoneNumbers        = new Mozu.Api.Contracts.Core.Phone
                    {
                        Home = string.Format("{0}-{1}-{2}", Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                             Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                             Generator.RandomString(4, Generator.RandomCharacterGroup.NumericOnly)),
                        Mobile = string.Format("{0}-{1}-{2}", Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                               Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                               Generator.RandomString(4, Generator.RandomCharacterGroup.NumericOnly)),
                        Work = string.Format("{0}-{1}-{2}", Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                             Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                             Generator.RandomString(4, Generator.RandomCharacterGroup.NumericOnly))
                    }
                },
                IsSameBillingShippingAddress = true
            }, order.Id);

            var shipping = FulfillmentInfoFactory.SetFulFillmentInfo(AnonShopperMsgHandler, new FulfillmentInfo()
            {
                IsDestinationCommercial = false,
                FulfillmentContact      = new Mozu.Api.Contracts.Core.Contact
                {
                    Address = new Address
                    {
                        Address1        = string.Format("{0} {1}", Generator.RandomString(8, Generator.RandomCharacterGroup.NumericOnly), Generator.RandomString(75, Generator.RandomCharacterGroup.AlphaNumericOnly)),
                        Address2        = Generator.RandomString(50, Generator.RandomCharacterGroup.AlphaNumericOnly),
                        Address3        = Generator.RandomString(20, Generator.RandomCharacterGroup.AlphaNumericOnly),
                        Address4        = Generator.RandomString(15, Generator.RandomCharacterGroup.AlphaNumericOnly),
                        CityOrTown      = Generator.RandomString(25, Generator.RandomCharacterGroup.AlphaOnly),
                        CountryCode     = "US",
                        PostalOrZipCode = "78713",
                        StateOrProvince = "TX"
                    },
                    CompanyOrOrganization = Generator.RandomString(50, Generator.RandomCharacterGroup.AlphaNumericOnly),
                    Email               = Generator.RandomEmailAddress(),
                    FirstName           = Generator.RandomString(15, Generator.RandomCharacterGroup.AlphaOnly),
                    MiddleNameOrInitial = Generator.RandomString(1, Generator.RandomCharacterGroup.AlphaOnly),
                    LastNameOrSurname   = Generator.RandomString(35, Generator.RandomCharacterGroup.AlphaOnly),
                    PhoneNumbers        = new Mozu.Api.Contracts.Core.Phone
                    {
                        Home = string.Format("{0}-{1}-{2}", Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                             Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                             Generator.RandomString(4, Generator.RandomCharacterGroup.NumericOnly)),
                        Mobile = string.Format("{0}-{1}-{2}", Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                               Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                               Generator.RandomString(4, Generator.RandomCharacterGroup.NumericOnly)),
                        Work = string.Format("{0}-{1}-{2}", Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                             Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                             Generator.RandomString(4, Generator.RandomCharacterGroup.NumericOnly))
                    }
                },
                ShippingMethodCode = "CUSTOM_FLAT_RATE_PER_ORDER_EXACT_AMOUNT",
                ShippingMethodName = "Flat Rate"
            }, order.Id);
            var getOrder = OrderFactory.GetOrder(AnonShopperMsgHandler, order.Id);

            Assert.IsTrue(billing.PaymentType.Equals("Check"));
            Assert.IsTrue(billing.BillingContact.Address.StateOrProvince.Equals("TX"));
            Assert.IsTrue(billing.BillingContact.Address.PostalOrZipCode.Equals("78717"));
            Assert.IsTrue(billing.IsSameBillingShippingAddress);
            Assert.IsTrue(shipping.FulfillmentContact.Address.PostalOrZipCode.Equals("78726"));
            Assert.IsTrue(shipping.FulfillmentContact.Address.StateOrProvince.Equals("TX"));
            Assert.IsFalse(Convert.ToBoolean(shipping.IsDestinationCommercial));
            Assert.IsTrue(shipping.ShippingMethodCode.Equals("CUSTOM_FLAT_RATE_PER_ORDER_EXACT_AMOUNT"));
            Assert.IsTrue(shipping.ShippingMethodName.Equals("Flat Rate"));
            Assert.AreEqual(getOrder.Subtotal, getUserCart.Subtotal);
            Assert.AreEqual(getOrder.DiscountTotal, getUserCart.DiscountTotal);
            Assert.AreEqual(getOrder.DiscountedTotal, getUserCart.DiscountedTotal);
            Assert.AreEqual(getOrder.ShippingTotal, 15);
        }
Exemplo n.º 6
0
 public ShoppingCart(CartItemFactory item_factory, IList<CartItem> items)
 {
     this.item_factory = item_factory;
     this.items = items;
 }