示例#1
0
        public void AddMultipleItemsToCart()
        {
            var price = 0.30M;

            var MockProductData = new ProductRepository
            {
                Products = new List <Product>
                {
                    new Product {
                        SKU = "sku1", Name = "Product1", Price = price
                    },
                    new Product {
                        SKU = "sku2", Name = "Product2", Price = price
                    },
                    new Product {
                        SKU = "sku3", Name = "Product3", Price = price
                    }
                }
            };

            var MockProductDiscountData = new ProductDiscountRepository
            {
                ProductDiscounts = new List <ProductDiscount>()
            };

            var cart = new ShoppingCart(MockProductData, MockProductDiscountData);

            cart.Add("sku1");
            cart.Add("sku2");
            cart.Add("sku3");
            cart.Add("sku2");

            Assert.AreEqual(cart.TotalItems, 4);
            Assert.AreEqual(cart.TotalPrice, price * 4);
        }
示例#2
0
        private static void Main()
        {
            var shoppingCart = new ShoppingCart("*****@*****.**");

            shoppingCart.Add(new Item {
                Description = "Weight fish", Quantity = 1
            });
            shoppingCart.Add(new Item {
                Description = "Each oil", Quantity = 5
            });

            Console.WriteLine(shoppingCart.TotalAmount());

            var order = new Order();

            order.Checkout(
                shoppingCart,
                new PaymentDetails
            {
                CardholderName   = "Ivan",
                CreditCardNumber = "1111 2222 3333 4444",
                ExpiryDate       = DateTime.ParseExact(
                    "12/11/17 2:52:35 PM",
                    "yy/MM/dd h:mm:ss tt",
                    CultureInfo
                    .InvariantCulture),
                PaymentMethod = PaymentMethod.CreditCard
            },
                true);
        }
示例#3
0
        static void Main(string[] args)
        {
            var cart = new ShoppingCart();

            cart.Add(new OrderItem()
            {
                Product  = "Bread",
                UOM      = "grams",
                Quantity = 250
            });
            cart.Add(new OrderItem()
            {
                Product  = "Coke",
                UOM      = "bottle",
                Quantity = 4
            });
            cart.Add(new OrderItem()
            {
                Product  = "Potato chips",
                UOM      = "bag",
                Quantity = 4
            });

            Console.WriteLine("You pay ${0} for:\r\n{1}", cart.TotalAmount(), cart.Content());
            Console.Read();
        }
示例#4
0
        public void calculate_the_final_price()
        {
            Enumerable.Range(1, 10)
            .ToList()
            .ForEach(i => cart.Add(new Product(i)));

            cart.CalculateTotalPrice().Should().Be(55);
        }
        public ShoppingCart CreateCart()
        {
            // Setting items to the shopping cart
            ShoppingCart cart = new ShoppingCart();

            cart.Add(new Item("Zapatos", 1, 10000, null, -1));
            cart.Add(new Item("Pantalon", 1, 5000, null, -1));
            return(cart);
        }
        public void AddSameProduct_ReturnCount()
        {
            var shoppingCart = new ShoppingCart <ProductConditionDiscount>();
            var product      = new Product("Milk", 1.15m, ProductType.MILK);

            shoppingCart.Add(product);
            shoppingCart.Add(product);
            Assert.Single(shoppingCart.Products);
        }
示例#7
0
        public void CanAddItemToTaxItemManager()
        {
            IShoppingItem itemToAdd = CreateFakeTaxItem("Playstation 5");

            _shoppingCart.Add(itemToAdd);

            var items = _shoppingCart.TaxableItems;

            Assert.AreEqual(items.Contains(itemToAdd), true);
        }
        public void SimpleSum()
        {
            ShoppingCart cart = new ShoppingCart(null);

            cart.Add(new Product("TypeA", 10.0m));
            cart.Add(new Product("TypeB", 20.0m));

            decimal total = cart.GetTotal();

            Assert.Equal(30.0m, total);
        }
