示例#1
0
        public async Task BodyControlThrowOnUpgradeAfterAbort()
        {
            var bodyControl = new BodyControl(Mock.Of <IHttpBodyControlFeature>(), Mock.Of <IHttpResponseControl>());

            var(request, response, requestPipe, responsePipe) = bodyControl.Start(new MockMessageBody(upgradeable: true));
            var ex = new Exception("My error");

            bodyControl.Abort(ex);

            var upgrade = bodyControl.Upgrade();

            var writeEx = await Assert.ThrowsAsync <InvalidOperationException>(() => response.WriteAsync(new byte[1], 0, 1));

            Assert.Equal(CoreStrings.ResponseStreamWasUpgraded, writeEx.Message);

            Assert.Same(ex,
                        await Assert.ThrowsAsync <Exception>(() => request.ReadAsync(new byte[1], 0, 1)));

            Assert.Same(ex,
                        await Assert.ThrowsAsync <Exception>(() => upgrade.ReadAsync(new byte[1], 0, 1)));
            Assert.Same(ex,
                        await Assert.ThrowsAsync <Exception>(async() => await requestPipe.ReadAsync()));

            await upgrade.WriteAsync(new byte[1], 0, 1);
        }
示例#2
0
        public async Task BodyControlThrowAfterAbort()
        {
            var bodyControl = new BodyControl(Mock.Of <IHttpBodyControlFeature>(), Mock.Of <IHttpResponseControl>());

            var(request, response, requestPipe, responsePipe) = bodyControl.Start(new MockMessageBody());

            var ex = new Exception("My error");

            bodyControl.Abort(ex);

            await response.WriteAsync(new byte[1], 0, 1);

            Assert.Same(ex,
                        await Assert.ThrowsAsync <Exception>(() => request.ReadAsync(new byte[1], 0, 1)));
            Assert.Same(ex,
                        await Assert.ThrowsAsync <Exception>(async() => await requestPipe.ReadAsync()));
        }
示例#3
0
    public async Task RequestPipeMethodsThrowAfterAbort()
    {
        var bodyControl = new BodyControl(Mock.Of <IHttpBodyControlFeature>(), Mock.Of <IHttpResponseControl>());

        var(_, response, requestPipe, responsePipe) = bodyControl.Start(new MockMessageBody(upgradeable: true));
        var ex = new Exception("My error");

        bodyControl.Abort(ex);

        await response.WriteAsync(new byte[1], 0, 1);

        Assert.Same(ex,
                    Assert.Throws <Exception>(() => requestPipe.AdvanceTo(new SequencePosition())));
        Assert.Same(ex,
                    Assert.Throws <Exception>(() => requestPipe.AdvanceTo(new SequencePosition(), new SequencePosition())));
        Assert.Same(ex,
                    Assert.Throws <Exception>(() => requestPipe.CancelPendingRead()));
        Assert.Same(ex,
                    Assert.Throws <Exception>(() => requestPipe.TryRead(out var res)));
        Assert.Same(ex,
                    Assert.Throws <Exception>(() => requestPipe.Complete()));
    }