Ejemplo n.º 1
0
        public void TransportFileWithoutKnownLengthShouldBeDecodable()
        {
            string fileName = "Test";
            string mimeType = "application/zip";

            var transFile = new TransportFile(fileName, mimeType);
            var srcData   = new byte[81924]; // has to be dividable by 3 without known length
            var rand      = new Random();

            rand.NextBytes(srcData);

            using (var srcMs = new MemoryStream(srcData))
                transFile.ReadFrom(srcMs);

            transFile.OriginalLength = 0; // Reset to default state!

            byte[] destData;
            using (var destMs = new MemoryStream())
            {
                transFile.WriteTo(destMs);
                destData = destMs.ToArray();
            }

            Assert.Equal(srcData.Length, destData.Length);
            Assert.Equal(srcData, destData);
        }
Ejemplo n.º 2
0
        [InlineData(81925)] // more then one buffer - not dividable by 3
        public void EncodeDecodeLengthsMatchForDifferentLengths(int numberOfBytes)
        {
            string fileName = "Test";
            string mimeType = "application/zip";

            var transFile = new TransportFile(fileName, mimeType);
            var srcData   = new byte[numberOfBytes];

            var rand = new Random();

            rand.NextBytes(srcData);

            using (var srcMs = new MemoryStream(srcData))
                transFile.ReadFrom(srcMs);

            byte[] destData;
            using (var destMs = new MemoryStream())
            {
                transFile.WriteTo(destMs);
                destData = destMs.ToArray();
            }

            Assert.Equal(srcData.Length, destData.Length);
            Assert.Equal(srcData, destData);
        }