public void testStoreOrder()
        {
            try {
                //week 3
                //IOrderSvc ics = factory.getOrderSvc();

                //week 4
                IOrderSvc ics = (IOrderSvc)factory.getService("IOrderSvc");

                // First let's store the Order
                Assert.True(ics.storeOrder(o));

                // Then let's read it back in
                o = ics.getOrder(o.id);
                Assert.True(o.validate());

                // Update the Order
                o.isComplete = true;
                o.isSubmitted = true;
                Assert.True(ics.storeOrder(o));

                // Finally, let's cleanup the file that was created
                Assert.True(ics.deleteOrder(o.id));
            }
            catch(Exception e) {
                Console.WriteLine("Exception in testStoreOrder: " + e.Message + "\n" + e.StackTrace);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }
        public void testInvalidOrder()
        {
            try {
                Order o = new Order();

                Assert.False(o.validate());
            }
            catch(Exception e) {
                Console.WriteLine("Exception in testInvalidOrder: " + e.Message + "\n" + e.StackTrace);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }
Example #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public Boolean updateOrder(Order o)
        {
            dLog.Debug("In updateOrder");
            Boolean result = false;

            try
            {
                if (o.validate())
                {
                    if (orderSvc.storeOrder(o))
                        result = true;
                }
            }
            catch (Exception e)
            {
                dLog.Debug("Exception in updateOrder: " + e.Message + "\n" + e.StackTrace);
                result = false;
            }

            dLog.Debug("updateOrder result: " + result);
            return result;
        }
Example #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public Boolean submitOrder(Order o)
        {
            dLog.Debug("In submitOrder");
            Boolean result = false;

            try
            {
                if (o.validate())
                {
                    dLog.Debug("Order ID: " + o.id + " | Size: " + o.burritos.Count + " | Total Cost: " + o.totalCost);

                    // ensure we have at least one burrito and the cost of the burritos has been calculated
                    if (o.burritos.Count > 0 && o.totalCost > 0)
                    {
                        // set order submitted flag
                        o.isSubmitted = true;

                        // store updated Order
                        if (orderSvc.storeOrder(o))
                            result = true;
                    }
                }
            }
            catch (Exception e)
            {
                dLog.Debug("Exception in submitOrder: " + e.Message + "\n" + e.StackTrace);
                result = false;
            }

            dLog.Debug("submitOrder result: " + result);
            return result;
        }
        public void testValidateOrder()
        {
            try {
                Order o = new Order();
                o.burritos = new List<Burrito>();
                o.burritos.Add(new Burrito(1, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, Decimal.Parse("0.00")));
                o.orderDate = DateTime.Now;
                o.isComplete = true;
                o.isSubmitted = true;
                o.id = 1;
                o.totalCost = Decimal.Parse("17.00");

                Assert.True(o.validate());
            }
            catch(Exception e) {
                Console.WriteLine("Exception in testValidateOrder: " + e.Message + "\n" + e.StackTrace);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }
        /// <summary>
        /// This method stores a order.
        /// </summary>
        /// <param name="o">The order object to store</param>
        /// <returns>Success/Failure</returns>
        public Boolean storeOrder(Order o)
        {
            dLog.Info("Entering method storeOrder | ID: " + o.id);
            Stream output = null;
            Boolean result = false;

            try
            {
                //ensure we were passed a valid object before attempting to write
                if (o.validate())
                {
                    output = File.Open("Order_" + o.id + ".txt", FileMode.Create);
                    BinaryFormatter bFormatter = new BinaryFormatter();
                    bFormatter.Serialize(output, o);
                    result = true;
                }
            }
            catch (IOException e1)
            {
                dLog.Error("IOException in storeOrder: " + e1.Message);
                result = false;
            }
            catch (Exception e2)
            {
                dLog.Error("Exception in storeOrder: " + e2.Message);
                result = false;
            }
            finally
            {
                //ensure that output is close regardless of the errors in try/catch
                if (output != null)
                {
                    output.Close();
                }
            }

            return result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="i"></param>
        /// <param name="o"></param>
        /// <returns></returns>
        public Boolean returnToInventory(Inventory i, Order o)
        {
            dLog.Debug("In returnToInventory");
            Boolean result = false;

            try
            {
                if (i.validate() && o.validate())
                {
                    // loop through all burritos on the order and add to inventory
                    foreach (Burrito b in o.burritos)
                    {
                        if (b.Beef) i.setBeefQty(i.BeefQty + 1);
                        if (b.Chicken) i.setChickenQty(i.ChickenQty + 1);
                        if (b.Hummus) i.setHummusQty(i.HummusQty + 1);

                        //calculate remaining extras
                        if (b.ChiliTortilla) i.setChiliTortillaQty(i.ChiliTortillaQty + 1);
                        if (b.HerbGarlicTortilla) i.setHerbGarlicTortillaQty(i.HerbGarlicTortillaQty + 1);
                        if (b.JalapenoCheddarTortilla) i.setJalapenoCheddarTortillaQty(i.JalapenoCheddarTortillaQty + 1);
                        if (b.TomatoBasilTortilla) i.setTomatoBasilTortillaQty(i.TomatoBasilTortillaQty + 1);
                        if (b.WheatTortilla) i.setWheatTortillaQty(i.WheatTortillaQty + 1);
                        if (b.FlourTortilla) i.setFlourTortillaQty(i.FlourTortillaQty + 1);

                        if (b.WhiteRice) i.setWhiteRiceQty(i.WhiteRiceQty + 1);
                        if (b.BrownRice) i.setBrownRiceQty(i.BrownRiceQty + 1);

                        if (b.BlackBeans) i.setBlackBeansQty(i.BlackBeansQty + 1);
                        if (b.PintoBeans) i.setPintoBeansQty(i.PintoBeansQty + 1);

                        if (b.SalsaPico) i.setSalsaPicoQty(i.SalsaPicoQty + 1);
                        if (b.SalsaSpecial) i.setSalsaSpecialQty(i.SalsaSpecialQty + 1);
                        if (b.SalsaVerde) i.setSalsaVerdeQty(i.SalsaVerdeQty + 1);

                        if (b.Guacamole) i.setGuacamoleQty(i.GuacamoleQty + 1);

                        if (b.Cucumber) i.setCucumberQty(i.CucumberQty + 1);
                        if (b.Jalapenos) i.setJalapenosQty(i.JalapenosQty + 1);
                        if (b.Lettuce) i.setLettuceQty(i.LettuceQty + 1);
                        if (b.Onion) i.setOnionQty(i.OnionQty + 1);
                        if (b.Tomatoes) i.setTomatoesQty(i.TomatoesQty + 1);
                    }

                    // ensure the inventory gets updated
                    if (inventorySvc.storeInventory(i))
                    {
                        result = true;
                    }
                }
            }
            catch (Exception e)
            {
                dLog.Debug("Exception in returnToInventory: " + e.Message + "\n" + e.StackTrace);
                result = false;
            }

            dLog.Debug("returnToInventory result: " + result);
            return result;
        }