示例#9
0
        public void Add_same_product_twice_to_the_cart_correctly()
        {
            var product1 = CreateProduct(productId: "765");
            var product2 = CreateProduct(productId: "765");
            var cart     = new ShoppingCart();

            cart.Add(product1);
            cart.Add(product2);

            Assert.IsTrue(2 == cart.Get("765").Count());
        }
        static void Main(string[] args)
        {
            // Setting comerce data
            Onepay.SharedSecret    = "?XW#WOLG##FBAGEAYSNQ5APD#JF@$AYZ";
            Onepay.ApiKey          = "dKVhq1WGt_XapIYirTXNyUKoWTDFfxaEV63-O5jcsdw";
            Onepay.IntegrationType = Transbank.Onepay.Enums.OnepayIntegrationType.Test;

            // Setting items to the shopping cart
            ShoppingCart cart = new ShoppingCart();

            cart.Add(new Item(
                         description: "Zapatos",
                         quantity: 1,
                         amount: 10000,
                         additionalData: null,
                         expire: 10));

            cart.Add(new Item("Pantalon", 1, 5000, null, -1));

            // Send transaction to Transbank
            TransactionCreateResponse response = Transaction.Create(cart);

            Console.WriteLine(response.ToString());

            var bytes = Convert.FromBase64String(response.QrCodeAsBase64);

            using (var imageFile = new FileStream(@"Qr.jpg", FileMode.Create))
            {
                imageFile.Write(bytes, 0, bytes.Length);
                imageFile.Flush();
            }

            Console.WriteLine("Pay with the app and then press any key to continue....");
            Console.ReadKey();

            TransactionCommitResponse commitResponse = Transaction.Commit(
                response.Occ, response.ExternalUniqueNumber);

            Console.WriteLine(commitResponse.ToString());

            Console.WriteLine("Press any key to Refund Transaction...");
            Console.ReadKey();

            RefundCreateResponse refundResponse = Refund.Create(commitResponse.Amount,
                                                                commitResponse.Occ, response.ExternalUniqueNumber,
                                                                commitResponse.AuthorizationCode);

            Console.WriteLine(refundResponse.ToString());

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
示例#11
0
        public void InitShoppingCart()
        {
            ShoppingCart sc = new ShoppingCart();

            Product productA = new tshirt(10);
            Product productB = new Jean(20);

            sc.Add(productA);
            sc.Add(productB);


            Assert.AreEqual(2, sc.Products.Count);
        }
示例#12
0
        public void CheckoutService()
        {
            var cart = new ShoppingCart();

            cart.Add(new ShoppingCartItem(1, JewelrySize.Medium, new Jewelry("Bracelet", "foo.jpg")));
            cart.Add(new ShoppingCartItem(2, JewelrySize.Medium, new Jewelry("Necklace", "foo.jpg")));

            var order = _checkoutService.CalculateOrder(cart);

            order.TotalAmountOrdered.Should().Be(3);
            order.TotalGoodsValue.Should().Be(300);
            order.TotalShippingCost.Should().Be(36 * 3);
        }
示例#13
0
        public void ShoppingCartAddingSameProductIncreasesQuantity()
        {
            var cart = new ShoppingCart();

            var product = new Product();

            cart.Add(product);
            cart.Add(product);

            var item = cart.Items.Single(x => x.Product == product);

            Assert.AreEqual(2, item.Quantity);
        }
示例#14
0
        public void ShopingCartAddWithItemNegativeValueGreaterThanTotalAmountTest()
        {
            var item1 = new Item("item 1", 1, 200, null, 10);
            var item2 = new Item("item discount", 1, -201, "", 10);

            var cart = new ShoppingCart();

            cart.Add(item1);
            Assert.AreEqual(1, cart.ItemQuantity);
            Assert.AreEqual(200, cart.Total);

            Assert.ThrowsException <AmountException>(() => cart.Add(item2));
        }
示例#15
0
        public void Buy2Jeans2Tshirt()
        {
            ShoppingCart sc = new ShoppingCart();

            Product jean   = new Jean(20);
            Product tshirt = new tshirt(10);

            sc.Add(jean, 2);
            sc.Add(tshirt, 2);

            double totalPrice = sc.TotalValue();

            Assert.AreEqual(45, totalPrice);
        }
示例#16
0
        public void Sc1AddTshirtAndJean()
        {
            ShoppingCart sc = new ShoppingCart();

            Product tshirt = new tshirt(10);
            Product jean   = new Jean(20);

            sc.Add(tshirt);
            sc.Add(jean);

            double totalPrice = sc.TotalValue();

            Assert.AreEqual(30, totalPrice);
        }
示例#17
0
        public double Claulate_total_correctly(double firstItemPrice, double secondItemPrice, double thirdItemPrice)
        {
            var product1 = CreateProduct(firstItemPrice);
            var product2 = CreateProduct(secondItemPrice);
            var product3 = CreateProduct(thirdItemPrice);

            var cart = new ShoppingCart();

            cart.Add(product1);
            cart.Add(product2);
            cart.Add(product3);

            return(cart.Total);
        }
示例#18
0
        public void Remove_OneOfTwoSameItems_DoesntRemoveAllSameItems()
        {
            // Arrange
            var shoppingCart = new ShoppingCart();

            shoppingCart.Add(_apple);
            shoppingCart.Add(_apple);

            // Act
            shoppingCart.Remove(_apple);

            // Assert
            Assert.Equal(1, shoppingCart.Count());
        }
示例#19
0
        public void Add_MultipleItems_CountIsCorrect()
        {
            // Arrange
            var shoppingCart = new ShoppingCart();

            // Act
            shoppingCart.Add(_apple);
            shoppingCart.Add(_apple);
            shoppingCart.Add(_banana);
            shoppingCart.Add(_orange);

            // Assert
            Assert.Equal(4, shoppingCart.Count());
        }
示例#20
0
        public void ShopingCartAddWithItemNegativeValueTest()
        {
            var item1 = new Item("item 1", 1, 200, null, 10);
            var item2 = new Item("item discount", 1, -10, "", 10);

            var cart = new ShoppingCart();

            cart.Add(item1);
            Assert.AreEqual(1, cart.ItemQuantity);
            Assert.AreEqual(200, cart.Total);

            cart.Add(item2);
            Assert.AreEqual(2, cart.ItemQuantity);
            Assert.AreEqual(190, cart.Total);
        }
示例#21
0
        public void CalculateTotalPrice_MultipleDifferentItems_ReturnsCorrectPrice()
        {
            // Arrange
            var shoppingCart = new ShoppingCart();

            shoppingCart.Add(_apple);
            shoppingCart.Add(_banana);
            shoppingCart.Add(_orange);

            // Act
            var price = shoppingCart.CalculateTotalPrice();

            // Assert
            Assert.Equal(_apple.Price + _banana.Price + _orange.Price, price);
        }
示例#22
0
        public void CalculateTotalPrice_MultipleSameItems_ReturnsCorrectPrice()
        {
            // Arrange
            var shoppingCart = new ShoppingCart();

            shoppingCart.Add(_apple);
            shoppingCart.Add(_apple);
            shoppingCart.Add(_apple);

            // Act
            var price = shoppingCart.CalculateTotalPrice();

            // Assert
            Assert.Equal(_apple.Price * 3, price);
        }
示例#23
0
        public void Remove_TwoSameItems_CountIsZero()
        {
            // Arrange
            var shoppingCart = new ShoppingCart();

            shoppingCart.Add(_apple);
            shoppingCart.Add(_apple);

            // Act
            shoppingCart.Remove(_apple);
            shoppingCart.Remove(_apple);

            // Assert
            Assert.Equal(0, shoppingCart.Count());
        }
示例#24
0
        public ActionResult Index()
        {
            ShoppingCart cart = new ShoppingCart();

            cart.Add(new ShoppingCartItem {
                Id = stockA, Quantity = 1, Name = "Adidas"
            });
            cart.Add(new ShoppingCartItem {
                Id = stockB, Quantity = 1, Name = "AF1"
            });
            cart.Add(new ShoppingCartItem {
                Id = stockC, Quantity = 1, Name = "AJ1"
            });
            return(View(cart));
        }
        // GET: ExampleJavaScriptResultApplication
        public ActionResult Index()
        {
            ShoppingCart cart = new ShoppingCart();

            cart.Add(new ShoppingCartItem {
                Id = stockA, Quantity = 2, Name = "Air Jordan篮球鞋"
            });
            cart.Add(new ShoppingCartItem {
                Id = stockB, Quantity = 1, Name = "衣服"
            });
            cart.Add(new ShoppingCartItem {
                Id = stockC, Quantity = 3, Name = "帽子"
            });
            return(View(cart));
        }
示例#26
0
        public void AddMultipleItemsWithDiscount()
        {
            var price1         = 0.80M;
            var price2         = 0.40M;
            var price3         = 0.60M;
            var discountPrice1 = 0.70M;

            var MockProductData = new ProductRepository
            {
                Products = new List <Product>
                {
                    new Product {
                        SKU = "sku1", Name = "Product1", Price = price1
                    },
                    new Product {
                        SKU = "sku2", Name = "Product2", Price = price2
                    },
                    new Product {
                        SKU = "sku3", Name = "Product3", Price = price3
                    }
                }
            };

            var MockProductDiscountData = new ProductDiscountRepository
            {
                ProductDiscounts = new List <ProductDiscount>
                {
                    new ProductDiscount
                    {
                        SKUKeys = new List <string> {
                            "sku2", "sku2"
                        },
                        Name  = "Discount1",
                        Price = discountPrice1
                    }
                }
            };

            var cart = new ShoppingCart(MockProductData, MockProductDiscountData);

            cart.Add("sku1");
            cart.Add("sku2");
            cart.Add("sku3");
            cart.Add("sku2");

            Assert.AreEqual(cart.TotalItems, 4);
            Assert.AreEqual(cart.TotalPrice, price1 + price3 + discountPrice1);
        }
示例#27
0
        public void ShoppingCartWithCouponDiscountWithMultipleLineItemsHasCorrectPriceTest()
        {
            // Arrange
            IShoppingCart           shoppingCart = new ShoppingCart();
            IEnumerable <ILineItem> lineItems    = new List <ILineItem>
            {
                new FixedPriceLineItem(1),
                new FixedPriceLineItem(2),
                new ByWeightLineItem(1, 1),
                new ByWeightLineItem(2, 1)
            };

            shoppingCart.Add(lineItems);
            IShoppingCart shoppingCartWithCouponDiscount = new ShoppingCartWithCouponDiscount(shoppingCart)
            {
                CouponDiscount = 10.00m
            };
            const decimal expectedPrice = 35.00m;

            // Act
            decimal actualPrice = shoppingCartWithCouponDiscount.GetPrice();

            // Assert
            Assert.That(actualPrice, Is.EqualTo(expectedPrice));
        }
示例#28
0
        protected void AddToCart()
        {
            ShopConfig shopConfig = SiteConfig.ShopConfig;

            if ((shopConfig.OrderProductNumber != 0) && (shopConfig.OrderProductNumber <= ShoppingCart.GetInfoByCart(this.cartId, false).Count))
            {
                DynamicPage.WriteErrMsg("<li>超出系统所设置的购物车商品种类数量:" + shopConfig.OrderProductNumber + "</li>", "ShoppingCart.aspx");
            }
            ShoppingCartInfo shoppingcartinfo   = new ShoppingCartInfo();
            int             productId           = 0;
            string          tableName           = string.Empty;
            CommonModelInfo commonModelInfoById = ContentManage.GetCommonModelInfoById(BasePage.RequestInt32("ID"));

            if (commonModelInfoById.IsNull)
            {
                DynamicPage.WriteErrMsg("<li>找不到指定的商品</li>");
            }
            else
            {
                productId = commonModelInfoById.ItemId;
                tableName = commonModelInfoById.TableName;
            }
            int         num3        = Order.CountBuyNum(PEContext.Current.User.UserName, productId);
            ProductInfo productById = Product.GetProductById(productId);
            int         minimum     = DataConverter.CLng(this.Page.Request.QueryString["Num"]);

            if ((productById.Minimum > minimum) && (productById.Minimum > 0))
            {
                minimum = productById.Minimum;
            }
            else if (minimum == 0)
            {
                minimum = 1;
            }
            if ((productById.LimitNum > 0) && ((num3 + minimum) > productById.LimitNum))
            {
                DynamicPage.WriteErrMsg(string.Concat(new object[] { "您订购了", num3, productById.Unit, productById.ProductName, ",曾经购买了", num3, productById.Unit, ",而此商品每人限购数量为", productById.LimitNum, productById.Unit, ",请重新调整您的购物车!" }), "ShoppingCart.aspx");
            }
            string property = DataSecurity.FilterBadChar(BasePage.RequestString("Property"));

            if (!this.ProductExist(this.cartId, productId, tableName, property))
            {
                if (Product.IsEnableSale(productId, tableName, property, this.cartId))
                {
                    shoppingcartinfo.Quantity   = minimum;
                    shoppingcartinfo.ProductId  = productId;
                    shoppingcartinfo.TableName  = tableName;
                    shoppingcartinfo.Property   = property;
                    shoppingcartinfo.UserName   = this.m_UserName;
                    shoppingcartinfo.UpdateTime = DateTime.Now;
                    shoppingcartinfo.IsPresent  = false;
                    shoppingcartinfo.CartId     = this.cartId;
                    ShoppingCart.Add(shoppingcartinfo);
                }
                else
                {
                    DynamicPage.WriteErrMsg(Product.ErrMsgOfEnableSale);
                }
            }
        }
示例#29
0
        private void ModifyCart()
        {
            ShoppingCartInfo shoppingcartinfo = new ShoppingCartInfo();

            shoppingcartinfo.UserName   = this.m_UserName;
            shoppingcartinfo.UpdateTime = DateTime.Now;
            shoppingcartinfo.CartId     = this.cartId;
            string[] strArray = this.GetParameterList("ChkProductId", "HdfProductId", "TxtProductAmount", "HdfTableName", "HdfProperty").Split(new string[] { "$$$" }, StringSplitOptions.RemoveEmptyEntries);
            this.m_ProductCount = strArray.Length;
            string[] strArray2 = this.GetPresentParameterList("ChkPresentId", "HdnPresentId", "LitPresentNum").Split(new string[] { "$$$" }, StringSplitOptions.RemoveEmptyEntries);
            ShoppingCart.Delete(this.cartId);
            for (int i = 0; i < strArray.Length; i++)
            {
                string[] strArray3 = strArray[i].Split(new char[] { ',' });
                shoppingcartinfo.IsPresent = false;
                shoppingcartinfo.ProductId = DataConverter.CLng(strArray3[0]);
                shoppingcartinfo.TableName = DataSecurity.FilterBadChar(strArray3[1]);
                shoppingcartinfo.Quantity  = DataConverter.CLng(strArray3[2], 1);
                shoppingcartinfo.Property  = DataSecurity.FilterBadChar(strArray3[3]);
                ShoppingCart.Add(shoppingcartinfo);
            }
            if (strArray2.Length != 0)
            {
                for (int j = 0; j < strArray2.Length; j++)
                {
                    string[] strArray4 = strArray2[j].Split(new char[] { ',' });
                    shoppingcartinfo.IsPresent = true;
                    shoppingcartinfo.ProductId = DataConverter.CLng(strArray4[0]);
                    shoppingcartinfo.Quantity  = DataConverter.CLng(strArray4[1]);
                    ShoppingCart.Add(shoppingcartinfo);
                }
            }
            this.RptShoppingCart_DataBind();
        }
示例#30
0
        public void AddSingleItemToCart()
        {
            var sku   = "sku1";
            var price = 0.30M;

            var MockProductData = new ProductRepository
            {
                Products = new List <Product>
                {
                    new Product {
                        SKU = sku, Name = "Product", Price = price
                    }
                }
            };

            var MockProductDiscountData = new ProductDiscountRepository
            {
                ProductDiscounts = new List <ProductDiscount>()
            };

            var cart = new ShoppingCart(MockProductData, MockProductDiscountData);

            cart.Add(sku);

            Assert.AreEqual(cart.TotalItems, 1);
            Assert.AreEqual(cart.TotalPrice, price);
        }
示例#31
0
        public void PercentDiscount()
        {
            List <ICheckoutRule> rules = new List <ICheckoutRule>();

            rules.Add(new PercentDiscountRule(10));

            ShoppingCart cart = new ShoppingCart(rules);

            cart.Add(new Product("TypeA", 20.0m));
            cart.Add(new Product("TypeB", 100.0m));


            decimal total = cart.GetTotal();

            Assert.Equal(120.0m - 12m, total);
        }
示例#32
0
        public void ShoppingCartCanAddProducts()
        {
            var cart = new ShoppingCart();

            cart.Add(new Product());

            Assert.AreEqual(1, cart.Items.Count);
        }
示例#33
0
        public void ShoppingCartCanClear()
        {
            var cart = new ShoppingCart();

            cart.Add(new Product());
            cart.Clear();

            Assert.AreEqual(0, cart.Items.Count);
        }
示例#34
0
 public ActionResult Index()
 {
     ShoppingCart cart = new ShoppingCart();
     cart.Add(new ShoppingCartItem
     {
         Id = "001",
         Quantity = 1,
         Name = "商品A"
     });
     cart.Add(new ShoppingCartItem
     {
         Id = "002",
         Quantity = 1,
         Name = "商品B"
     });
     cart.Add(new ShoppingCartItem
     {
         Id = "003",
         Quantity = 1,
         Name = "商品C"
     });
     return View(cart);
 }