public void MakeSureTheBlockChecksArgumentsBeforeWritingAnything() { var virtualDisk = VirtualDiskTestFactory.ConstructDefaultTestDisk(); DiskBlock block = new DiskBlock(virtualDisk, 10, 0, 0); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentNullException>( delegate { block.WriteBytes(null, 10, 11); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentException>( delegate { block.WriteBytes(new byte[2], 10, 11); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentOutOfRangeException>( delegate { block.WriteBytes(new byte[2], -10, 11); }); ExceptionAssert.MakeSureExceptionIsRaisedBy <ArgumentOutOfRangeException>( delegate { block.WriteBytes(new byte[2], 10, -1); }); }
public void MakeSureThePositionChangesAsYouAreWritingToTheBlock() { var virtualDisk = VirtualDiskTestFactory.ConstructDefaultTestDisk(); DiskBlock block = new DiskBlock(virtualDisk, 10, 0, 0); Assert.AreEqual(0, block.Position); block.WriteBytes(new byte[15], 0, 15); Assert.AreEqual(15, block.Position); // после последнего записанного байта. block.WriteBytes(new byte[15], 9, 6); Assert.AreEqual(21, block.Position); // после последнего записанного байта. }
public void TryWriteReadCycleForABuffer() { var virtualDisk = VirtualDiskTestFactory.ConstructDefaultTestDisk(); DiskBlock block = new DiskBlock(virtualDisk, 10, 0, 0); for (int i = 0; i < 2048 / 4; i++) { byte[] fourByteBlock = new byte[4]; MemoryStream writerStream = new MemoryStream(fourByteBlock); BinaryWriter writer = new BinaryWriter(writerStream); writer.Write(i); block.WriteBytes(fourByteBlock, 0, fourByteBlock.Length); } byte[] allBytes = block.ReadAll(); MemoryStream readerStream = new MemoryStream(allBytes); BinaryReader reader = new BinaryReader(readerStream); for (int i = 0; i < 2048 / 4; i++) { Assert.AreEqual(i, reader.ReadInt32()); } Assert.IsFalse(block.CanAcceptBytesAtCurrentPosition); }