Esempio n. 1
0
        public async Task CanHandleLargeBlocks()
        {
            using (var input = new TestInput())
            {
                var body = Http1MessageBody.For(HttpVersion.Http10, new HttpRequestHeaders {
                    HeaderContentLength = "8197"
                }, input.Http1Connection);
                var stream = new HttpRequestStream(Mock.Of <IHttpBodyControlFeature>());
                stream.StartAcceptingReads(body);

                // Input needs to be greater than 4032 bytes to allocate a block not backed by a slab.
                var largeInput = new string('a', 8192);

                input.Add(largeInput);
                // Add a smaller block to the end so that SocketInput attempts to return the large
                // block to the memory pool.
                input.Add("Hello");

                var ms = new MemoryStream();

                await stream.CopyToAsync(ms);

                var requestArray = ms.ToArray();
                Assert.Equal(8197, requestArray.Length);
                AssertASCII(largeInput + "Hello", new ArraySegment <byte>(requestArray, 0, requestArray.Length));

                await body.StopAsync();
            }
        }
Esempio n. 2
0
        public void NullDestinationCausesCopyToAsyncToThrowArgumentNullException()
        {
            var stream = new HttpRequestStream(Mock.Of <IHttpBodyControlFeature>());

            stream.StartAcceptingReads(null);
            Assert.Throws <ArgumentNullException>(() => { stream.CopyToAsync(null); });
        }
Esempio n. 3
0
        public void ZeroBufferSizeCausesCopyToAsyncToThrowArgumentException()
        {
            var stream = new HttpRequestStream(Mock.Of <IHttpBodyControlFeature>());

            stream.StartAcceptingReads(null);
            Assert.Throws <ArgumentException>(() => { stream.CopyToAsync(Mock.Of <Stream>(), 0); });
        }
Esempio n. 4
0
        public void StopAcceptingReadsCausesCopyToAsyncToThrowObjectDisposedException()
        {
            var stream = new HttpRequestStream(Mock.Of <IHttpBodyControlFeature>());

            stream.StartAcceptingReads(null);
            stream.StopAcceptingReads();
            Assert.Throws <ObjectDisposedException>(() => { stream.CopyToAsync(Mock.Of <Stream>()); });
        }
        public async Task AbortCausesCopyToAsyncToCancel()
        {
            var stream = new HttpRequestStream(Mock.Of <IHttpBodyControlFeature>());

            stream.StartAcceptingReads(null);
            stream.Abort();
            await Assert.ThrowsAsync <TaskCanceledException>(() => stream.CopyToAsync(Mock.Of <Stream>()));
        }
Esempio n. 6
0
        public void AbortCausesCopyToAsyncToCancel()
        {
            var stream = new HttpRequestStream(Mock.Of <IHttpBodyControlFeature>());

            stream.StartAcceptingReads(null);
            stream.Abort();
            var task = stream.CopyToAsync(Mock.Of <Stream>());

            Assert.True(task.IsCanceled);
        }
        public async Task AbortWithErrorCausesCopyToAsyncToCancel()
        {
            var stream = new HttpRequestStream(Mock.Of <IHttpBodyControlFeature>());

            stream.StartAcceptingReads(null);
            var error = new Exception();

            stream.Abort(error);
            var exception = await Assert.ThrowsAsync <Exception>(() => stream.CopyToAsync(Mock.Of <Stream>()));

            Assert.Same(error, exception);
        }
Esempio n. 8
0
        public void AbortWithErrorCausesCopyToAsyncToCancel()
        {
            var stream = new HttpRequestStream(Mock.Of <IHttpBodyControlFeature>());

            stream.StartAcceptingReads(null);
            var error = new Exception();

            stream.Abort(error);
            var task = stream.CopyToAsync(Mock.Of <Stream>());

            Assert.True(task.IsFaulted);
            Assert.Same(error, task.Exception.InnerException);
        }