コード例 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Shopping cart demo");

            var ruleProvider = new DiscountRuleProvider(new List <IDiscountRule>()
            {
                new Buy3MilksGet4thFreeRule(),
                new Buy2ButtersGet1Bread50Off()
            });
            var analyticsLog = new AnalyticsConsoleLog();

            var basket = new Basket(analyticsLog, ruleProvider);

            var milk = new Product()
            {
                Name = "Milk", Price = 1.15
            };
            var bread = new Product()
            {
                Name = "Bread", Price = 1
            };
            var butter = new Product()
            {
                Name = "Butter", Price = 0.8
            };

            basket.AddToBasket(milk, 8);
            basket.AddToBasket(bread, 1);
            basket.AddToBasket(butter, 2);

            basket.GetTotal();
            Console.ReadLine();
        }
コード例 #2
0
        public void AddToBasket_NoProductsInBasketGivenNULLProduct_ProductNotAddedToBasket()
        {
            Product productToAdd = null;

            basket.AddToBasket(productToAdd);

            Assert.AreEqual(0, basket.Lines.Count);
        }
コード例 #3
0
        public void TestGetBasketCostNoVoucher()
        {
            Basket basket = new Basket();

            basket.AddToBasket(fakePizza1);
            basket.AddToBasket(fakePizza2);
            basket.SetBasketCost();
            Assert.AreEqual(16, basket.GetTotalCost());
        }
        public void Basket_With_5_Butter_And_1_Bread_Returns_0_50_Discount()
        {
            var basket = new Basket();

            basket.AddToBasket(_testButter, 5);
            basket.AddToBasket(_testBread);

            var discount = _butterAndBreadDiscount.ApplyDiscount(basket);

            discount.Should().Be(0.50m);
        }
コード例 #5
0
        public void Basket_With_2_Butter_And_2_Bread_Returns_Cost_Of_3_10()
        {
            var basket = new Basket();

            basket.AddToBasket(_testBread, 2);
            basket.AddToBasket(_testButter, 2);

            var cost = _basketCalculator.GetCostOfBasket(basket);

            cost.Should().Be(3.10m);
        }
コード例 #6
0
        public void Cannot_Add_Product_Quantity_Less_Than_1()
        {
            var basket = new Basket();

            basket.AddToBasket(_testBread, 0);
            basket.AddToBasket(_testBread, -6);

            var qty = basket.GetProductQtyById(_testBread.Id);

            qty.Should().Be(0);
        }
コード例 #7
0
        public void Basket_With_2_Butter_And_1_Bread_8_Milk_Returns_Cost_Of_9_00()
        {
            var basket = new Basket();

            basket.AddToBasket(_testButter, 2);
            basket.AddToBasket(_testBread);
            basket.AddToBasket(_testMilk, 8);

            var cost = _basketCalculator.GetCostOfBasket(basket);

            cost.Should().Be(9.00m);
        }
コード例 #8
0
        public void Basket_With_1_Bread_1_Milk_1_Butter_Returns_2_95()
        {
            var basket = new Basket();

            basket.AddToBasket(_testBread);
            basket.AddToBasket(_testMilk);
            basket.AddToBasket(_testButter);

            var cost = _basketCalculator.GetCostOfBasket(basket);

            cost.Should().Be(2.95m);
        }
コード例 #9
0
        public void Add_Same_Product_Multiple_Times_Increases_Product_Quantity()
        {
            var basket = new Basket();

            basket.AddToBasket(_testButter, 3);
            basket.AddToBasket(_testButter);
            basket.AddToBasket(_testButter, 6);

            var qty = basket.GetProductQtyById(_testButter.Id);

            qty.Should().Be(10);
        }
コード例 #10
0
        public void Basket_With_Same_Product_Multiple_Times_Returns_Product_Price_Times_Quantity()
        {
            var basket = new Basket();

            basket.AddToBasket(_testBread, 4);
            basket.AddToBasket(_testBread);
            basket.AddToBasket(_testBread, 1);

            var cost = _basketCalculator.GetCostOfBasket(basket);

            cost.Should().Be(6.0m);
        }
コード例 #11
0
        public void Test_ClearingBasketAndDiscount()
        {
            Basket basket = new Basket();

            basket.AddToBasket("Small Parcel", 3);
            basket.GetParcelWeight("1", "4");
            basket.GetSpeedyShipping("1");
            basket.AddToBasket("Small Parcel", 3);
            basket.AddToBasket("Additional Weight Cost", 0);
            basket.GetSpeedyShipping("1");
            basket.AddToBasket("Small Parcel", 3);
            basket.GetParcelWeight("1", "3");
            basket.GetSpeedyShipping("1");
            basket.AddToBasket("Small Parcel", 3);
            basket.GetParcelWeight("1", "3");
            basket.AddToBasket("Speedy Shipping", 0);
            basket.GetSmallBasketDiscounts(); // Add discount to parcels
            basket.Clear();                   // Clear basket
            basket.AddToBasket("Small Parcel", 3);
            basket.AddToBasket("Additional Weight Cost", 0);
            basket.GetSpeedyShipping("1");
            decimal totalPrice = basket.GetBasketTotalPrice();

            Assert.AreEqual(totalPrice, 6);
        }
