public void TestAddChucksWithSameIndexes() { var holder = new FileChunkHolder(); holder.Add(0, new byte[] { 0x00 }); holder.Add(0, new byte[] { 0xDE, 0xAD }); }
public void TestGetSameChuckSeveralTimes() { var holder = new FileChunkHolder(); holder.Add(0, new byte[0]); holder.Get(0); holder.Get(0); }
public void TestFileChunksFromSomeByteArray() { var bytes = Encoding.UTF8.GetBytes("Hello, World!"); var holder = new FileChunkHolder(); holder.Add(0, bytes.RangeSubset(0, 5)); holder.Add(1, bytes.RangeSubset(5, 2)); holder.Add(2, bytes.RangeSubset(7, 5)); holder.Add(3, bytes.RangeSubset(12, 1)); Assert.AreEqual(4, holder.Count()); Assert.AreEqual("Hello", Encoding.UTF8.GetString(holder.Get(0))); Assert.AreEqual(", ", Encoding.UTF8.GetString(holder.Get(1))); Assert.AreEqual("World", Encoding.UTF8.GetString(holder.Get(2))); Assert.AreEqual("!", Encoding.UTF8.GetString(holder.Get(3))); Assert.AreEqual(0, holder.Count()); }
public void TestWriteSomeFileFromSeveralChunks() { var file = new FileInfo("output.txt"); File.Delete(file.Name); var chunkHolder = new FileChunkHolder(); var chunks = new List <byte[]> { Encoding.UTF8.GetBytes("Hello, World!"), Encoding.UTF8.GetBytes("Hello, Veeam!"), Encoding.UTF8.GetBytes("Availability for the Always-On Enterprise") }; chunkHolder.Add(0, chunks[0]); chunkHolder.Add(1, chunks[1]); chunkHolder.Add(2, chunks[2]); Assert.AreEqual(chunks.Count, chunkHolder.Count()); var commands = new List <ICommand>(3) { new WriteChunkCommand(0, chunkHolder, file.Name), new WriteChunkCommand(1, chunkHolder, file.Name), new WriteChunkCommand(2, chunkHolder, file.Name) }; foreach (var command in commands) { command.Execute(); } var chunkHolderBytes = new List <byte>(0); foreach (var chunk in chunks) { chunkHolderBytes.AddRange(chunk); } Assert.AreEqual(0, chunkHolder.Count()); CollectionAssert.AreEqual(chunkHolderBytes, File.ReadAllBytes(file.Name)); }
public void TestDecompressSeveralChunks() { var originalByteChunks = new List <byte[]>(3) { new List <byte>().Concat(Constants.GZipDefaultHeader).Concat(new byte[] { 0x00, 0x01, 0x02 }).ToArray(), new List <byte>().Concat(Constants.GZipDefaultHeader).Concat(new byte[] { 0x05, 0x06, 0x07 }).ToArray(), new List <byte>().Concat(Constants.GZipDefaultHeader).Concat(new byte[] { 0x0A, 0x0B, 0x0C }).ToArray() }; var compressor = new GZipCompressor(); var inputHolder = new FileChunkHolder(); var outputHolder = new FileChunkHolder(); inputHolder.Add(0, originalByteChunks[0]); inputHolder.Add(1, originalByteChunks[1]); inputHolder.Add(2, originalByteChunks[2]); Assert.AreEqual(originalByteChunks.Count, inputHolder.Count()); Assert.AreEqual(0, outputHolder.Count()); var commands = new List <ICommand>(3) { new DecompressChunkCommand(0, inputHolder, outputHolder, compressor), new DecompressChunkCommand(1, inputHolder, outputHolder, compressor), new DecompressChunkCommand(2, inputHolder, outputHolder, compressor) }; foreach (var command in commands) { command.Execute(); } Assert.AreEqual(0, inputHolder.Count()); Assert.AreEqual(originalByteChunks.Count, outputHolder.Count()); CollectionAssert.AreEqual(new byte[0], outputHolder.Get(0)); CollectionAssert.AreEqual(new byte[0], outputHolder.Get(1)); CollectionAssert.AreEqual(new byte[0], outputHolder.Get(2)); }
public void TestCompressSeveralChunks() { var originalByteChunks = new List <byte[]>(3) { Encoding.UTF8.GetBytes("High-Speed Recovery"), Encoding.UTF8.GetBytes("Verified Recoverability"), Encoding.UTF8.GetBytes("Complete Visibility") }; var compressor = new GZipCompressor(); var inputHolder = new FileChunkHolder(); var outputHolder = new FileChunkHolder(); inputHolder.Add(0, originalByteChunks[0]); inputHolder.Add(1, originalByteChunks[1]); inputHolder.Add(2, originalByteChunks[2]); Assert.AreEqual(originalByteChunks.Count, inputHolder.Count()); Assert.AreEqual(0, outputHolder.Count()); var commands = new List <ICommand>(3) { new CompressChunkCommand(0, inputHolder, outputHolder, compressor), new CompressChunkCommand(1, inputHolder, outputHolder, compressor), new CompressChunkCommand(2, inputHolder, outputHolder, compressor) }; foreach (var command in commands) { command.Execute(); } Assert.AreEqual(0, inputHolder.Count()); Assert.AreEqual(originalByteChunks.Count, outputHolder.Count()); CollectionAssert.AreEqual(compressor.Compress(originalByteChunks[0]), outputHolder.Get(0)); CollectionAssert.AreEqual(compressor.Compress(originalByteChunks[1]), outputHolder.Get(1)); CollectionAssert.AreEqual(compressor.Compress(originalByteChunks[2]), outputHolder.Get(2)); }
public void TestWriteWholeFileFromOneChunk() { var file = new FileInfo("output.txt"); File.Delete(file.Name); var chunkHolder = new FileChunkHolder(); var bytes = Encoding.UTF8.GetBytes("Hello, World!"); chunkHolder.Add(0, bytes); var command = new WriteChunkCommand(0, chunkHolder, file.Name); command.Execute(); Assert.AreEqual(0, chunkHolder.Count()); CollectionAssert.AreEqual(File.ReadAllBytes(file.Name), bytes); }
public void TestCompressOneChunk() { var originalBytes = Encoding.UTF8.GetBytes("AVAILABILITY for the Always-On Enterprise"); var compressor = new GZipCompressor(); var inputHolder = new FileChunkHolder(); var outputHolder = new FileChunkHolder(); inputHolder.Add(0, originalBytes); Assert.AreEqual(1, inputHolder.Count()); Assert.AreEqual(0, outputHolder.Count()); var command = new CompressChunkCommand(0, inputHolder, outputHolder, compressor); command.Execute(); Assert.AreEqual(0, inputHolder.Count()); Assert.AreEqual(1, outputHolder.Count()); CollectionAssert.AreEqual(compressor.Compress(originalBytes), outputHolder.Get(0)); }
public void TestDecompressOneChunk() { var originalBytes = new List <byte>() .Concat(Constants.GZipDefaultHeader) .Concat(new byte[] { 0x00, 0x01, 0x02 }).ToArray(); var compressor = new GZipCompressor(); var inputHolder = new FileChunkHolder(); var outputHolder = new FileChunkHolder(); inputHolder.Add(0, originalBytes); Assert.AreEqual(1, inputHolder.Count()); Assert.AreEqual(0, outputHolder.Count()); var command = new DecompressChunkCommand(0, inputHolder, outputHolder, compressor); command.Execute(); Assert.AreEqual(0, inputHolder.Count()); Assert.AreEqual(1, outputHolder.Count()); CollectionAssert.AreEqual(new byte[0], outputHolder.Get(0)); }