public void Resuming_Takes_Offset_Of_Previously_Written_Blocks_Into_Account() { token.MaxBlockSize = 3000; token.NextBlockOffset = 15000; stream = new BufferedBlockOutputStream(token, 2000, WriteBlock); stream.Write(source, 0, 100); stream.Flush(); Assert.AreEqual(100, stream.WrittenBytes); Assert.AreEqual(1, receivedBlocks.Count); //check the offset of the block Assert.AreEqual(15000, receivedBlocks[0].Offset); //flush another one stream.Write(source, 0, 200); stream.Flush(); Assert.AreEqual(300, stream.WrittenBytes); Assert.AreEqual(2, receivedBlocks.Count); //check the offset of the block Assert.AreEqual(15100, receivedBlocks[1].Offset); }
public void Last_Transmitted_Block_Number_Should_Match_Token_After_Flushing() { token.MaxBlockSize = 3000; stream = new BufferedBlockOutputStream(token, 2000, WriteBlock); Assert.IsNull(stream.LastTransmittedBlockNumber); stream.Write(source, 0, 100); stream.Flush(); Assert.AreEqual(1, receivedBlocks.Count); Assert.AreEqual(receivedBlocks[0].BlockNumber, stream.LastTransmittedBlockNumber); Assert.AreEqual(token.TransmittedBlockCount, stream.LastTransmittedBlockNumber); }
public void Writing_All_Data_Should_Create_Exact_Copy() { stream = new BufferedBlockOutputStream(token, 2000, WriteBlock); int count = source.Length/20; for(int i=0; i<20; i++) { if(i%2 == 0) { byte[] copy = new byte[count]; Array.Copy(source, i*count, copy, 0, count); stream.Write(copy, 0, copy.Length); } else { stream.Write(source, i*count, count); } } stream.Flush(); VerifyTransmission(); }
public void Flushing_Buffer_Should_Create_Multiple_Blocks_If_Buffer_Is_Bigger_Than_Maximum_BlockSize() { //set auto-stream so it doesn't auto-flush stream = new BufferedBlockOutputStream(token, 10000, WriteBlock); token.MaxBlockSize = 3000; //write 7000 bytes - no flush stream.Write(source, 0, 7000); Assert.IsEmpty(receivedBlocks); Assert.AreEqual(0, stream.WrittenBytes); Assert.AreEqual(7000, stream.InternalBufferSize); stream.Flush(); Assert.AreEqual(3, receivedBlocks.Count); Assert.AreEqual(3000, receivedBlocks[0].BlockLength); Assert.AreEqual(3000, receivedBlocks[1].BlockLength); Assert.AreEqual(1000, receivedBlocks[2].BlockLength); }
public void Flushing_Stream_Should_Submit_All_Buffered_Data() { stream = new BufferedBlockOutputStream(token, 50000, WriteBlock); token.MaxBlockSize = 3000; stream.Write(source, 0, 7000); Assert.AreEqual(0, receivedBlocks.Count); stream.Flush(); Assert.AreEqual(3, receivedBlocks.Count); Assert.AreEqual(3000, receivedBlocks[0].BlockLength); Assert.AreEqual(3000, receivedBlocks[1].BlockLength); Assert.AreEqual(1000, receivedBlocks[2].BlockLength); Assert.AreEqual(0, stream.InternalBufferSize); }