protected void SetUp()
 {
     factory = Factory.getInstance();
     o = new Order(1, new List<Burrito>(), DateTime.Now, false, false, Decimal.Parse("17.00"));
     b = 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("3.00"));
     o.burritos.Add(b);
 }
        public void testAddBurritoToOrder()
        {
            try
            {
                dLog.Info("Start testAddBurritoToOrder");
                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()));
                b.Price = bManager.calculatePrice(b);
                oManager.addBurritoToOrder(o, b);
                o.totalCost = oManager.calculateTotal(o);

                Assert.True(oManager.createOrder(o));

                Assert.True(oManager.addBurritoToOrder(o, b));

                Assert.True(oManager.deleteOrder(o));

                dLog.Info("Finish testAddBurritoToOrder");
            }
            catch (Exception e)
            {
                dLog.Error("Exception in testAddBurritoToOrder: " + e.Message);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }
        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);
            }
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        public void testNotEqualsOrder()
        {
            try {
                Order o = new Order(1,new List<Burrito>(),DateTime.Now, false,false,Decimal.Parse("17.00"));
                Order p= new Order();

                Assert.False(o.Equals(p));
            }
            catch(Exception e) {
                Console.WriteLine("Exception in testNotEqualsOrder: " + e.Message + "\n" + e.StackTrace);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }
Пример #6
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;
        }
Пример #7
0
        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);
            }
        }
        public void testCalculateTotal()
        {
            try
            {
                dLog.Info("Start testCalculateTotal");
                o = new Order(rand.Next(), new List<Burrito>(), new DateTime(), false, false, new Decimal(0));
                oManager.addBurritoToOrder(o, b);
                o.totalCost = oManager.calculateTotal(o);

                Assert.True(oManager.createOrder(o));

                dLog.Debug("Order ID: " + o.id);

                //randomly create some burritos to add to order
                for (int n = 0; n < rand.Next(2, 7); n++)
                {
                    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()));
                    b.Price = bManager.calculatePrice(b);
                    Assert.True(oManager.addBurritoToOrder(o, b));
                }

                o.totalCost = oManager.calculateTotal(o);
                dLog.Debug("Total cost of order: " + o.totalCost + " | Number of burritos: " + o.burritos.Count);
                if (o.totalCost == -1)
                    Assert.Fail("Invalid total calculated for order");

                Assert.True(oManager.submitOrder(o));

                Assert.True(oManager.cancelOrder(o));

                dLog.Info("Finish testCalculateTotal");
            }
            catch (Exception e)
            {
                dLog.Error("Exception in testCalculateTotal: " + e.Message);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }
Пример #9
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;
        }
