Exemplo n.º 1
0
        public static async Task StreamDisposed_ExpectedObjectDisposedExceptionAsync(Func <HttpResponseStreamWriter, Task> function)
        {
            var httpResponseStreamWriter = new HttpResponseStreamWriter(new MemoryStream(), Encoding.UTF8, 10, ArrayPool <byte> .Shared, ArrayPool <char> .Shared);

            httpResponseStreamWriter.Dispose();

            await Assert.ThrowsAsync <ObjectDisposedException>(() =>
            {
                return(function(httpResponseStreamWriter));
            });
        }
Exemplo n.º 2
0
        public static void StreamDisposed_ExpectedObjectDisposedException(Action <HttpResponseStreamWriter> action)
        {
            var httpResponseStreamWriter = new HttpResponseStreamWriter(new MemoryStream(), Encoding.UTF8, 10, ArrayPool <byte> .Shared, ArrayPool <char> .Shared);

            httpResponseStreamWriter.Dispose();

            Assert.Throws <ObjectDisposedException>(() =>
            {
                action(httpResponseStreamWriter);
            });
        }
Exemplo n.º 3
0
        public async Task DoesNotDispose_UnderlyingStream_OnDisposingWriter()
        {
            // Arrange
            var stream = new TestMemoryStream();
            var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);

            // Act
            await writer.WriteAsync("Hello world");

            writer.Dispose();

            // Assert
            Assert.Equal(0, stream.DisposeCallCount);
        }
Exemplo n.º 4
0
        public async Task FlushesBuffer_OnDispose(int byteLength)
        {
            // Arrange
            var stream = new TestMemoryStream();
            var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
            await writer.WriteAsync(new string('a', byteLength));

            // Act
            writer.Dispose();

            // Assert
            Assert.Equal(0, stream.FlushCallCount);
            Assert.Equal(0, stream.FlushAsyncCallCount);
            Assert.Equal(byteLength, stream.Length);
        }
Exemplo n.º 5
0
        public async Task FlushWriteThrows_DontFlushInDispose(int byteLength)
        {
            // Arrange
            var stream = new TestMemoryStream()
            {
                ThrowOnWrite = true
            };
            var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);

            await writer.WriteAsync(new string('a', byteLength));

            await Assert.ThrowsAsync <IOException>(() => writer.FlushAsync());

            // Act
            writer.Dispose();

            // Assert
            Assert.Equal(1, stream.WriteAsyncCallCount);
            Assert.Equal(0, stream.WriteCallCount);
            Assert.Equal(0, stream.FlushCallCount);
            Assert.Equal(0, stream.FlushAsyncCallCount);
            Assert.Equal(0, stream.Length);
        }