Esempio 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);
        }
Esempio n. 2
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);
        }
        public async Task MemoryStream_NonZeroPosition_To_MemoryStream(bool sourceIsExposable, bool disposeSource)
        {
            byte[] input = CreateByteArray(8192);
            MemoryStream source = CreateSourceMemoryStream(sourceIsExposable, input);
            const int StartingPosition = 1024;
            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);
        }
Esempio 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);
        }
        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);
        }
        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);
        }