Esempio n. 1
0
        public void testLobOpenWrite4()
        {
            String str1    = "Hello, world!";
            int    offset1 = 1024 * 256 * 2 + 1024 * 2;
            String str2    = "LOB random Write";
            int    offset2 = offset1 - str2.Length * 2;

            ObjectId id  = ObjectId.GenerateNewId();
            DBLob    lob = cl.CreateLob(id);

            lob.Close();

            DBLob lob1 = cl.OpenLob(id, DBLob.SDB_LOB_WRITE);
            DBLob lob2 = cl.OpenLob(id, DBLob.SDB_LOB_WRITE);

            lob1.LockAndSeek(offset1, str1.Length);
            lob1.Write(System.Text.Encoding.Default.GetBytes(str1));

            lob2.LockAndSeek(offset2, str2.Length);
            lob2.Write(System.Text.Encoding.Default.GetBytes(str2));

            lob1.Close();
            lob2.Close();

            long lobSize = lob1.GetSize();

            DBCursor     cursor = cl.ListLobs();
            BsonDocument obj    = cursor.Next();

            Assert.IsNotNull(obj);
            ObjectId oid = obj.GetValue("Oid").AsObjectId;

            Assert.AreEqual(id, oid);
            Assert.IsNull(cursor.Next());

            lob = cl.OpenLob(id);
            Assert.AreEqual(lobSize, lob.GetSize());
            byte[] bytes = new byte[(int)lob.GetSize()];
            lob.Read(bytes);
            lob.Close();

            String s1 = System.Text.Encoding.Default.GetString(bytes, offset1, str1.Length);

            Assert.AreEqual(str1, s1);

            String s2 = System.Text.Encoding.Default.GetString(bytes, offset2, str2.Length);

            Assert.AreEqual(str2, s2);

            cl.RemoveLob(id);
            cursor = cl.ListLobs();
            Assert.IsNull(cursor.Next());
        }
Esempio n. 2
0
        public void testLobOpenWrite8()
        {
            String str  = "1234567890";
            String str2 = "abcde";
            String str3 = "12345abcde";

            ObjectId id  = ObjectId.GenerateNewId();
            DBLob    lob = cl.CreateLob(id);

            lob.Close();

            lob = cl.OpenLob(id, DBLob.SDB_LOB_WRITE);
            lob.Write(System.Text.Encoding.Default.GetBytes(str));
            lob.Close();

            lob = cl.OpenLob(id, DBLob.SDB_LOB_WRITE);
            lob.LockAndSeek(5, -1);
            lob.Write(System.Text.Encoding.Default.GetBytes(str2));
            lob.Close();

            long lobSize = lob.GetSize();

            DBCursor     cursor = cl.ListLobs();
            BsonDocument obj    = cursor.Next();

            Assert.IsNotNull(obj);
            ObjectId oid = obj.GetValue("Oid").AsObjectId;

            Assert.AreEqual(id, oid);
            Assert.IsNull(cursor.Next());

            lob = cl.OpenLob(id);
            Assert.AreEqual(lobSize, lob.GetSize());
            byte[] bytes = new byte[(int)lob.GetSize()];
            lob.Read(bytes);
            lob.Close();

            String s = System.Text.Encoding.Default.GetString(bytes);

            Assert.AreEqual(str3, s);

            cl.RemoveLob(id);
            cursor = cl.ListLobs();
            Assert.IsNull(cursor.Next());
        }