public void ShouldReadAndWriteLBABackend() { var underlyingFile = TemporaryFilesManager.Instance.GetTemporaryFile(); try { var blocksCount = random.Next(MaxBlocksCount + 1); using (var lbaBackend = new LBABackend(underlyingFile, blocksCount, BlockSize)) { var testBlocksCount = Math.Min(DesiredTestBlocksCount, blocksCount); var blockPositions = Enumerable.Range(0, blocksCount).OrderBy(x => random.Next()).Take(testBlocksCount).ToArray(); var blockContent = new byte[testBlocksCount][]; for (var i = 0; i < testBlocksCount; i++) { blockContent[i] = new byte[BlockSize]; random.NextBytes(blockContent[i]); lbaBackend.Write(blockPositions[i], blockContent[i], 1); } for (var i = 0; i < testBlocksCount; i++) { CollectionAssert.AreEqual(blockContent[i], lbaBackend.Read(blockPositions[i], 1)); } } } finally { File.Delete(underlyingFile); } }
public MassStorage(string underlyingFile, int?numberOfBlocks = null, int blockSize = 512, bool persistent = true) { lbaBackend = new LBABackend(underlyingFile, numberOfBlocks, blockSize, persistent); Init(); }
public MassStorage(int numberOfBlocks, int blockSize = 512) { lbaBackend = new LBABackend(numberOfBlocks, blockSize); Init(); }