Пример #1
0
        public void SeekingPastEndOfColumnStreamDoesNotGrowStream()
        {
            const int Offset = 1200;

            Api.JetBeginTransaction(this.sesid);
            Api.JetPrepareUpdate(this.sesid, this.tableid, JET_prep.Insert);
            using (var stream = new ColumnStream(this.sesid, this.tableid, this.columnidLongText))
            {
                stream.Seek(Offset, SeekOrigin.Begin);
            }

            this.UpdateAndGotoBookmark();
            Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush);

            using (var stream = new ColumnStream(this.sesid, this.tableid, this.columnidLongText))
            {
                Assert.AreEqual(0, stream.Length);
            }
        }
Пример #2
0
        public void OverwriteColumnStream()
        {
            var bookmark = new byte[SystemParameters.BookmarkMost];
            int bookmarkSize;

            var data = Any.BytesOfLength(1024);
            var newData = Any.BytesOfLength(128);
            const int Offset = 10;

            using (var transaction = new Transaction(this.sesid))
            using (var update = new Update(this.sesid, this.tableid, JET_prep.Insert))
            using (var stream = new ColumnStream(this.sesid, this.tableid, this.columnidLongText))
            {
                stream.Write(data, 0, data.Length);
                stream.Position = 0;
                stream.Seek(Offset, SeekOrigin.Current);
                stream.Write(newData, 0, newData.Length);
                update.Save(bookmark, bookmark.Length, out bookmarkSize);
                transaction.Commit(CommitTransactionGrbit.LazyFlush);
            }

            Api.JetGotoBookmark(this.sesid, this.tableid, bookmark, bookmarkSize);
            using (var stream = new ColumnStream(this.sesid, this.tableid, this.columnidLongText))
            {
                Assert.AreEqual(data.Length, stream.Length);
                var retrieved = new byte[data.Length];
                var expected = new byte[data.Length];
                Array.Copy(data, 0, expected, 0, data.Length);
                Array.Copy(newData, 0, expected, Offset, newData.Length);
                Assert.AreEqual(retrieved.Length, stream.Read(retrieved, 0, retrieved.Length));
                CollectionAssert.AreEqual(expected, retrieved);
            }
        }
Пример #3
0
        public void ReadReturnsNumberOfBytesRead()
        {
            var bookmark = new byte[SystemParameters.BookmarkMost];
            int bookmarkSize;

            var data = Any.BytesOfLength(1024);

            using (var transaction = new Transaction(this.sesid))
            using (var update = new Update(this.sesid, this.tableid, JET_prep.Insert))
            using (var stream = new ColumnStream(this.sesid, this.tableid, this.columnidLongText))
            {
                stream.Write(data, 0, data.Length);
                update.Save(bookmark, bookmark.Length, out bookmarkSize);
                transaction.Commit(CommitTransactionGrbit.LazyFlush);
            }

            Api.JetGotoBookmark(this.sesid, this.tableid, bookmark, bookmarkSize);
            using (var stream = new ColumnStream(this.sesid, this.tableid, this.columnidLongText))
            {
                var retrieved = new byte[data.Length];
                stream.Seek(-1, SeekOrigin.End);
                Assert.AreEqual(1, stream.Read(retrieved, 0, retrieved.Length));
                Assert.AreEqual(data[data.Length - 1], retrieved[0]);
            }
        }
Пример #4
0
        public void ExtendingColumnStream()
        {
            var bookmark = new byte[SystemParameters.BookmarkMost];
            int bookmarkSize;

            var data = Any.BytesOfLength(4096);

            using (var transaction = new Transaction(this.sesid))
            using (var update = new Update(this.sesid, this.tableid, JET_prep.Insert))
            using (var stream = new ColumnStream(this.sesid, this.tableid, this.columnidLongText))
            {
                // Write some of the data, rewind a bit and then overwrite the
                // last few bytes and append some more data
                stream.Write(data, 0, data.Length - 10);
                stream.Seek(-10, SeekOrigin.End);
                stream.Write(data, data.Length - 20, 20);
                update.Save(bookmark, bookmark.Length, out bookmarkSize);
                transaction.Commit(CommitTransactionGrbit.LazyFlush);
            }

            Api.JetGotoBookmark(this.sesid, this.tableid, bookmark, bookmarkSize);
            using (var stream = new ColumnStream(this.sesid, this.tableid, this.columnidLongText))
            {
                Assert.AreEqual(data.Length, stream.Length);
                var retrieved = new byte[data.Length];
                Assert.AreEqual(retrieved.Length, stream.Read(retrieved, 0, retrieved.Length));
                CollectionAssert.AreEqual(data, retrieved);
            }
        }
Пример #5
0
 public void ColumnStreamThrowsExceptionWhenSeekOffsetIsTooLarge()
 {
     using (var t = new Transaction(this.sesid))
     using (var u = new Update(this.sesid, this.tableid, JET_prep.Insert))
     using (var stream = new ColumnStream(this.sesid, this.tableid, this.columnidLongText))
     {
         stream.Seek(0x800000000, SeekOrigin.Begin);
     }
 }
Пример #6
0
 public void VerifySeekFromEndThrowsExceptionOnOverflow()
 {
     using (var t = new Transaction(this.sesid))
     using (var u = new Update(this.sesid, this.tableid, JET_prep.Insert))
     using (var stream = new ColumnStream(this.sesid, this.tableid, this.columnidLongText))
     {
         stream.Write(new byte[10], 0, 10);
         try
         {
             stream.Seek(Int64.MaxValue, SeekOrigin.End);
             Assert.Fail("Expected OverflowException");
         }
         catch (OverflowException)
         {
             // expected
         }
     }
 }
Пример #7
0
 public void ColumnStreamThrowsExceptionWhenSeekOriginIsInvalid()
 {
     using (var t = new Transaction(this.sesid))
     using (var u = new Update(this.sesid, this.tableid, JET_prep.Insert))
     using (var stream = new ColumnStream(this.sesid, this.tableid, this.columnidLongText))
     {
         stream.Seek(0x800000000, (SeekOrigin)0x1234);
     }
 }
Пример #8
0
        public void WritePastMaxSizeThrowsException()
        {
            var data = new byte[256];

            using (var transaction = new Transaction(this.sesid))
            using (var update = new Update(this.sesid, this.tableid, JET_prep.Insert))
            using (var stream = new ColumnStream(this.sesid, this.tableid, this.columnidLongText))
            {
                stream.Seek(Int32.MaxValue - 10, SeekOrigin.Begin);
                try
                {
                    stream.Write(data, 0, data.Length);
                    Assert.Fail("Expected OverflowException");
                }
                catch (OverflowException)
                {
                    // expected
                }
            }
        }