示例#1
0
        public void Transaction_Begin_Rollback_Insert_Test()
        {
            // create cs, cl
            string csName = "testfoo";
            string cName  = "testbar";

            if (sdb.IsCollectionSpaceExist(csName))
            {
                sdb.DropCollectionSpace(csName);
            }
            sdb.CreateCollectionSpace(csName);
            CollectionSpace cs = sdb.GetCollecitonSpace(csName);
            DBCollection    cl = cs.CreateCollection(cName);

            // transction begin
            sdb.TransactionBegin();
            // insert record
            BsonDocument insertor1 = new BsonDocument();

            insertor1.Add("name", "tom");
            insertor1.Add("age", 25);
            insertor1.Add("addr", "guangzhou");
            BsonDocument insertor2 = new BsonDocument();

            insertor2.Add("name", "sam");
            insertor2.Add("age", 27);
            insertor2.Add("addr", "shanghai");
            cl.Insert(insertor1);
            cl.Insert(insertor2);
            // rollback
            sdb.TransactionRollback();
            // check up
            DBCursor cursor = cl.Query();

            Assert.IsNotNull(cursor);
            int count = 0;

            while (cursor.Next() != null)
            {
                ++count;
                BsonDocument bson = cursor.Current();
                Assert.IsNotNull(bson);
            }
            Assert.IsTrue(count == 0);
        }