Пример #1
0
        public void UnderlyingStreamsDisposed()
        {
            var stream1      = new ThrowOnDisposeStream();
            var stream2      = new ThrowOnDisposeStream();
            var mergedStream = stream1.Concat(stream2);

            Assert.Throws <Exception>(() => mergedStream.Dispose());
        }
Пример #2
0
        public async Task DispoingTheRequestBodyDoesNotDisposeClientStreams()
        {
            var builder = new WebHostBuilder().Configure(app =>
            {
                app.Run(async context =>
                {
                    using (var sr = new StreamReader(context.Request.Body))
                    {
                        await context.Response.WriteAsync(await sr.ReadToEndAsync());
                    }
                });
            });
            var server = new TestServer(builder);

            var stream = new ThrowOnDisposeStream();

            stream.Write(Encoding.ASCII.GetBytes("Hello World"));
            var response = await server.CreateClient().PostAsync("/", new StreamContent(stream));

            Assert.True(response.IsSuccessStatusCode);
            Assert.Equal("Hello World", await response.Content.ReadAsStringAsync());
        }
Пример #3
0
        public void UnderlyingStreamsAreNotDisposedIfFlagSet()
        {
            var mergedStream = new ThrowOnDisposeStream().Concat(false, new ThrowOnDisposeStream());

            mergedStream.Dispose();
        }