Exemplo n.º 1
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.º 2
0
        public void ShouldPassThrough()
        {
            // Arrange

            var input = new byte[1000];

            new Random(100500).NextBytes(input);

            var output = new byte[2000];

            var compressor = new PassThroughCompressor();

            // Act

            var size = compressor.Compress(input, 0, input.Length, output, 100, output.Length);

            // Assert

            Assert.Equal(1000, size);
            Assert.Equal(input, output.Skip(100).Take(1000));
        }