public void testBurritoSvc()
        {
            try {
                //week 3
                //IBurritoSvc ics = factory.getBurritoSvc();

                //week 4
                dLog.Debug("Going to get the service implementation");
                IBurritoSvc ics = (IBurritoSvc) factory.getService("IBurritoSvc");

                dLog.Debug("Going to create burrito");
                // First let's store the Burrito
                Assert.True(ics.storeBurrito(b));

                dLog.Debug("Going to read burrito");
                // Then let's read it back in
                b = ics.getBurrito(b.id);
                Assert.True(b.validate());

                // Update burrito
                dLog.Debug("Going to update burrito");
                b.Beef = false;
                b.Hummus = true;
                Assert.True(ics.storeBurrito(b));

                dLog.Debug("Going to delete burrito");
                // Finally, let's cleanup the file that was created
                Assert.True(ics.deleteBurrito(b.id));
            }
            catch(Exception e) {
                Console.WriteLine("Exception in testBurritoSvc: " + e.Message + "\n" + e.StackTrace);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }
Пример #2
0
        public void testInvalidBurrito()
        {
            try {
                Burrito b = new Burrito();
                b.id = -1;

                Assert.False(b.validate());
            }
            catch(Exception e) {
                Console.WriteLine("Exception in testInvalidBurrito: " + e.Message + "\n" + e.StackTrace);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }
Пример #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="o"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public Boolean addBurritoToOrder(Order o, Burrito b)
        {
            dLog.Debug("In addBurritoToOrder");
            Boolean result = false;

            try
            {
                if (b.validate())
                {
                    o.burritos.Add(b);

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

            dLog.Debug("addBurritoToOrder result: " + result);
            return result;
        }
        /// <summary>
        /// This method stores a burrito.
        /// </summary>
        /// <param name="b">The burrito object to store</param>
        /// <returns>Success/Failure</returns>
        public Boolean storeBurrito(Burrito b)
        {
            dLog.Info("Entering method storeBurrito | ID: "+b.id);
            Stream output = null;
            Boolean result = false;

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

            return result;
        }
Пример #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="o"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public Boolean updateBurritoInOrder(Order o, Burrito b)
        {
            dLog.Debug("In updateBurritoInOrder");
            Boolean result = false;

            try
            {
                if (b.validate())
                {
                    var idx = 0;
                    foreach (Burrito b1 in o.burritos)
                    {
                        if (b1.id == b.id)
                        {
                            o.burritos[idx] = b;
                            result = true;
                            break;
                        }

                        idx++;
                    }

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

            dLog.Debug("updateBurritoInOrder result: " + result);
            return result;
        }
Пример #6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="i"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public Boolean returnToInventory(Inventory i, Burrito b)
        {
            dLog.Debug("In returnToInventory");
            Boolean result = false;

            try
            {
                if (i.validate() && b.validate())
                {
                    // add burrito ingredients to inventory
                    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;
        }
Пример #7
0
        public void testValidBurrito()
        {
            try {
                Burrito b = new Burrito();
                b.id = 1;
                b.Beef = true;
                b.BlackBeans = true;
                b.BrownRice = true;
                b.Chicken = false;
                b.ChiliTortilla = false;
                b.Cucumber = true;
                b.FlourTortilla = false;
                b.Guacamole = true;
                b.HerbGarlicTortilla = true;
                b.Hummus = false;
                b.JalapenoCheddarTortilla = false;
                b.Jalapenos = true;
                b.Lettuce = true;
                b.Onion = false;
                b.PintoBeans = false;
                b.SalsaPico = true;
                b.SalsaSpecial = false;
                b.SalsaVerde = false;
                b.TomatoBasilTortilla = false;
                b.Tomatoes = false;
                b.WheatTortilla = false;
                b.WhiteRice = false;
                b.Price = Decimal.Parse("3.00");

                Assert.True(b.validate());
            }
            catch(Exception e) {
                Console.WriteLine("Exception in testValidBurrito: " + e.Message);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }
Пример #8
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="b"></param>
        /// <returns></returns>
        public Decimal calculatePrice(Burrito b)
        {
            dLog.Debug("In calculatePrice");
            Decimal result = new Decimal(-1);

            try
            {
                //check for valid burrito
                if (b.validate())
                {
                    result = new Decimal(0);

                    // first determine base type of Beef, Chicken, or Hummus by order of cost then determine extras
                    if (b.Beef)
                    {
                        result = result + Prices.getItemPrice("BeefBurrito");

                        //add extra main
                        if (b.Chicken)
                            result = result + Prices.getItemPrice("ExtraMeat");
                        if (b.Hummus)
                            result = result + Prices.getItemPrice("ExtraBeans");
                    }
                    else if (b.Chicken)
                    {
                        result = result + Prices.getItemPrice("BeefBurrito");

                        if (b.Hummus)
                            result = result + Prices.getItemPrice("ExtraBeans");
                    }
                    else if (b.Hummus)
                    {
                        result = result + Prices.getItemPrice("HummusBurrito");
                    }

                    // calculate remaining extras
                    if (b.ChiliTortilla || b.HerbGarlicTortilla || b.JalapenoCheddarTortilla || b.TomatoBasilTortilla || b.WheatTortilla)
                        result = result + Prices.getItemPrice("FlavoredTortilla");

                    if (b.WhiteRice && b.BrownRice)
                        result = result + Prices.getItemPrice("ExtraRice");

                    if (b.BlackBeans && b.PintoBeans)
                        result = result + Prices.getItemPrice("ExtraBeans");

                    if (b.SalsaPico && b.SalsaSpecial && b.SalsaVerde)
                        result = result + Prices.getItemPrice("ExtraSalsa");

                    if (b.Guacamole)
                        result = result + Prices.getItemPrice("Guacamole");
                }
            }
            catch (Exception e)
            {
                dLog.Debug("Exception in calculatePrice: " + e.Message + "\n" + e.StackTrace);
                result = new Decimal(-1);
            }

            dLog.Debug("calculatePrice result: " + result);
            return result;
        }
Пример #9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="b"></param>
        /// <returns></returns>
        public Boolean updateBurrito(Burrito b)
        {
            Boolean result = false;

            try
            {
                if (b.validate())
                {
                    if (burritoSvc.storeBurrito(b))
                    {
                        result = true;
                    }
                }
            }
            catch (Exception e)
            {
                dLog.Debug("Exception in updateBurrito: " + e.Message + "\n" + e.StackTrace);
                result = false;
            }

            return result;
        }
Пример #10
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="b"></param>
        /// <returns></returns>
        public Boolean createBurrito(Burrito b)
        {
            dLog.Debug("In createBurrito");
            Boolean result = false;

            try
            {
                dLog.Debug("Validating burrito object");
                if (b.validate())
                {
                    if (burritoSvc.storeBurrito(b))
                    {
                        result = true;
                    }
                }
            }
            catch (Exception e)
            {
                dLog.Debug("Exception in createBurrito: " + e.Message + "\n" + e.StackTrace);
                result = false;
            }

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