Exemplo n.º 1
0
        public void ShouldGenerateWhenOneChunk()
        {
            //  Arrange

            var file = new byte[16 + 5]
            {
                /* compressedSize */ 5, 0, 0, 0, /*  source.offset */ 0, 0, 0, 0, 0, 0, 0, 0, /* source.size */ 10, 0, 0, 0,
                1, 2, 3, 4, 5,
            };
            var reader = new InmemoryReader(file);

            var generator = new DecompressionInfoGenerator(reader);

            // Act

            var chunks = new List <ChunkDecompressionInfo>();

            while (generator.TryDequeue(out var info))
            {
                chunks.Add(info);
            }

            // Assert

            Assert.Collection(chunks,
                              info =>
            {
                Assert.Equal(16L, info.source.offset);
                Assert.Equal(5, info.source.size);
                Assert.Equal(0L, info.target.offset);
                Assert.Equal(10, info.target.size);
            });
        }
Exemplo n.º 2
0
        public void ShouldDecompress()
        {
            // Arrange

            var file = new byte[16 + 10 + 16 + 2]
            {
                /* compressedSize */ 10, 0, 0, 0, /*  source.offset */ 0, 0, 0, 0, 0, 0, 0, 0, /* source.size */ 10, 0, 0, 0,
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
                /* compressedSize */ 2, 0, 0, 0, /* source.offset */ 10, 0, 0, 0, 0, 0, 0, 0, /* source.size */ 2, 0, 0, 0,
                11, 12
            };
            var reader = new InmemoryReader(file);

            var decompressor = new PassThroughDecompressor();

            var output = new byte[12];
            var writer = new InmemoryWriter(output);

            var fileDecompressor = new FileDecompressor(
                new DecompressionInfoGenerator(reader),
                reader,
                decompressor,
                writer);

            // Act

            fileDecompressor.Execute();

            // Assert

            Assert.Equal(Enumerable.Range(1, 12).Select(i => (byte)i), output);
        }
Exemplo n.º 3
0
        public void ShouldCompress()
        {
            // Arrange

            var fileService = new Mock <IFileService>();

            fileService.Setup(m => m.GetSize(It.IsAny <string>())).Returns(12);

            var file = new byte[12] {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
            };
            var reader = new InmemoryReader(file);

            var compressor = new Mocks.PassThroughCompressor();

            var output = new byte[44];
            var writer = new InmemoryWriter(output);

            var fileCompressor = new FileCompressor(
                new FileCompressorOptions {
                Size = 10
            },
                new CompressionInfoGenerator(
                    new CompressorInfoGeenratorOptions {
                Path = @"C:\file.txt", Size = 10
            },
                    fileService.Object),
                reader,
                compressor,
                writer);

            // Act

            fileCompressor.Execute();

            // Assert

            Assert.Equal(
                new byte[16 + 10 + 16 + 2]
            {
                /* compressedSize */ 10, 0, 0, 0, /*  source.offset */ 0, 0, 0, 0, 0, 0, 0, 0, /* source.size */ 10, 0, 0, 0,
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
                /* compressedSize */ 2, 0, 0, 0, /* source.offset */ 10, 0, 0, 0, 0, 0, 0, 0, /* source.size */ 2, 0, 0, 0,
                11, 12
            }, output);
        }
Exemplo n.º 4
0
        public void ShouldNotGenerateWhenEmpty()
        {
            //  Arrange

            var file   = new byte[0];
            var reader = new InmemoryReader(file);

            var generator = new DecompressionInfoGenerator(reader);

            // Act

            var chunks = new List <ChunkDecompressionInfo>();

            while (generator.TryDequeue(out var info))
            {
                chunks.Add(info);
            }

            // Assert

            Assert.Empty(chunks);
        }