Пример #10
0
        /// <summary>
        /// This method retrieves a order.
        /// </summary>
        /// <param name="id">Unique ID of order to retrieve</param>
        /// <returns>order object</returns>
        public Order getOrder(Int32 id)
        {
            dLog.Info("Entering method getOrder | ID: " + id);
            Order o = new Order();

            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("order");
                    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 Order Fields
                        o.id = id;
                        o.isComplete = myDoc["isComplete"].AsBoolean;
                        o.isSubmitted = myDoc["isSubmitted"].AsBoolean;
                        o.orderDate = myDoc["orderDate"].AsDateTime;
                        o.totalCost = Decimal.Parse(myDoc["totalCost"].AsString);
                        #endregion

                        //get burritos
                        dLog.Debug("Getting burritos");
                        coll = db.GetCollection("burrito");
                        query.Clear();
                        query.Add("orderID", id);
                        MongoCursor cur = coll.Find(query);

                        o.burritos = new List<Burrito>();

                        foreach (var doc in cur)
                        {
                            myDoc = (BsonDocument)doc;
                            Burrito b = new Burrito();

                            //cleaner but too many extra queries this way
                            //o.burritos.Add(burritoSvc.getBurrito(myDoc["id"].AsInt32));

                            #region Read burrito Fields
                            b.id = id;
                            b.Beef = myDoc["beef"].AsBoolean;
                            b.BlackBeans = myDoc["blackBeans"].AsBoolean;
                            b.BrownRice = myDoc["brownRice"].AsBoolean;
                            b.Chicken = myDoc["chicken"].AsBoolean;
                            b.ChiliTortilla = myDoc["chiliTortilla"].AsBoolean;
                            b.Cucumber = myDoc["cucumber"].AsBoolean;
                            b.FlourTortilla = myDoc["flourTortilla"].AsBoolean;
                            b.Guacamole = myDoc["guacamole"].AsBoolean;
                            b.HerbGarlicTortilla = myDoc["herbGarlicTortilla"].AsBoolean;
                            b.Hummus = myDoc["hummus"].AsBoolean;
                            b.JalapenoCheddarTortilla = myDoc["jalapenoCheddarTortilla"].AsBoolean;
                            b.Jalapenos = myDoc["jalapenos"].AsBoolean;
                            b.Lettuce = myDoc["lettuce"].AsBoolean;
                            b.Onion = myDoc["onion"].AsBoolean;
                            b.orderID = myDoc["orderID"].AsInt32;
                            b.PintoBeans = myDoc["pintoBeans"].AsBoolean;
                            b.Price = Decimal.Parse(myDoc["price"].AsString);
                            b.SalsaPico = myDoc["salsaPico"].AsBoolean;
                            b.SalsaSpecial = myDoc["salsaSpecial"].AsBoolean;
                            b.SalsaVerde = myDoc["salsaVerde"].AsBoolean;
                            b.TomatoBasilTortilla = myDoc["tomatoBasilTortilla"].AsBoolean;
                            b.Tomatoes = myDoc["tomatoes"].AsBoolean;
                            b.WheatTortilla = myDoc["wheatTortilla"].AsBoolean;
                            b.WhiteRice = myDoc["whiteRice"].AsBoolean;
                            #endregion

                            o.burritos.Add(b);
                        }
                    }
                    dLog.Debug("Finishing setting order");
                }
            }
            catch (Exception e2)
            {
                dLog.Error("Exception in getOrder: " + e2.Message + "\n" + e2.StackTrace);
                o = new Order();
            }
            finally
            {
                //using statement above already calls RequestDone()
            }

            return o;
        }
Пример #11
0
        /// <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;
        }
Пример #12
0
        /// <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;
        }