コード例 #12
0
        public void Basket_With_Multiple_Products_Multiple_Times_Returns_Correct_Cost_Sum()
        {
            var basket = new Basket();

            basket.AddToBasket(_testBread, 4);
            basket.AddToBasket(_testMilk);
            basket.AddToBasket(_testBread, 1);
            basket.AddToBasket(_testButter, 2);
            basket.AddToBasket(_testMilk, 3);

            var cost = _basketCalculator.GetCostOfBasket(basket);

            cost.Should().Be(11.20m);
        }
コード例 #13
0
        public ActionResult AddToBasket(int id, int quantity)
        {
            Basket basket = Basket.GetBasket();

            basket.AddToBasket(id, quantity);
            return(RedirectToAction("Index"));
        }
コード例 #14
0
        public void TestGetBasketCostWithVoucher()
        {
            Basket basket = new Basket();

            basket.AddToBasket(fakePizza1);
            basket.AddToBasket(fakePizza2);
            basket.SetBasketCost();
            string  voucherCode = "2SMALLCOLL";
            Voucher voucher     = new Voucher();

            voucher.VoucherCode = voucherCode;
            voucher.CheckValidVoucher(VR.GetWhere(voucherCode, null, true));
            basket.Voucher  = voucher;
            basket.Delivery = "Collection";
            basket.CheckVoucherConditions();
            Assert.AreEqual(12, basket.GetTotalCost());
        }
コード例 #15
0
    void main()
    {
        Basket bsk = new Basket();
        parent pnt = new parent();
        Lemon  lmn = new Lemon();

        bsk.AddToBasket(lmn);// is this OK?
    }
コード例 #16
0
        public ActionResult AddToBasket(MultipleModelInOneView viewModel, FormCollection form)
        {
            Basket basket   = Basket.GetBasket();
            int    quantity = Int32.Parse(form["quantity"]);

            basket.AddToBasket(viewModel.Products.ID, quantity, viewModel.Orders.IMEI);
            return(RedirectToAction("Index"));
        }
コード例 #17
0
        static void Main()
        {
            Basket basket = new Basket();

            Console.WriteLine("Welcome, to add a product to your basket and to see your receipt, please enter one of the following options.");
            DisplayInputMessage();

            string userInput = "";

            while (userInput != "/")
            {
                userInput = Console.ReadLine();
                switch (userInput)
                {
                case "1":
                    basket.AddToBasket(Products.Bread);
                    DisplayBill(basket);
                    break;

                case "2":
                    basket.AddToBasket(Products.Milk);
                    DisplayBill(basket);
                    break;

                case "3":
                    basket.AddToBasket(Products.Cheese);
                    DisplayBill(basket);
                    break;

                case "4":
                    basket.AddToBasket(Products.Soup);
                    DisplayBill(basket);
                    break;

                case "5":
                    basket.AddToBasket(Products.Butter);
                    DisplayBill(basket);
                    break;

                default:
                    Console.WriteLine("Apologies we didn't recognise that options, please try again.");
                    break;
                }
            }
        }
コード例 #18
0
        public void Null_Product_Returns_No_Products()
        {
            var basket = new Basket();

            basket.AddToBasket(null);

            var basketProducts = basket.GetBasketProducts();

            basketProducts.Length.Should().Be(0);
        }
コード例 #19
0
        public void Basket_With_Single_Product_Returns_Product_Price()
        {
            var basket = new Basket();

            basket.AddToBasket(_testButter);

            var cost = _basketCalculator.GetCostOfBasket(basket);

            cost.Should().Be(0.80m);
        }
コード例 #20
0
        public void Basket_With_4_Milk_Returns_Cost_Of_3_45()
        {
            var basket = new Basket();

            basket.AddToBasket(_testMilk, 4);

            var cost = _basketCalculator.GetCostOfBasket(basket);

            cost.Should().Be(3.45m);
        }
        public void Basket_With_2_Butter_And_No_Bread_Returns_0_Discount()
        {
            var basket = new Basket();

            basket.AddToBasket(_testButter, 2);

            var discount = _butterAndBreadDiscount.ApplyDiscount(basket);

            discount.Should().Be(0);
        }
