コード例 #1
0
        public void testBurritoSvc()
        {
            try {
                //week 3
                //IBurritoSvc ics = factory.getBurritoSvc();

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

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

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

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

                dLog.Debug("Going to delete burrito");
                // Finally, let's cleanup the file that was created
                Assert.True(ics.deleteBurrito(b.id));
            }
            catch (Exception e) {
                Console.WriteLine("Exception in testBurritoSvc: " + e.Message + "\n" + e.StackTrace);
                Assert.Fail(e.Message + "\n" + e.StackTrace);
            }
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="b"></param>
        /// <returns></returns>
        public Boolean createBurrito(Burrito b)
        {
            dLog.Debug("In createBurrito");
            Boolean result = false;

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

            dLog.Debug("createBurrito result: " + result);
            return(result);
        }
コード例 #3
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);
        }