public void GetPrice()
        {
            var itemOne = new Item { BarCodeId = 111 };//Apple barcode
             var itemTwo = new Item { BarCodeId = 222 };//Orange barcode
             var items = new List<Item> { itemOne, itemTwo };
             var priceCalculationResource = new PriceCalculationResource { Items = items };

             var manager = new PriceCalculationManager();
             var result = manager.CalculatePrice(priceCalculationResource);

             Assert.IsNotNull(result);
             Assert.IsTrue(result.TotalPrice.ToString() == "0.85");
        }
        public Task<HttpResponseMessage> GetPriceOffer(PriceCalculationResource priceCalculationResource)
        {
            return this.TryWork(async () =>
            {
                try
                {
                    //call PriceCalculationManager to calculate price of the passed data contract
                    var priceCalculationManager = new PriceCalculationManager();
                    var priceCalculationStatusResource = priceCalculationManager.CalculatePrice(priceCalculationResource,true);

                    return Request.CreateResponse(HttpStatusCode.OK, priceCalculationStatusResource);

                }
                catch (Exception ex)
                {
                    return Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, ex);
                }
            }
            );
        }
        public void GetPricewithOffer()
        {
            var itemApple1 = new Item { BarCodeId = 111 };//Apple barcode
             var itemApple2 = new Item { BarCodeId = 111 };//Apple barcode
             var itemApple3 = new Item { BarCodeId = 111 };//Apple barcode
             var itemApple4 = new Item { BarCodeId = 111 };//Apple barcode
             var itemApple5 = new Item { BarCodeId = 111 };//Apple barcode
             var itemOrange1 = new Item { BarCodeId = 222 };//Orange barcode
             var itemOrange2 = new Item { BarCodeId = 222 };//Orange barcode
             var itemOrange3 = new Item { BarCodeId = 222 };//Orange barcode
             var itemOrange4 = new Item { BarCodeId = 222 };//Orange barcode

             var items = new List<Item> { itemApple1,itemApple2,itemApple3,itemApple4,itemApple5,itemOrange1,itemOrange2,
                 itemOrange3, itemOrange4 };
             var priceCalculationResource = new PriceCalculationResource { Items = items };

             var manager = new PriceCalculationManager();
             var result = manager.CalculatePrice(priceCalculationResource);

             Assert.IsNotNull(result);
             Assert.IsTrue(result.TotalPrice.ToString() == "2.3");
        }
        public void GetPriceWithOffer()
        {
            var itemOne = new Item { BarCodeId = 111 };//Apple barcode
            var itemTwo = new Item { BarCodeId = 222 };//Orange barcode
            var items = new List<Item> { itemOne, itemTwo };
            var priceCalculationResource = new PriceCalculationResource { Items = items };
            var content = JsonConvert.SerializeObject(priceCalculationResource);
            byte[] byteArray = Encoding.UTF8.GetBytes(content);

            HttpWebResponse response = null;

            var theRequest = (HttpWebRequest)WebRequest.Create("http://localhost:27387/api/getprice/Offer");
            theRequest.ContentType = "application/Json";
            theRequest.Method = WebRequestMethods.Http.Post;
            theRequest.ContentLength = content.Length;

            var requestStream = theRequest.GetRequestStream();
            requestStream.Write(byteArray, 0, byteArray.Length);
            requestStream.Close();

            response = (HttpWebResponse)theRequest.GetResponse();

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }