Ejemplo n.º 1
0
        public async Task NonMemoryStream_To_LimitMemoryStream_EqualCapacity(bool sourceIsExposable, bool disposeSource)
        {
            byte[] input       = CreateByteArray(8192);
            var    source      = new WrapperStream(CreateSourceMemoryStream(sourceIsExposable, input));
            var    destination = new HttpContent.LimitMemoryStream(int.MaxValue, input.Length);

            await StreamToStreamCopy.CopyAsync(source, destination, 4096, disposeSource);

            Assert.NotEqual(disposeSource, source.CanRead);
            if (!disposeSource)
            {
                Assert.Equal(input.Length, source.Position);
            }

            Assert.Equal(input, destination.ToArray());
            Assert.Equal(input.Length, destination.Position);
            Assert.Equal(input.Length, destination.Length);
        }
Ejemplo n.º 2
0
        public async Task NonSeekableMemoryStream_To_MemoryStream(bool sourceIsExposable, bool disposeSource)
        {
            byte[] input       = CreateByteArray(8192);
            var    source      = new NonSeekableMemoryStream(input, sourceIsExposable);
            var    destination = new MemoryStream();

            await StreamToStreamCopy.CopyAsync(source, destination, 4096, disposeSource);

            Assert.NotEqual(disposeSource, source.CanRead);
            if (!disposeSource)
            {
                Assert.Equal(input.Length, source.Position);
            }

            Assert.Equal(input, destination.ToArray());
            Assert.Equal(input.Length, destination.Position);
            Assert.Equal(input.Length, destination.Length);
        }
Ejemplo n.º 3
0
        public async Task MemoryStream_To_LimitMemoryStream_BiggerLength(bool sourceIsExposable, bool disposeSource)
        {
            byte[]       input       = CreateByteArray(8192);
            MemoryStream source      = CreateSourceMemoryStream(sourceIsExposable, input);
            var          destination = new HttpContent.LimitMemoryStream(int.MaxValue, 0);

            destination.SetLength(input.Length * 2);

            await StreamToStreamCopy.CopyAsync(source, destination, 4096, disposeSource);

            Assert.NotEqual(disposeSource, source.CanRead);
            if (!disposeSource)
            {
                Assert.Equal(input.Length, source.Position);
            }

            Assert.Equal(input.Concat(new byte[input.Length]), destination.ToArray());
            Assert.Equal(input.Length, destination.Position);
            Assert.Equal(input.Length * 2, destination.Length);
        }
Ejemplo n.º 4
0
        public async Task MemoryStream_PositionAtEnd_To_MemoryStream(bool sourceIsExposable, bool disposeSource)
        {
            byte[]       input            = CreateByteArray(8192);
            MemoryStream source           = CreateSourceMemoryStream(sourceIsExposable, input);
            int          StartingPosition = input.Length;

            source.Position = StartingPosition;

            var destination = new HttpContent.LimitMemoryStream(int.MaxValue, 0);

            await StreamToStreamCopy.CopyAsync(source, destination, 4096, disposeSource);

            Assert.NotEqual(disposeSource, source.CanRead);
            if (!disposeSource)
            {
                Assert.Equal(input.Length, source.Position);
            }

            Assert.Equal(input.Skip(StartingPosition), destination.ToArray());
            Assert.Equal(input.Length - StartingPosition, destination.Position);
            Assert.Equal(input.Length - StartingPosition, destination.Length);
        }