Пример #13
0
        /// <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);
            Boolean result = false;
            SqlConnection conn = null;
            SqlCommand stmt = null;

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

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

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

                    sqlStr = "UPDATE Orders SET isComplete=@isComplete, isSubmitted=@isSubmitted, orderDate=@orderDate, totalCost=@TotalCost WHERE id=@id";
                }
                else
                {
                    //if first is null, then we need to do an insert
                    dLog.Info("Inserting order into database");

                    sqlStr = "INSERT INTO Orders (id, isComplete, isSubmitted, orderDate, totalCost) ";
                    sqlStr += "VALUES (@id, @isComplete, @isSubmitted, @orderDate, @TotalCost)";
                }

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

                #region Add SQL Parameters
                stmt.Parameters.Add(new SqlParameter("@id", o.id));
                stmt.Parameters.Add(new SqlParameter("@isComplete", o.isComplete));
                stmt.Parameters.Add(new SqlParameter("@isSubmitted", o.isSubmitted));
                stmt.Parameters.Add(new SqlParameter("@orderDate", o.orderDate));
                stmt.Parameters.Add(new SqlParameter("@TotalCost", o.totalCost));
                #endregion

                if (stmt.ExecuteNonQuery() > 0)
                    result = true;

                dLog.Info("Trying to insert: " + o.burritos.Count + " burritos");
                foreach (Burrito b in o.burritos)
                {
                    dLog.Info("Validating burrito object");
                    if (b.validate())
                    {
                        sqlStr = "SELECT COUNT(1) FROM Burrito WHERE id = @id";

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

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

                            sqlStr = "UPDATE Burrito SET Beef=@Beef, BlackBeans=@BlackBeans, BrownRice=@BrownRice, Chicken=@Chicken, ChiliTortilla=@ChiliTortilla, ";
                            sqlStr += "Cucumber=@Cucumber, FlourTortilla=@FlourTortilla, Guacamole=@Guacamole, HerbGarlicTortilla=@HerbGarlicTortilla, Hummus=@Hummus, ";
                            sqlStr += "JalapenoCheddarTortilla=@JalapenoCheddarTortilla, Jalapenos=@Jalapenos, Lettuce=@Lettuce, Onion=@Onion, OrderID=@OrderID, PintoBeans=@PintoBeans, ";
                            sqlStr += "Price=@Price, SalsaPico=@SalsaPico, SalsaSpecial=@SalsaSpecial, SalsaVerde=@SalsaVerde, TomatoBasilTortilla=@TomatoBasilTortilla, ";
                            sqlStr += "Tomatoes=@Tomatoes, WheatTortilla=@WheatTortilla, WhiteRice=@WhiteRice WHERE id=@id";
                        }
                        else
                        {
                            //if first is null, then we need to do an insert
                            dLog.Info("Inserting burrito into database");

                            sqlStr = "INSERT INTO Burrito (Beef, BlackBeans, BrownRice, Chicken, ChiliTortilla, Cucumber,";
                            sqlStr += "FlourTortilla, Guacamole, HerbGarlicTortilla, Hummus, JalapenoCheddarTortilla, Jalapenos,";
                            sqlStr += "Lettuce, Onion, OrderID, PintoBeans, Price, SalsaPico, SalsaSpecial, SalsaVerde, TomatoBasilTortilla,";
                            sqlStr += "Tomatoes, WheatTortilla, WhiteRice, id) VALUES (@Beef, @BlackBeans, @BrownRice, @Chicken, @ChiliTortilla, @Cucumber,";
                            sqlStr += "@FlourTortilla, @Guacamole, @HerbGarlicTortilla, @Hummus, @JalapenoCheddarTortilla, @Jalapenos,";
                            sqlStr += "@Lettuce, @Onion, @OrderID, @PintoBeans, @Price, @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", b.id));
                        stmt.Parameters.Add(new SqlParameter("@Beef", b.Beef));
                        stmt.Parameters.Add(new SqlParameter("@BlackBeans", b.BlackBeans));
                        stmt.Parameters.Add(new SqlParameter("@BrownRice", b.BrownRice));
                        stmt.Parameters.Add(new SqlParameter("@Chicken", b.Chicken));
                        stmt.Parameters.Add(new SqlParameter("@ChiliTortilla", b.ChiliTortilla));
                        stmt.Parameters.Add(new SqlParameter("@Cucumber", b.Cucumber));
                        stmt.Parameters.Add(new SqlParameter("@FlourTortilla", b.FlourTortilla));
                        stmt.Parameters.Add(new SqlParameter("@Guacamole", b.Guacamole));
                        stmt.Parameters.Add(new SqlParameter("@HerbGarlicTortilla", b.HerbGarlicTortilla));
                        stmt.Parameters.Add(new SqlParameter("@Hummus", b.Hummus));
                        stmt.Parameters.Add(new SqlParameter("@JalapenoCheddarTortilla", b.JalapenoCheddarTortilla));
                        stmt.Parameters.Add(new SqlParameter("@Jalapenos", b.Jalapenos));
                        stmt.Parameters.Add(new SqlParameter("@Lettuce", b.Lettuce));
                        stmt.Parameters.Add(new SqlParameter("@Onion", b.Onion));
                        stmt.Parameters.Add(new SqlParameter("@OrderID", b.orderID));
                        stmt.Parameters.Add(new SqlParameter("@PintoBeans", b.PintoBeans));
                        stmt.Parameters.Add(new SqlParameter("@Price", b.Price));
                        stmt.Parameters.Add(new SqlParameter("@SalsaPico", b.SalsaPico));
                        stmt.Parameters.Add(new SqlParameter("@SalsaSpecial", b.SalsaSpecial));
                        stmt.Parameters.Add(new SqlParameter("@SalsaVerde", b.SalsaVerde));
                        stmt.Parameters.Add(new SqlParameter("@TomatoBasilTortilla", b.TomatoBasilTortilla));
                        stmt.Parameters.Add(new SqlParameter("@Tomatoes", b.Tomatoes));
                        stmt.Parameters.Add(new SqlParameter("@WheatTortilla", b.WheatTortilla));
                        stmt.Parameters.Add(new SqlParameter("@WhiteRice", b.WhiteRice));
                        #endregion

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

            return result;
        }
        public void testInvalidSubmitOrder()
        {
            try
            {
                dLog.Info("Start testInvalidSubmitOrder");
                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()));
                b.Price = bManager.calculatePrice(b);
                oManager.addBurritoToOrder(o, b);

                Assert.True(oManager.createOrder(o));

                dLog.Debug("Order ID: " + o.id);

                Assert.True(oManager.addBurritoToOrder(o, b));

                Assert.False(oManager.submitOrder(o));

                Assert.True(oManager.cancelOrder(o));

                dLog.Info("Finish testInvalidSubmitOrder");
            }
            catch (Exception e)
            {
                dLog.Error("Exception in testInvalidSubmitOrder: " + e.Message);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }
