public void testStoreInventory()
        {
            try {
                //week 3
                //IInventorySvc ics = factory.getInventorySvc();

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

                // First let's store the Inventory
                Assert.True(ics.storeInventory(i));

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

                // Update Inventory
                i.BlackBeansQty = 3;
                i.CucumberQty = 17;
                i.SalsaVerdeQty = 12;
                Assert.True(ics.storeInventory(i));

                // Finally, let's cleanup the file that was created
                Assert.True(ics.deleteInventory(i.id));
            }
            catch(Exception e) {
                Console.WriteLine("Exception in testStoreInventory: " + e.Message + "\n" + e.StackTrace);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }
Exemplo n.º 2
0
        public void testInvalidInventory()
        {
            try {
                Inventory i = new Inventory();

                Assert.False(i.validate());
            }
            catch(Exception e) {
                Console.WriteLine("Exception in testInvalidInventory: " + e.Message + "\n" + e.StackTrace);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public Boolean createInventory(Inventory i)
        {
            dLog.Debug("In createInventory");
            Boolean result = false;

            try
            {
                dLog.Debug("Validating inventory object");
                if (i.validate())
                {
                    if (inventorySvc.storeInventory(i))
                        result = true;
                }
            }
            catch (Exception e)
            {
                dLog.Debug("Exception in createInventory: " + e.Message + "\n" + e.StackTrace);
                result = false;
            }

            dLog.Debug("createInventory result: " + result);
            return result;
        }
Exemplo n.º 4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public Boolean deleteInventory(Inventory i)
        {
            dLog.Debug("In deleteInventory");
            Boolean result = false;

            try
            {
                if (i.validate())
                {
                    if (inventorySvc.deleteInventory(i.id))
                        result = true;
                }
            }
            catch (Exception e)
            {
                dLog.Debug("Exception in deleteInventory: " + e.Message + "\n" + e.StackTrace);
                result = false;
            }

            dLog.Debug("deleteInventory result: " + result);
            return result;
        }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
0
        public void testValidateInventory()
        {
            try {
                Inventory i = new Inventory();
                i.id = 1;
                i.setBeefQty(50);
                i.setBlackBeansQty(50);
                i.setBrownRiceQty(50);
                i.setChickenQty(50);
                i.setChiliTortillaQty(50);
                i.setCucumberQty(50);
                i.setFlourTortillaQty(50);
                i.setGuacamoleQty(20);
                i.setHerbGarlicTortillaQty(50);
                i.setHummusQty(50);
                i.setJalapenoCheddarTortillaQty(50);
                i.setLettuceQty(50);
                i.setOnionQty(50);
                i.setPintoBeansQty(50);
                i.setSalsaPicoQty(50);
                i.setSalsaSpecialQty(50);
                i.setSalsaVerdeQty(50);
                i.setTomatoBasilTortillaQty(50);
                i.setTomatoesQty(50);
                i.setWheatTortillaQty(50);
                i.setWhiteRiceQty(50);
                i.setJalapenosQty(50);

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

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

            return result;
        }