/**
         * Save an item. If an item with the same sku already exists, it will be replaced.
         */
        public void SaveItem(Item item)
        {
            if (itemsBySku.ContainsKey(item.GetSku()))
            {
                itemsBySku.Remove(item.GetSku());
            }

            itemsBySku.Add(item.GetSku(), item);
        }
        public void TestConstructorWithSpecialOffer()
        {
            Supermarket.Item item = new Supermarket.Item("Bob", 123, 2, 210);

            Assert.AreEqual(item.GetSku(), "Bob");
            Assert.AreEqual(item.GetPrice(), 123);
            Assert.IsTrue(item.HasSpecialOffer());
            Assert.AreEqual(item.GetSpecialOfferMultiple(), 2);
            Assert.AreEqual(item.GetSpecialOfferPrice(), 210);
        }
        public void TestConstructorWithoutSpecialOffer()
        {
            Supermarket.Item item = new Supermarket.Item("Rob", 456);

            Assert.AreEqual(item.GetSku(), "Rob");
            Assert.AreEqual(item.GetPrice(), 456);
            Assert.IsFalse(item.HasSpecialOffer());
            Assert.AreEqual(item.GetSpecialOfferMultiple(), 0);
            Assert.AreEqual(item.GetSpecialOfferPrice(), 0);
        }
Beispiel #4
0
        /**
         * Get the total price for the items that have been scanned
         */
        public double GetTotalPrice()
        {
            double total = 0;

            foreach (var sku in itemCountsBySku.Keys)
            {
                Item item = itemRepository.FindItem(sku);

                if (item == null)
                {
                    throw new SupermarketException("Missing item: " + sku);
                }

                int itemCount = itemCountsBySku[item.GetSku()];
                total += GetSubtotalForItem(item, itemCount);
            }

            return(total);
        }
 /**
  * Remove an item, if it doesn't exist, this method will just return without
  * doing anything.
  */
 public void RemoveItem(Item item)
 {
     itemsBySku.Remove(item.GetSku());
 }