Пример #15
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;
        }
        /// <summary>
        /// This method retrieves a order.
        /// </summary>
        /// <param name="id">Unique ID of order to retrieve</param>
        /// <returns>order object</returns>
        public Order getOrder(Int32 id)
        {
            dLog.Info("Entering method getOrder | ID: " + id);
            Order o = new Order();
            ISession session = null;

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

                        o = query.List<Order>()[0];
                    }

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

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

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

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

            return result;
        }
Пример #18
0
        /// <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);
            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("order");
                    var query = new QueryDocument("id", o.id);

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

                    query.Add("isComplete", o.isComplete);
                    query.Add("isSubmitted", o.isSubmitted);
                    query.Add("orderDate", o.orderDate);
                    query.Add("totalCost", o.totalCost.ToString());

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

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

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

                        dLog.Debug("SafeModeResult: " + wr.Ok);
                        if (wr.LastErrorMessage == null && wr.Ok)
                        {
                            result = true;
                        }
                        else
                        {
                            dLog.Debug("SafeModeResult: " + wr.LastErrorMessage);
                        }
                    }

                    //now insert the burritos
                    if (result)
                    {
                        dLog.Debug("Trying to insert " + o.burritos.Count + " burritos");

                        var index = 0;
                        foreach (Burrito b in o.burritos)
                        {
                            b.orderID = o.id;

                            dLog.Debug("Set order ID " + o.id + " for burrito: " + index);
                            if (b.validate())
                            {
                                dLog.Debug("Storing burrito: " + index);
                                result = burritoSvc.storeBurrito(b);
                            }
                            index++;
                        }
                    }
                }
            }
            catch (Exception e2)
            {
                dLog.Error("Exception in storeBurrito: " + 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");
        }
Пример #20
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 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);
            }
        }
Пример #22
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;
        }
