Пример #1
0
        public async Task SynchronousWritesThrowIfDisallowedByIHttpBodyControlFeature()
        {
            var allowSynchronousIO = false;
            var mockBodyControl    = new Mock <IHttpBodyControlFeature>();

            mockBodyControl.Setup(m => m.AllowSynchronousIO).Returns(() => allowSynchronousIO);
            var mockFrameControl = new Mock <IFrameControl>();

            mockFrameControl.Setup(m => m.WriteAsync(It.IsAny <ArraySegment <byte> >(), CancellationToken.None)).Returns(Task.CompletedTask);

            var stream = new FrameResponseStream(mockBodyControl.Object, mockFrameControl.Object);

            stream.StartAcceptingWrites();

            // WriteAsync doesn't throw.
            await stream.WriteAsync(new byte[1], 0, 1);

            var ioEx = Assert.Throws <InvalidOperationException>(() => stream.Write(new byte[1], 0, 1));

            Assert.Equal("Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead.", ioEx.Message);

            allowSynchronousIO = true;
            // If IHttpBodyControlFeature.AllowSynchronousIO is true, Write no longer throws.
            stream.Write(new byte[1], 0, 1);
        }
Пример #2
0
        public void PositionThrows()
        {
            var stream = new FrameResponseStream(Mock.Of <IHttpBodyControlFeature>(), new MockFrameControl());

            Assert.Throws <NotSupportedException>(() => stream.Position);
            Assert.Throws <NotSupportedException>(() => stream.Position = 0);
        }
        public void PositionThrows()
        {
            var stream = new FrameResponseStream();

            Assert.Throws <NotSupportedException>(() => stream.Position);
            Assert.Throws <NotSupportedException>(() => stream.Position = 0);
        }
Пример #4
0
        public void StopAcceptingWritesCausesWriteToThrowObjectDisposedException()
        {
            var stream = new FrameResponseStream(Mock.Of <IHttpBodyControlFeature>(), Mock.Of <IFrameControl>());

            stream.StartAcceptingWrites();
            stream.StopAcceptingWrites();
            Assert.Throws <ObjectDisposedException>(() => { stream.WriteAsync(new byte[1], 0, 1); });
        }
Пример #5
0
 public Streams(IHttpBodyControlFeature bodyControl, IFrameControl frameControl)
 {
     _request             = new FrameRequestStream(bodyControl);
     _emptyRequest        = new FrameRequestStream(bodyControl);
     _response            = new FrameResponseStream(bodyControl, frameControl);
     _upgradeableResponse = new WrappingStream(_response);
     _upgradeStream       = new FrameDuplexStream(_request, _response);
 }
        public void CanWriteReturnsTrue()
        {
            var stream = new FrameResponseStream();

            Assert.True(stream.CanWrite);
        }
        public void SetLengthThrows()
        {
            var stream = new FrameResponseStream();

            Assert.Throws <NotSupportedException>(() => stream.SetLength(0));
        }
        public void SeekThrows()
        {
            var stream = new FrameResponseStream();

            Assert.Throws <NotSupportedException>(() => stream.Seek(0, SeekOrigin.Begin));
        }
Пример #9
0
        public void CanSeekReturnsFalse()
        {
            var stream = new FrameResponseStream(new MockFrameControl());

            Assert.False(stream.CanSeek);
        }
Пример #10
0
        public void SeekThrows()
        {
            var stream = new FrameResponseStream(Mock.Of <IHttpBodyControlFeature>(), new MockFrameControl());

            Assert.Throws <NotSupportedException>(() => stream.Seek(0, SeekOrigin.Begin));
        }
Пример #11
0
 public async Task ReadAsyncThrows()
 {
     var stream = new FrameResponseStream(Mock.Of <IHttpBodyControlFeature>(), new MockFrameControl());
     await Assert.ThrowsAsync <NotSupportedException>(() => stream.ReadAsync(new byte[1], 0, 1));
 }
Пример #12
0
        public void CanSeekReturnsFalse()
        {
            var stream = new FrameResponseStream(Mock.Of <IHttpBodyControlFeature>(), new MockFrameControl());

            Assert.False(stream.CanSeek);
        }
        public void CanSeekReturnsFalse()
        {
            var stream = new FrameResponseStream();

            Assert.False(stream.CanSeek);
        }
Пример #14
0
 public Streams(IFrameControl frameControl)
 {
     RequestBody  = new FrameRequestStream();
     ResponseBody = new FrameResponseStream(frameControl);
     DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody);
 }
Пример #15
0
        public void LengthThrows()
        {
            var stream = new FrameResponseStream(new MockFrameControl());

            Assert.Throws <NotSupportedException>(() => stream.Length);
        }
Пример #16
0
        public void ReadThrows()
        {
            var stream = new FrameResponseStream(new MockFrameControl());

            Assert.Throws <NotSupportedException>(() => stream.Read(new byte[1], 0, 1));
        }
Пример #17
0
        public void CanWriteReturnsTrue()
        {
            var stream = new FrameResponseStream(new MockFrameControl());

            Assert.True(stream.CanWrite);
        }
Пример #18
0
        public void CanWriteReturnsTrue()
        {
            var stream = new FrameResponseStream(Mock.Of <IHttpBodyControlFeature>(), new MockFrameControl());

            Assert.True(stream.CanWrite);
        }
        public void ReadByteThrows()
        {
            var stream = new FrameResponseStream();

            Assert.Throws <NotSupportedException>(() => stream.ReadByte());
        }
Пример #20
0
        public void BeginReadThrows()
        {
            var stream = new FrameResponseStream(Mock.Of <IHttpBodyControlFeature>(), new MockFrameControl());

            Assert.Throws <NotSupportedException>(() => stream.BeginRead(new byte[1], 0, 1, null, null));
        }
 public async Task ReadAsyncThrows()
 {
     var stream = new FrameResponseStream();
     await Assert.ThrowsAsync <NotSupportedException>(() => stream.ReadAsync(new byte[1], 0, 1));
 }
        public void BeginReadThrows()
        {
            var stream = new FrameResponseStream();

            Assert.Throws <NotSupportedException>(() => stream.BeginRead(new byte[1], 0, 1, null, null));
        }
Пример #23
0
 public Streams()
 {
     RequestBody  = new FrameRequestStream();
     ResponseBody = new FrameResponseStream();
     DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody);
 }