Exemple #1
0
        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);
            }
        }
Exemple #2
0
 public MassStorage(string underlyingFile, int?numberOfBlocks = null, int blockSize = 512, bool persistent = true)
 {
     lbaBackend = new LBABackend(underlyingFile, numberOfBlocks, blockSize, persistent);
     Init();
 }
Exemple #3
0
 public MassStorage(int numberOfBlocks, int blockSize = 512)
 {
     lbaBackend = new LBABackend(numberOfBlocks, blockSize);
     Init();
 }