Пример #23
0
        /// <summary>
        /// This method retrieves a order.
        /// </summary>
        /// <param name="id">Unique ID of order to retrieve</param>
        /// <returns>order object</returns>
        public Order getOrder(Int32 id)
        {
            dLog.Info("Entering method getOrder | ID: " + id);
            Order o = new Order();
            SqlDataReader rs = null;
            SqlConnection conn = null;
            SqlCommand stmt = null;

            try
            {
                String sqlStr = "SELECT isComplete, orderDate, isSubmitted, totalCost, Beef, BlackBeans, BrownRice, Chicken, ChiliTortilla, Cucumber, FlourTortilla, Guacamole, ";
                sqlStr += "HerbGarlicTortilla, Hummus, JalapenoCheddarTortilla, Jalapenos, Lettuce, Onion, b.orderID, PintoBeans, Price, SalsaPico, SalsaSpecial, SalsaVerde, ";
                sqlStr += "TomatoBasilTortilla, Tomatoes, WheatTortilla, WhiteRice, b.id FROM Orders o LEFT JOIN Burrito b on o.id = b.orderID WHERE o.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())
                {
                    Int32 tID;
                    dLog.Info("Got the " + rs.FieldCount + " fields of the record ");
                    o.id = id;

                    #region Read Fields
                    if(!rs.IsDBNull(0))
                        o.isComplete = rs.GetBoolean(0);
                    if(!rs.IsDBNull(1))
                        o.orderDate = rs.GetDateTime(1);
                    if(!rs.IsDBNull(2))
                        o.isSubmitted = rs.GetBoolean(2);
                    if(!rs.IsDBNull(3))
                        o.totalCost = rs.GetDecimal(3);

                    Burrito b = new Burrito();
                    if (!rs.IsDBNull(4))
                        b.Beef = rs.GetBoolean(4);
                    if (!rs.IsDBNull(5))
                        b.BlackBeans = rs.GetBoolean(5);
                    if (!rs.IsDBNull(6))
                        b.BrownRice = rs.GetBoolean(6);
                    if (!rs.IsDBNull(7))
                        b.Chicken = rs.GetBoolean(7);
                    if (!rs.IsDBNull(8))
                        b.ChiliTortilla = rs.GetBoolean(8);
                    if (!rs.IsDBNull(9))
                        b.Cucumber = rs.GetBoolean(9);
                    if (!rs.IsDBNull(10))
                        b.FlourTortilla = rs.GetBoolean(10);
                    if (!rs.IsDBNull(11))
                        b.Guacamole = rs.GetBoolean(11);
                    if (!rs.IsDBNull(12))
                        b.HerbGarlicTortilla = rs.GetBoolean(12);
                    if (!rs.IsDBNull(13))
                        b.Hummus = rs.GetBoolean(13);
                    if (!rs.IsDBNull(14))
                        b.JalapenoCheddarTortilla = rs.GetBoolean(14);
                    if (!rs.IsDBNull(15))
                        b.Jalapenos = rs.GetBoolean(15);
                    if (!rs.IsDBNull(16))
                        b.Lettuce = rs.GetBoolean(16);
                    if (!rs.IsDBNull(17))
                        b.Onion = rs.GetBoolean(17);
                    if (!rs.IsDBNull(18))
                        b.orderID = rs.GetInt32(18);
                    if (!rs.IsDBNull(19))
                        b.PintoBeans = rs.GetBoolean(19);
                    if (!rs.IsDBNull(20))
                        b.Price = rs.GetDecimal(20);
                    if (!rs.IsDBNull(21))
                        b.SalsaPico = rs.GetBoolean(21);
                    if (!rs.IsDBNull(22))
                        b.SalsaSpecial = rs.GetBoolean(22);
                    if (!rs.IsDBNull(23))
                        b.SalsaVerde = rs.GetBoolean(23);
                    if (!rs.IsDBNull(24))
                        b.TomatoBasilTortilla = rs.GetBoolean(24);
                    if (!rs.IsDBNull(25))
                        b.Tomatoes = rs.GetBoolean(25);
                    if (!rs.IsDBNull(26))
                        b.WheatTortilla = rs.GetBoolean(26);
                    if (!rs.IsDBNull(27))
                        b.WhiteRice = rs.GetBoolean(27);
                    if (!rs.IsDBNull(28) && Int32.TryParse(rs.GetString(14), out tID))
                        b.id = tID;

                    o.burritos.Add(b);
                    #endregion
                }
            }
            catch (SqlException e1)
            {
                dLog.Error("SqlException in getOrder: " + e1.Message + "\n" + e1.StackTrace);
                o = new Order();
            }
            catch (Exception e2)
            {
                dLog.Error("Exception in getOrder: " + e2.Message + "\n" + e2.StackTrace);
                o = new Order();
            }
            finally
            {
                if (rs != null && !rs.IsClosed)
                    rs.Close();
                if (conn != null && conn.State == System.Data.ConnectionState.Open)
                    conn.Close();
            }

            return o;
        }
Пример #24
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public Decimal calculateTotal(Order o)
        {
            dLog.Debug("In calculateTotal");
            Decimal result = new Decimal(-1);

            try
            {
                result = new Decimal(0);

                // loop through all burritos on the order
                foreach (Burrito b in o.burritos)
                {
                    //check for valid burrito
                    if (b.validate())
                    {
                        // 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 calculateTotal: " + e.Message + "\n" + e.StackTrace);
                result = new Decimal(-1);
            }

            dLog.Debug("calculateTotal result: " + result);
            return result;
        }
        public void testgetOrderHistories()
        {
            try
            {
                dLog.Info("Start testgetOrderHistories");
                o = new Order(rand.Next(), new List<Burrito>(), new DateTime(), false, false, new Decimal(0));
                oManager.addBurritoToOrder(o, b);
                o.totalCost = oManager.calculateTotal(o);

                Assert.True(oManager.createOrder(o));

                Assert.NotNull(oManager.getOrderHistories());

                Assert.True(oManager.cancelOrder(o));

                dLog.Info("Finish testgetOrderHistories");
            }
            catch (Exception e)
            {
                dLog.Error("Exception in testgetOrderHistories: " + e.Message);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }