示例#1
0
        public void AddItem(GrocItem gi)
        {
            if (_priceService != null)
            {
                double price = _priceService.LookUpPrice(gi);
                gi.ItemPrice = price;
            }

            _itemList.Add(gi);
        }
示例#2
0
 public void testItemsEnteredOneAtATime()
 {
     CashRegister cr = new CashRegister();
     GrocItem gi_one = new GrocItem("Bread");
     cr.AddItem(gi_one);
     Assert.AreEqual(1, cr.ItemCount);
     GrocItem gi_two = new GrocItem("Milk");
     cr.AddItem(gi_two);
     Assert.AreEqual(2, cr.ItemCount);
 }
示例#3
0
        public void testFoodItemTypes()
        {
            FoodTypeService fts = new FoodTypeService();

            GrocItem giFood = new GrocItem("Burger", fts);
            GrocItem giNonFood = new GrocItem("Light Bulb", fts);

            Assert.AreEqual(FoodType.FOOD, giFood.ItemFoodType);
            Assert.AreEqual(FoodType.NONFOOD, giNonFood.ItemFoodType);
        }
示例#4
0
        public void testAssignItemPrice()
        {
            CashRegister cr = new CashRegister(new PriceService());

            GrocItem giFood = new GrocItem("Burger");
            cr.AddItem(giFood);
            Assert.AreEqual(5.0, cr.Item(0).ItemPrice);

            GrocItem giNonFood = new GrocItem("Tooth Picks");
            cr.AddItem(giNonFood);
            Assert.AreEqual(0.99, cr.Item(1).ItemPrice);
        }
示例#5
0
        public double CalcItemTax(GrocItem gi)
        {
            double tax = 0.0;

            if (gi.ItemFoodType == FoodType.FOOD)
            {
                tax = gi.ItemPrice * 0.03;
            }
            else
            {
                tax = gi.ItemPrice * 0.07;
            }

            return tax;
        }
示例#6
0
        public double LookUpPrice(GrocItem gi)
        {
            string upper = gi.ItemName.ToUpper();
            double price = 0.0;

            if (upper.Equals("BURGER"))
            {
                price = 5.0;
            }
            else if (upper.Equals("BREAD"))
            {
                price = 2.99;
            }
            else if (upper.Equals("MILK"))
            {
                price = 3.99;
            }
            else if (upper.Equals("CEREAL"))
            {
                price = 4.39;
            }
            else if (upper.Equals("COFFEE"))
            {
                price = 7.49;
            }

            else if (upper.Equals("LIGHT BULB"))
            {
                price = 1.99;
            }
            else if (upper.Equals("TOOTH PICKS"))
            {
                price = 0.99;
            }
            else if (upper.Equals("CHARCOAL"))
            {
                price = 8.99;
            }
            else if (upper.Equals("PAPER TOWELS"))
            {
                price = 6.59;
            }

            return price;
        }
示例#7
0
        public void testFinalSummaryOutput()
        {
            PriceService ps = new PriceService();
            CashRegister cr = new CashRegister(ps);
            FoodTypeService fts = new FoodTypeService();

            String desiredOut = "Food Items: 2 NonFood Items: 1 Food Tax: 0.24 "
                + "NonFood Tax: 0.14 Subtotal: 9.98 Order Total: 10.36";

            GrocItem giFood1 = new GrocItem("Burger", fts);
            GrocItem giFood2 = new GrocItem("Bread", fts);

            GrocItem giNonFood = new GrocItem("Light Bulb", fts);

            cr.AddItem(giFood1);
            cr.AddItem(giFood2);
            cr.AddItem(giNonFood);

            String receipt = cr.PrintFinalTotals();

            Assert.AreEqual(desiredOut, receipt);
        }
示例#8
0
        public void testItemTax()
        {
            CashRegister cr = new CashRegister(new PriceService());

            GrocItem giFood = new GrocItem("Burger");
            cr.AddItem(giFood);

            double itemTax = cr.CalcItemTax(giFood);

            Assert.AreEqual(5.00 * 0.03, itemTax);
        }
示例#9
0
        public void testDefaultFoodType()
        {
            GrocItem gi = new GrocItem("Burger");

            Assert.AreEqual(FoodType.FOOD, gi.ItemFoodType);
        }