Esempio n. 1
0
        public void SumPrices_ZeroQuantity()
        {
            List <Item> testList = new List <Item>();
            Item        item1    = new Item();
            Item        item2    = new Item();
            Item        item3    = new Item();

            item1.price    = 13.89;
            item1.quantity = 73;
            item2.price    = 4.30;
            item2.quantity = 5;
            item3.price    = 9.99;
            item3.quantity = 0;
            testList.Add(item1);
            testList.Add(item2);
            testList.Add(item3);

            double actual = PriceInfo.TotalPrice(testList);
        }
Esempio n. 2
0
        public IHttpActionResult Get()
        {
            IHttpActionResult ret = NotFound();

            // Retrieves the current database to get all orders so far.
            using (var db = new LiteDatabase(@"C:\Users\Public\MyDB.db"))
            {
                var         items  = db.GetCollection <Item>("items");
                var         Tester = items.Find(Query.All());
                List <Item> thing  = Tester.ToList();

                // Uses the TotalPrice method to sum all of the item prices that have been ordered.
                Item   finalPriceItem = new Item();
                double total          = PriceInfo.TotalPrice(thing);
                finalPriceItem.price = total;
                thing.Add(finalPriceItem);

                // Returns the final list of items that have been ordered along with the sum price.
                ret = Ok(thing);
            }
            return(ret);
        }
Esempio n. 3
0
        public void SumPrices_ValidAmounts_QuantityMultiple()
        {
            List <Item> testList = new List <Item>();
            Item        item1    = new Item();
            Item        item2    = new Item();
            Item        item3    = new Item();

            item1.price    = 13.89;
            item1.quantity = 73;
            item2.price    = 4.30;
            item2.quantity = 5;
            item3.price    = 9.99;
            item3.quantity = 900;
            double expected = 10026.47;

            testList.Add(item1);
            testList.Add(item2);
            testList.Add(item3);

            double actual = PriceInfo.TotalPrice(testList);

            Assert.AreEqual(expected, actual, 0.001, "Amounts are unequal");
        }