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);
            }
        }
        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);
            }
        }
        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);
            }
        }
        public void testNotEqualsInventory()
        {
            try {
                Inventory i = new Inventory(1, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50);
                Inventory j = new Inventory(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

                Assert.False(i.Equals(j));
            }
            catch(Exception e) {
                Console.WriteLine("Exception in testNotEqualsInventory: " + e.Message + "\n" + e.StackTrace);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }
示例#5
0
        /// <summary>
        /// 
        /// </summary>
        public OrderUI(Inventory _i)
        {
            try
            {
                //Spring.NET
                XmlApplicationContext ctx = new XmlApplicationContext("config/spring.cfg.xml");
                iManager = (InventoryManager)ctx.GetObject("InventoryManager");
                oManager = (OrderManager)ctx.GetObject("OrderManager");

                newOrder = new Order();
                curInventory = _i;
                bDialog = new BurritoDialog(curInventory);
            }
            catch (Exception e)
            {
                dLog.Debug("Exception | Unable to initialize business layer components: " + e.Message + "\n" + e.StackTrace);
            }

            InitializeComponent();

            // Initialize the DataGridView.
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.AutoSize = true;

            // Initialize columns
            DataGridViewColumn column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "#";
            column.Name = "#";
            dataGridView1.Columns.Add(column);

            column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "Type";
            column.Name = "Type";
            dataGridView1.Columns.Add(column);

            column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "Price";
            column.Name = "Price";
            dataGridView1.Columns.Add(column);
            dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dataGridView1.ReadOnly = true;

            this.AutoSize = true;
        }
        public void testCreateInventory()
        {
            try
            {
                dLog.Info("Start testCreateInventory");
                i = new Inventory(rand.Next(), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250));

                Assert.True(iManager.createInventory(i));

                Assert.True(iManager.deleteInventory(i));

                dLog.Info("Finish testCreateInventory");
            }
            catch (Exception e)
            {
                dLog.Error("Exception in testCreateInventory: " + e.Message);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }
示例#7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="_i"></param>
        public void clearState(Inventory _i)
        {
            try
            {
                curInventory = _i;
                this.DialogResult = DialogResult.Cancel;
                newBurrito = new Burrito();

                //reset UI
                beefChk.Checked = false;
                ChickenChk.Checked = false;
                hummusChk.Checked = false;
                flourTorillaChk.Checked = false;
                herbGarlicChk.Checked = false;
                wheatChk.Checked = false;
                chiliChk.Checked = false;
                jalapenoCheddarChk.Checked = false;
                tomatoBasilChk.Checked = false;
                whiteRiceChk.Checked = false;
                brownRiceChk.Checked = false;
                blackBeansChk.Checked = false;
                pintoBeansChk.Checked = false;
                picoSalsaChk.Checked = false;
                salsaSpecialChk.Checked = false;
                salsaVerdeChk.Checked = false;
                guacamoleChk.Checked = false;
                lettuceChk.Checked = false;
                cucumbersChk.Checked = false;
                jalapenosChk.Checked = false;
                onionsChk.Checked = false;
                tomatoesChk.Checked = false;

                priceLbl.Text = "Total Price: $0.00";

                //initialize options based on inventory
                initAvailableOptions();
            }
            catch (Exception e)
            {
                dLog.Error("Exception in updateBurritoCost: " + e.Message);
            }
        }
示例#8
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="_i"></param>
        public InventoryUI(Inventory _i)
        {
            try
            {
                //Spring.NET
                XmlApplicationContext ctx = new XmlApplicationContext("config/spring.cfg.xml");
                iManager = (InventoryManager)ctx.GetObject("InventoryManager");

                rand = new Random();
                curInventory = _i;
            }
            catch (Exception e)
            {
                dLog.Debug("Exception | Unable to initialize Inventory UI: " + e.Message + "\n" + e.StackTrace);
            }

            InitializeComponent();

            setDefaultValues();
        }
示例#9
0
        /// <summary>
        /// 
        /// </summary>
        public BurritoDialog(Inventory _i)
        {
            try
            {
                //Spring.NET
                XmlApplicationContext ctx = new XmlApplicationContext("config/spring.cfg.xml");
                bManager = (BurritoManager)ctx.GetObject("BurritoManager");

                rand = new Random();
                newBurrito = new Burrito();
                curInventory = _i;

                initAvailableOptions();
            }
            catch (Exception e)
            {
                dLog.Debug("Exception | Unable to initialize business layer components: " + e.Message + "\n" + e.StackTrace);
            }

            InitializeComponent();
        }
示例#10
0
        /// <summary>
        /// 
        /// </summary>
        public MainUI()
        {
            try
            {
                //Spring.NET
                XmlApplicationContext ctx = new XmlApplicationContext("config/spring.cfg.xml");
                iManager = (InventoryManager)ctx.GetObject("InventoryManager");

                rand = new Random();
                i = new Inventory(rand.Next(), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250));
                iManager.createInventory(i);
            }
            catch (Exception e)
            {
                dLog.Debug("Exception | Unable to create Inventory: " + e.Message + "\n" + e.StackTrace);
            }

            InitializeComponent();

            this.IsMdiContainer = true;
        }
        /// <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;
        }
        public void testRemoveFromInventoryBurrito()
        {
            try
            {
                dLog.Info("Start testRemoveFromInventoryBurrito");
                i = new Inventory(rand.Next(), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250));
                b = new Burrito(rand.Next(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), new Decimal(rand.NextDouble()));

                Assert.True(iManager.createInventory(i));

                Assert.True(iManager.removeFromInventory(i, b));

                Assert.True(iManager.deleteInventory(i));

                dLog.Info("Finish testRemoveFromInventoryBurrito");
            }
            catch (Exception e)
            {
                dLog.Error("Exception in testRemoveFromInventoryBurrito: " + e.Message);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }
        /// <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;
        }
        public void testUpdateInventory()
        {
            try
            {
                dLog.Info("Start testUpdateInventory");
                i = new Inventory(rand.Next(), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250));

                Assert.True(iManager.createInventory(i));

                i.setBeefQty(i.BeefQty - 5);
                i.setChickenQty(i.ChickenQty + 23);
                i.setHerbGarlicTortillaQty(i.HerbGarlicTortillaQty - 3);

                Assert.True(iManager.updateInventory(i));

                Assert.True(iManager.deleteInventory(i));

                dLog.Info("Finish testUpdateInventory");
            }
            catch (Exception e)
            {
                dLog.Error("Exception in testUpdateInventory: " + e.Message);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }
        /// <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;
        }
        /// <summary>
        /// This method retrieves a inventory.
        /// </summary>
        /// <param name="id">Unique ID of inventory to retrieve</param>
        /// <returns>inventory object</returns>
        public Inventory getInventory(Int32 id)
        {
            dLog.Info("Entering method getInventory | ID: " + id);
            Inventory i = new Inventory();
            ISession session = null;

            try {
                using (session = getSession()) {
                    using (ITransaction transaction = session.BeginTransaction())
                    {
                        IQuery query = session.CreateQuery(@"FROM Inventory WHERE id = :id");
                        query.SetParameter("id", id);

                        i = query.List<Inventory>()[0];
                    }

                }
            }
            catch (Exception e2)
            {
                dLog.Error("Exception in getInventory: " + e2.Message + "\n" + e2.StackTrace);
                i = new Inventory();
            }
            finally
            {
                //ensure that session is close regardless of the errors in try/catch
                if (session != null && session.IsOpen)
                    session.Close();
            }

            return i;
        }
        /// <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);
            Boolean result = false;
            ISession session = null;

            try
            {
                using (session = getSession())
                {
                    using (ITransaction transaction = session.BeginTransaction())
                    {
                        session.Save(i);
                        transaction.Commit();

                        if (transaction.WasCommitted)
                            result = true;
                    }
                }
            }
            catch (Exception e2)
            {
                dLog.Error("Exception in storeInventory: " + e2.Message);
            }
            finally
            {
                //ensure that session is close regardless of the errors in try/catch
                if (session != null && session.IsOpen)
                    session.Close();
            }

            return result;
        }
        /// <summary>
        /// This method retrieves a inventory.
        /// </summary>
        /// <param name="id">Unique ID of inventory to retrieve</param>
        /// <returns>inventory object</returns>
        public Inventory getInventory(Int32 id)
        {
            dLog.Info("Entering method getInventory | ID: " + id);
            Inventory i = new Inventory();
            SqlDataReader rs = null;
            SqlConnection conn = null;
            SqlCommand stmt = null;

            try
            {
                String sqlStr = "SELECT BeefQty, BlackBeansQty, BrownRiceQty, ChickenQty, ChiliTortillaQty, CucumberQty, FlourTortillaQty, GuacamoleQty, HerbGarlicTortillaQty, HummusQty, ";
                sqlStr += "JalapenoCheddarTortillaQty, JalapenosQty, LettuceQty, OnionQty, PintoBeansQty, SalsaPicoQty, SalsaSpecialQty, SalsaVerdeQty, ";
                sqlStr += "TomatoBasilTortillaQty, TomatoesQty, WheatTortillaQty, WhiteRiceQty FROM Inventory WHERE id = @id";

                conn = new SqlConnection(connString);
                conn.Open();
                stmt = new SqlCommand(sqlStr, conn);
                stmt.Parameters.Add(new SqlParameter("@id", id));
                rs = stmt.ExecuteReader();

                while (rs.Read())
                {
                    dLog.Info("Got the " + rs.FieldCount + " fields of the record");
                    i.id = id;

                    #region Read Fields
                    if (!rs.IsDBNull(0))
                        i.BeefQty = rs.GetInt32(0);
                    if (!rs.IsDBNull(1))
                        i.BlackBeansQty = rs.GetInt32(1);
                    if (!rs.IsDBNull(2))
                        i.BrownRiceQty = rs.GetInt32(2);
                    if (!rs.IsDBNull(3))
                        i.ChickenQty = rs.GetInt32(3);
                    if (!rs.IsDBNull(4))
                        i.ChiliTortillaQty = rs.GetInt32(4);
                    if (!rs.IsDBNull(5))
                        i.CucumberQty = rs.GetInt32(5);
                    if (!rs.IsDBNull(6))
                        i.FlourTortillaQty = rs.GetInt32(6);
                    if (!rs.IsDBNull(7))
                        i.GuacamoleQty = rs.GetInt32(7);
                    if (!rs.IsDBNull(8))
                        i.HerbGarlicTortillaQty = rs.GetInt32(8);
                    if (!rs.IsDBNull(9))
                        i.HummusQty = rs.GetInt32(9);
                    if (!rs.IsDBNull(10))
                        i.JalapenoCheddarTortillaQty = rs.GetInt32(10);
                    if (!rs.IsDBNull(11))
                        i.JalapenosQty = rs.GetInt32(11);
                    if (!rs.IsDBNull(12))
                        i.LettuceQty = rs.GetInt32(12);
                    if (!rs.IsDBNull(13))
                        i.OnionQty = rs.GetInt32(13);
                    if (!rs.IsDBNull(14))
                        i.PintoBeansQty = rs.GetInt32(14);
                    if (!rs.IsDBNull(15))
                        i.SalsaPicoQty = rs.GetInt32(15);
                    if (!rs.IsDBNull(16))
                        i.SalsaSpecialQty = rs.GetInt32(16);
                    if (!rs.IsDBNull(17))
                        i.SalsaVerdeQty = rs.GetInt32(17);
                    if (!rs.IsDBNull(18))
                        i.TomatoBasilTortillaQty = rs.GetInt32(18);
                    if (!rs.IsDBNull(19))
                        i.TomatoesQty = rs.GetInt32(19);
                    if (!rs.IsDBNull(20))
                        i.WheatTortillaQty = rs.GetInt32(20);
                    if (!rs.IsDBNull(21))
                        i.WhiteRiceQty = rs.GetInt32(21);
                    #endregion
                }
            }
            catch (SqlException e1)
            {
                dLog.Error("SqlException in getInventory: " + e1.Message + "\n" + e1.StackTrace);
                i = new Inventory();
            }
            catch (Exception e2)
            {
                dLog.Error("Exception in getInventory: " + e2.Message + "\n" + e2.StackTrace);
                i = new Inventory();
            }
            finally
            {
                if (rs != null && !rs.IsClosed)
                    rs.Close();
                if (conn != null && conn.State == System.Data.ConnectionState.Open)
                    conn.Close();
            }

            return i;
        }
        /// <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);
            Boolean result = false;
            SqlConnection conn = null;
            SqlCommand stmt = null;

            try
            {
                String sqlStr = "SELECT COUNT(1) FROM Inventory WHERE id = @id";

                conn = new SqlConnection(connString);
                conn.Open();
                stmt = new SqlCommand(sqlStr, conn);
                stmt.Parameters.Add(new SqlParameter("@id", i.id));

                if (Int32.Parse(stmt.ExecuteScalar().ToString()) > 0)
                {
                    //if first is a valid row, then we need to do an update
                    dLog.Info("Updating inventory in database");

                    sqlStr = "UPDATE Inventory SET BeefQty=@Beef, BlackBeansQty=@BlackBeans, BrownRiceQty=@BrownRice, ChickenQty=@Chicken, ChiliTortillaQty=@ChiliTortilla, ";
                    sqlStr += "CucumberQty=@Cucumber, FlourTortillaQty=@FlourTortilla, GuacamoleQty=@Guacamole, HerbGarlicTortillaQty=@HerbGarlicTortilla, HummusQty=@Hummus, ";
                    sqlStr += "JalapenoCheddarTortillaQty=@JalapenoCheddarTortilla, JalapenosQty=@Jalapenos, LettuceQty=@Lettuce, OnionQty=@Onion, PintoBeansQty=@PintoBeans, ";
                    sqlStr += "SalsaPicoQty=@SalsaPico, SalsaSpecialQty=@SalsaSpecial, SalsaVerdeQty=@SalsaVerde, TomatoBasilTortillaQty=@TomatoBasilTortilla, ";
                    sqlStr += "TomatoesQty=@Tomatoes, WheatTortillaQty=@WheatTortilla, WhiteRiceQty=@WhiteRice WHERE id=@id";
                }
                else
                {
                    //if first is null, then we need to do an insert
                    dLog.Info("Inserting inventory into database");

                    sqlStr = "INSERT INTO Inventory (BeefQty, BlackBeansQty, BrownRiceQty, ChickenQty, ChiliTortillaQty, CucumberQty,";
                    sqlStr += "FlourTortillaQty, GuacamoleQty, HerbGarlicTortillaQty, HummusQty, JalapenoCheddarTortillaQty, JalapenosQty,";
                    sqlStr += "LettuceQty, OnionQty, PintoBeansQty, SalsaPicoQty, SalsaSpecialQty, SalsaVerdeQty, TomatoBasilTortillaQty,";
                    sqlStr += "TomatoesQty, WheatTortillaQty, WhiteRiceQty, id) VALUES (@Beef, @BlackBeans, @BrownRice, @Chicken, @ChiliTortilla, @Cucumber,";
                    sqlStr += "@FlourTortilla, @Guacamole, @HerbGarlicTortilla, @Hummus, @JalapenoCheddarTortilla, @Jalapenos,";
                    sqlStr += "@Lettuce, @Onion, @PintoBeans, @SalsaPico, @SalsaSpecial, @SalsaVerde, @TomatoBasilTortilla,";
                    sqlStr += "@Tomatoes, @WheatTortilla, @WhiteRice, @id)";
                }

                dLog.Info("SQL Statement: " + sqlStr);
                stmt = new SqlCommand(sqlStr, conn);

                #region Add SQL Parameters
                stmt.Parameters.Add(new SqlParameter("@id", i.id));
                stmt.Parameters.Add(new SqlParameter("@Beef", i.BeefQty));
                stmt.Parameters.Add(new SqlParameter("@BlackBeans", i.BlackBeansQty));
                stmt.Parameters.Add(new SqlParameter("@BrownRice", i.BrownRiceQty));
                stmt.Parameters.Add(new SqlParameter("@Chicken", i.ChickenQty));
                stmt.Parameters.Add(new SqlParameter("@ChiliTortilla", i.ChiliTortillaQty));
                stmt.Parameters.Add(new SqlParameter("@Cucumber", i.CucumberQty));
                stmt.Parameters.Add(new SqlParameter("@FlourTortilla", i.FlourTortillaQty));
                stmt.Parameters.Add(new SqlParameter("@Guacamole", i.GuacamoleQty));
                stmt.Parameters.Add(new SqlParameter("@HerbGarlicTortilla", i.HerbGarlicTortillaQty));
                stmt.Parameters.Add(new SqlParameter("@Hummus", i.HummusQty));
                stmt.Parameters.Add(new SqlParameter("@JalapenoCheddarTortilla", i.JalapenoCheddarTortillaQty));
                stmt.Parameters.Add(new SqlParameter("@Jalapenos", i.JalapenosQty));
                stmt.Parameters.Add(new SqlParameter("@Lettuce", i.LettuceQty));
                stmt.Parameters.Add(new SqlParameter("@Onion", i.OnionQty));
                stmt.Parameters.Add(new SqlParameter("@PintoBeans", i.PintoBeansQty));
                stmt.Parameters.Add(new SqlParameter("@SalsaPico", i.SalsaPicoQty));
                stmt.Parameters.Add(new SqlParameter("@SalsaSpecial", i.SalsaSpecialQty));
                stmt.Parameters.Add(new SqlParameter("@SalsaVerde", i.SalsaVerdeQty));
                stmt.Parameters.Add(new SqlParameter("@TomatoBasilTortilla", i.TomatoBasilTortillaQty));
                stmt.Parameters.Add(new SqlParameter("@Tomatoes", i.TomatoesQty));
                stmt.Parameters.Add(new SqlParameter("@WheatTortilla", i.WheatTortillaQty));
                stmt.Parameters.Add(new SqlParameter("@WhiteRice", i.WhiteRiceQty));
                #endregion

                if (stmt.ExecuteNonQuery() > 0)
                    result = true;
            }
            catch (SqlException e1)
            {
                dLog.Error("SqlException in storeInventory: " + e1.Message);
            }
            catch (Exception e2)
            {
                dLog.Error("Exception in storeInventory: " + e2.Message);
            }
            finally
            {
                if (conn.State == System.Data.ConnectionState.Open)
                    conn.Close();
            }

            return result;
        }
        public void testRemoveFromInventoryOrder()
        {
            try
            {
                dLog.Info("Start testRemoveFromInventoryOrder");
                i = new Inventory(rand.Next(), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250));
                o = new Order(rand.Next(), new List<Burrito>(), new DateTime(), false, false, new Decimal(0));

                Assert.True(iManager.createInventory(i));

                //randomly create burritos to remove from inventory
                for(int n=0; n< rand.Next(2,7); n++)
                    oManager.addBurritoToOrder(o, new Burrito(rand.Next(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), new Decimal(rand.NextDouble())));

                Assert.True(iManager.removeFromInventory(i, o));

                Assert.True(iManager.deleteInventory(i));

                dLog.Info("Finish testRemoveFromInventoryOrder");
            }
            catch (Exception e)
            {
                dLog.Error("Exception in testRemoveFromInventoryOrder: " + e.Message);
                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);
            Boolean result = false;

            try
            {
                MongoServer server = MongoServer.Create();
                MongoDatabase db = server.GetDatabase("neatoBurrito");
                //MongoCredentials credentials = new MongoCredentials("username", "password");
                //MongoDatabase salaries = server.GetDatabase("salaries", credentials);

                using (server.RequestStart(db))
                {
                    MongoCollection<BsonDocument> coll = db.GetCollection("inventory");
                    var query = new QueryDocument("id", i.id);

                    dLog.Debug("Finding if inventory exists");
                    BsonDocument myDoc = coll.FindOne(query);

                    query.Add("beefQty", i.BeefQty);
                    query.Add("blackBeansQty", i.BlackBeansQty);
                    query.Add("brownRiceQty", i.BrownRiceQty);
                    query.Add("chickenQty", i.ChickenQty);
                    query.Add("chiliTortillaQty", i.ChiliTortillaQty);
                    query.Add("cucumberQty", i.CucumberQty);
                    query.Add("flourTortillaQty", i.FlourTortillaQty);
                    query.Add("guacamoleQty", i.GuacamoleQty);
                    query.Add("herbGarlicTortillaQty", i.HerbGarlicTortillaQty);
                    query.Add("hummusQty", i.HummusQty);
                    query.Add("jalapenoCheddarTortillaQty", i.JalapenoCheddarTortillaQty);
                    query.Add("jalapenosQty", i.JalapenosQty);
                    query.Add("lettuceQty", i.LettuceQty);
                    query.Add("onionQty", i.OnionQty);
                    query.Add("pintoBeansQty", i.PintoBeansQty);
                    query.Add("salsaPicoQty", i.SalsaPicoQty);
                    query.Add("salsaSpecialQty", i.SalsaSpecialQty);
                    query.Add("salsaVerdeQty", i.SalsaVerdeQty);
                    query.Add("tomatoBasilTortillaQty", i.TomatoBasilTortillaQty);
                    query.Add("tomatoesQty", i.TomatoesQty);
                    query.Add("wheatTortillaQty", i.WheatTortillaQty);
                    query.Add("whiteRiceQty", i.WhiteRiceQty);

                    //ensure we were passed a valid object before attempting to write
                    if (myDoc == null)
                    {
                        dLog.Debug("Inserting inventory");
                        coll.Insert(query);

                        result = true;
                    }
                    else
                    {
                        var update = new UpdateDocument();
                        update.Add(query.ToBsonDocument());
                        dLog.Debug("Updating inventory");
                        dLog.Debug("myDoc: " + myDoc.ToString());
                        dLog.Debug("update Query: " + update.ToString());

                        SafeModeResult wr = coll.Update(new QueryDocument("id", i.id), update, SafeMode.True);

                        dLog.Debug("SafeModeResult: " + wr.Ok);
                        if (wr.LastErrorMessage == null && wr.Ok)
                        {
                            result = true;
                        }
                        else
                        {
                            dLog.Debug("SafeModeResult: " + wr.LastErrorMessage);
                        }
                    }
                }
            }
            catch (Exception e2)
            {
                dLog.Error("Exception in storeInventory: " + e2.Message);
            }
            finally
            {
                //using statement above already calls RequestDone()
            }

            return result;
        }
        protected void SetUp()
        {
            XmlConfigurator.Configure(new FileInfo("config/log4net.properties"));
            dLog.Info("Beginning InventoryManagerTestCase Setup");
            rand = new Random();

            try {
                //iManager = new InventoryManager();
                //oManager = new OrderManager();

                //Spring.NET
                XmlApplicationContext ctx = new XmlApplicationContext("config/spring.cfg.xml");
                iManager = (InventoryManager)ctx.GetObject("InventoryManager");
                oManager = (OrderManager)ctx.GetObject("OrderManager");

                i = new Inventory(rand.Next(), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250), rand.Next(10, 250));
                o = new Order(rand.Next(), new List<Burrito>(), new DateTime(), false, false, new Decimal(0));
                b = new Burrito(rand.Next(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), nextBool(), new Decimal(rand.NextDouble()));
            }
            catch (Exception e)
            {
                dLog.Error("Unable to initialize service/domain objects: " + e.Message + "\n" + e.StackTrace);
            }
            dLog.Info("Finishing InventoryManagerTestCase Setup");
        }
        /// <summary>
        /// This method retrieves a inventory.
        /// </summary>
        /// <param name="id">Unique ID of inventory to retrieve</param>
        /// <returns>inventory object</returns>
        public Inventory getInventory(Int32 id)
        {
            dLog.Info("Entering method getInventory | ID: " + id);
            Inventory i = new Inventory();

            try
            {
                MongoServer server = MongoServer.Create();
                MongoDatabase db = server.GetDatabase("neatoBurrito");
                //MongoCredentials credentials = new MongoCredentials("username", "password");
                //MongoDatabase salaries = server.GetDatabase("salaries", credentials);

                using (server.RequestStart(db))
                {
                    MongoCollection<BsonDocument> coll = db.GetCollection("inventory");
                    var query = new QueryDocument("id", id);

                    BsonDocument myDoc = coll.FindOne(query);

                    //ensure we were passed a valid object before attempting to read
                    if (myDoc != null)
                    {
                        dLog.Debug("myDoc: " + myDoc.ToString());

                        #region Read Fields
                        i.id = id;
                        i.BeefQty = myDoc["beefQty"].AsInt32;
                        i.BlackBeansQty = myDoc["blackBeansQty"].AsInt32;
                        i.BrownRiceQty = myDoc["brownRiceQty"].AsInt32;
                        i.ChickenQty = myDoc["chickenQty"].AsInt32;
                        i.ChiliTortillaQty = myDoc["chiliTortillaQty"].AsInt32;
                        i.CucumberQty = myDoc["cucumberQty"].AsInt32;
                        i.FlourTortillaQty = myDoc["flourTortillaQty"].AsInt32;
                        i.GuacamoleQty = myDoc["guacamoleQty"].AsInt32;
                        i.HerbGarlicTortillaQty = myDoc["herbGarlicTortillaQty"].AsInt32;
                        i.HummusQty = myDoc["hummusQty"].AsInt32;
                        i.JalapenoCheddarTortillaQty = myDoc["jalapenoCheddarTortillaQty"].AsInt32;
                        i.JalapenosQty = myDoc["jalapenosQty"].AsInt32;
                        i.LettuceQty = myDoc["lettuceQty"].AsInt32;
                        i.OnionQty = myDoc["onionQty"].AsInt32;
                        i.PintoBeansQty = myDoc["pintoBeansQty"].AsInt32;
                        i.SalsaPicoQty = myDoc["salsaPicoQty"].AsInt32;
                        i.SalsaSpecialQty = myDoc["salsaSpecialQty"].AsInt32;
                        i.SalsaVerdeQty = myDoc["salsaVerdeQty"].AsInt32;
                        i.TomatoBasilTortillaQty = myDoc["tomatoBasilTortillaQty"].AsInt32;
                        i.TomatoesQty = myDoc["tomatoesQty"].AsInt32;
                        i.WheatTortillaQty = myDoc["wheatTortillaQty"].AsInt32;
                        i.WhiteRiceQty = myDoc["whiteRiceQty"].AsInt32;
                        #endregion
                    }
                    dLog.Debug("Finishing setting inventory");
                }
            }
            catch (Exception e2)
            {
                dLog.Error("Exception in getInventory: " + e2.Message + "\n" + e2.StackTrace);
                i = new Inventory();
            }
            finally
            {
                //using statement above already calls RequestDone()
            }

            return i;
        }
        /// <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;
        }
 protected void SetUp()
 {
     factory = Factory.getInstance();
     i = new Inventory(1, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50);
 }