public void WriteThrowsExceptionWhenBufferOffsetIsNegative() { 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)) { var buffer = new byte[10]; stream.Write(buffer, -1, 1); } }
public void WriteThrowsExceptionWhenNumberOfBytesIsTooLarge() { 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)) { var buffer = new byte[10]; stream.Write(buffer, 1, buffer.Length); } }
public void WriteAtNonZeroOffset() { var bookmark = new byte[SystemParameters.BookmarkMost]; int bookmarkSize; var data = Any.BytesOfLength(1024); int offset = data.Length / 2; 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, offset, data.Length - offset); 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 - offset]; stream.Read(retrieved, 0, retrieved.Length); for (int i = 0; i < retrieved.Length; ++i) { Assert.AreEqual(retrieved[i], data[i + offset]); } } }
public void WriteThrowsExceptionWhenBufferIsNull() { 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(null, 0, 0); } }
public void SetColumnStreamToZeroLength() { var bookmark = new byte[SystemParameters.BookmarkMost]; int bookmarkSize; 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)) { byte[] data = Any.Bytes; stream.Write(data, 0, data.Length); stream.SetLength(0); Assert.AreEqual(0, stream.Length); update.Save(bookmark, bookmark.Length, out bookmarkSize); transaction.Commit(CommitTransactionGrbit.LazyFlush); } Api.JetGotoBookmark(this.sesid, this.tableid, bookmark, bookmarkSize); CollectionAssert.AreEqual(new byte[0], Api.RetrieveColumn(this.sesid, this.tableid, this.columnidLongText)); }
public void ShrinkColumnStream() { var bookmark = new byte[SystemParameters.BookmarkMost]; int bookmarkSize; const int Length = 1345; var data = Any.BytesOfLength(Length); 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.Write(data, 0, data.Length); Assert.AreEqual(Length * 2, stream.Length); stream.SetLength(Length); Assert.AreEqual(Length, stream.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(Length, stream.Length); var buffer = new byte[Length]; stream.Read(buffer, 0, buffer.Length); CollectionAssert.AreEqual(data, buffer); } }
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]); } }
public void SetColumnStreamPosition() { var bookmark = new byte[SystemParameters.BookmarkMost]; int bookmarkSize; 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(Any.BytesOfLength(1024), 0, 1024); 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)) { stream.Position = 10; Assert.AreEqual(10, stream.Position); } }
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); } }
public void GrowColumnStreamByWritingPastEnd() { var bookmark = new byte[SystemParameters.BookmarkMost]; int bookmarkSize; const int Length = 1345; const int Position = 1500; var data = Any.BytesOfLength(Length); 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.Position = Position; 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)) { Assert.AreEqual(Length + Position, stream.Length); var expected = new byte[Length + Position]; var actual = new byte[Length + Position]; Array.Copy(data, 0, expected, Position, Length); Assert.AreEqual(Length + Position, stream.Read(actual, 0, actual.Length)); CollectionAssert.AreEqual(expected, actual); } }
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); } }
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 } } }
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 } } }