Пример #1
0
        public async Task StreamsThrowAfterAbort()
        {
            var streams = new Streams(Mock.Of <IHttpBodyControlFeature>(), Mock.Of <IHttpResponseControl>());

            var(request, response) = streams.Start(new MockMessageBody());

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

            streams.Abort(ex);

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

            Assert.Same(ex,
                        await Assert.ThrowsAsync <Exception>(() => request.ReadAsync(new byte[1], 0, 1)));
        }
Пример #2
0
        public async Task StreamsThrowOnUpgradeAfterAbort()
        {
            var streams = new Streams(Mock.Of <IHttpBodyControlFeature>(), Mock.Of <IHttpResponseControl>());

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

            streams.Abort(ex);

            var upgrade = streams.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)));

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