public void getTotalCost_multipleItem_withPromoReducePrice_meetPromoQuantityAndMore_returnCorrectValue()
        {
            GroceryItemData groceryItem   = getGroceryItemData_meetPromoQuantityAndMore(PromoUtil.PromoReducePriceIfMeetQuantity);
            decimal         expectedValue = REGULAR_PRICE * (groceryItem.Count - QUANTITY) + PROMO_PRICE;

            Assert.AreEqual(expectedValue, Math.Round(groceryItem.getTotalCost(), 2));
        }
Ejemplo n.º 2
0
        private GroceryItemData getGroceryItemData(string item, decimal regularPrice, decimal promoPrice)
        {
            GroceryItemData groceryItemData = new GroceryItemData(item, regularPrice);

            groceryItemData.setPromotionInfo(PromoUtil.PromoReducePrice, promoPrice, 1);
            return(groceryItemData);
        }
        public void getTotalCost_multipleItem_withPromoBuyOneGetOneHalfOff_meetPromoQuantityAndMore_returnCorrectValue()
        {
            GroceryItemData groceryItem   = getGroceryItemData_meetPromoQuantityAndMore(PromoUtil.PromoBuyOneGetOneHalfOff);
            decimal         expectedValue = REGULAR_PRICE + REGULAR_PRICE + REGULAR_PRICE / 2;

            Assert.AreEqual(expectedValue, groceryItem.getTotalCost());
        }
        public HttpResponseMessage ItemByType(string type = "All")
        {
            using (GroceryItemData items = new GroceryItemData())
            {
                switch (type.ToLower())
                {
                case "fruit":
                    return(Request.CreateResponse(HttpStatusCode.OK,
                                                  items.GroceryItems.Where(e => e.ItemType.ToLower() == "fruit").ToList()));

                case "bakery":
                    return(Request.CreateResponse(HttpStatusCode.OK,
                                                  items.GroceryItems.Where(e => e.ItemType.ToLower() == "bakery").ToList()));

                case "vegitable":
                    return(Request.CreateResponse(HttpStatusCode.OK,
                                                  items.GroceryItems.Where(e => e.ItemType.ToLower() == "vegitable").ToList()));

                case "all":
                    return(Request.CreateResponse(HttpStatusCode.OK, items.GroceryItems.ToList()));


                default:
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "please try again"));
                }
            }
        }
        public void getTotalSavings_multipleItem_noPromo_returnCorrectValue()
        {
            int             quantity    = 2;
            GroceryItemData groceryItem = new GroceryItemData(PRODUCT, REGULAR_PRICE);

            groceryItem.Count = quantity;
            Assert.AreEqual(0 * groceryItem.Count, groceryItem.getTotalSavings());
        }
        private GroceryItemData getGroceryItemData_meetPromoQuantityAndMore(int promo)
        {
            GroceryItemData groceryItem = new GroceryItemData(PRODUCT, REGULAR_PRICE);

            groceryItem.setPromotionInfo(promo, PROMO_PRICE, QUANTITY);
            groceryItem.Count = QUANTITY + 1;
            return(groceryItem);
        }
Ejemplo n.º 7
0
        private GroceryItemData getGroceryItemData(string item)
        {
            GroceryItemData groceryItemData = new GroceryItemData(item, 1.50m);

            return(groceryItemData);
        }
        public void getTotalSavings_oneItem_noPromo_returnCorrectValue()
        {
            GroceryItemData groceryItem = new GroceryItemData(PRODUCT, REGULAR_PRICE);

            Assert.AreEqual(0, groceryItem.getTotalSavings());
        }
        public void getTotalCost_multipleItem_withPromoBuyOneGetOneHalfOff_meetPromoQuantity_returnCorrectValue()
        {
            GroceryItemData groceryItem = getGroceryItemData_meetPromoQuantity(PromoUtil.PromoBuyOneGetOneHalfOff);

            Assert.AreEqual(REGULAR_PRICE + REGULAR_PRICE / 2, groceryItem.getTotalCost());
        }
Ejemplo n.º 10
0
        public void getTotalCost_multipleItem_withPromoBuyOneGetOneFree_doesNotMeetPromoQuantity_returnCorrectValue()
        {
            GroceryItemData groceryItem = getGroceryItemData_doesNotMeetPromoQuantity(PromoUtil.PromoBuyOneGetOneFree);

            Assert.AreEqual(REGULAR_PRICE * groceryItem.Count, Math.Round(groceryItem.getTotalCost(), 2));
        }
Ejemplo n.º 11
0
        public void getTotalCost_multipleItem_withPromoReducePrice_meetPromoQuantity_returnCorrectValue()
        {
            GroceryItemData groceryItem = getGroceryItemData_meetPromoQuantity(PromoUtil.PromoReducePriceIfMeetQuantity);

            Assert.AreEqual(PROMO_PRICE, groceryItem.getTotalCost());
        }
Ejemplo n.º 12
0
        public void getTotalSavings_multipleItem_withPromoBuyOneGetOneFree_doesNotMeetPromoQuantity_returnCorrectValue()
        {
            GroceryItemData groceryItem = getGroceryItemData_doesNotMeetPromoQuantity(PromoUtil.PromoBuyOneGetOneFree);

            Assert.AreEqual(0, Math.Round(groceryItem.getTotalSavings(), 2));
        }
Ejemplo n.º 13
0
        public void getTotalSavings_multipleItem_withPromoReducePrice_meetPromoQuantity_returnCorrectValue()
        {
            GroceryItemData groceryItem = getGroceryItemData_meetPromoQuantity(PromoUtil.PromoReducePriceIfMeetQuantity);

            Assert.AreEqual((REGULAR_PRICE * QUANTITY - PROMO_PRICE), groceryItem.getTotalSavings());
        }