コード例 #22
0
        public void Add_Product_To_Basket_Stores_Product()
        {
            var basket = new Basket();

            basket.AddToBasket(_testBread);

            var qty = basket.GetProductQtyById(_testBread.Id);

            qty.Should().Be(1);
        }
コード例 #23
0
        public void Basket_With_4_Milk_Returns_Discount_Of_Price_Of_Milk()
        {
            var basket = new Basket();

            basket.AddToBasket(_testMilk, 4);

            var discount = _freeMilkDiscount.ApplyDiscount(basket);

            discount.Should().Be(_testMilk.Price);
        }
コード例 #24
0
        public void Basket_With_0_To_3_Milk_Returns_0_Discount(int milkCount)
        {
            var basket = new Basket();

            basket.AddToBasket(_testMilk, milkCount);

            var discount = _freeMilkDiscount.ApplyDiscount(basket);

            discount.Should().Be(0);
        }
コード例 #25
0
        public void Basket_With_8_Milk_Returns_Discount_Of_2_Times_Price_Of_Milk()
        {
            var basket = new Basket();

            basket.AddToBasket(_testMilk, 8);

            var discount = _freeMilkDiscount.ApplyDiscount(basket);

            var expectedDiscount = _testMilk.Price * 2.0m;

            discount.Should().Be(expectedDiscount);
        }
コード例 #26
0
        public void AddToCart(int id)
        {
            BasketItem b = new BasketItem();
            Product    p = utc.Products.FirstOrDefault(x => x.id == id);

            b.Product  = p;
            b.Quantity = 1;
            b.Discount = 0;

            Basket k = new Basket();

            k.AddToBasket(b);
        }
コード例 #27
0
        public ActionResult AddToBasket(Basket basket2, int?Oppor_Id)
        {
            if (Oppor_Id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tbl_Opportunity addedItem = db.tbl_Opportunity.Find(Oppor_Id);


            Basket basket = Basket.GetBasket(this.HttpContext);

            basket.AddToBasket(basket, addedItem);
            return(RedirectToAction("Index", "Opportunity"));
        }
コード例 #28
0
        public void AddToBasket(int id)
        {
            BasketItem bi = new BasketItem();

            Book book = db.Books.FirstOrDefault(x => x.Id == id);

            bi.Book     = book;
            bi.Quantity = 1;
            Basket b = new Basket();

            b.AddToBasket(bi);

            BasketWidget();
        }
コード例 #29
0
ファイル: OrderController.cs プロジェクト: Mallard6/portfolio
        public ActionResult Menu(string basePizza, string baseSize, List <string> Toppings, string voucherCode)
        {
            ViewBag.pizzaList   = PizzaRepository.ToPropertyList("Name");
            ViewBag.sizeList    = PizzaRepository.ToPropertyList("Size");
            ViewBag.toppingList = ToppingRepository.ToPropertyList("Name");

            Basket  basket  = GetSessionBasket();
            Voucher Voucher = new Voucher();

            if (voucherCode != null)
            {
                Voucher.VoucherCode = voucherCode;
                Voucher.CheckValidVoucher(VoucherRepository.GetWhere(voucherCode, null, true));
                if (Voucher.IsValid)
                {
                    if (basket.Voucher == null)
                    {
                        basket.Voucher = Voucher;
                    }
                    else
                    {
                        Voucher currentVoucher = basket.Voucher;
                        if (currentVoucher.VoucherCode != voucherCode)
                        {
                            basket.Voucher = Voucher;
                        }
                    }
                }
                SetSessionBasket(basket);
            }
            else if (basket.Voucher != null)
            {
                Voucher = basket.Voucher;
            }
            ViewBag.VoucherMessage = Voucher.VoucherMessage;
            if (basePizza != null && baseSize != null)
            {
                Pizza pizza = GetBase(basePizza, baseSize);
                pizza.InMenu   = false;
                pizza.Toppings = GetToppings(Toppings, pizza);
                pizza.CalculateTotalCost();
                basket.AddToBasket(pizza);
                SetSessionBasket(basket);
                ViewBag.Basket    = basket;
                ViewBag.TotalCost = basket.GetTotalCost();
            }
            return(View());
        }
コード例 #30
0
        public void TestCaseOne()
        {
            Shop Shop = new Shop(new CashDesk(50));

            Basket Basket1 = new Basket();

            Basket1.AddToBasket(
                new Product[] {
                new Product("Hat", 10.50m, ProductCategory.Hats, Currencies.GBP, 1),
                new Product("Jumper", 54.65m, ProductCategory.Jumpers, Currencies.GBP, 1)
            });

            Assert.AreEqual(60.15m,
                            Shop.GetTotal(Basket1,
                                          new Voucher("XXX-XXX", 5.00m, Currencies.GBP, VoucherType.Gift))
                            );
        }