Repository: dotnet/runtime
File: src/libraries/System.Runtime/tests/System.IO.Tests/BufferedStream/BufferedStreamTests.cs (C#)

Code before:
            catch (OutOfMemoryException)
            {
                return;
            }

            var writableStream = new WriteOnlyStream();
            using (var bs = new BufferedStream(writableStream))
            {
                bs.Write(new ReadOnlySpan<byte>(bytes));
                Assert.Equal(InputSize, writableStream.Position);
            }
        }

        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.Is64BitProcess))]
        [OuterLoop]
        public async Task WriteAsyncFromMemory_InputSizeLargerThanHalfOfMaxInt_ShouldSuccess()
        {
            const int InputSize = int.MaxValue / 2 + 1;
            byte[] bytes;
            try
            {
                bytes = new byte[InputSize];
            }
            catch (OutOfMemoryException)
            {
                return;
            }

            var writableStream = new WriteOnlyStream();
            using (var bs = new BufferedStream(writableStream))
            {
                await bs.WriteAsync(new ReadOnlyMemory<byte>(bytes));
                Assert.Equal(InputSize, writableStream.Position);
            }
        }

        [Theory]
        [InlineData(true)]
        [InlineData(false)]
        public async Task ShouldNotFlushUnderlyingStreamIfReadOnly(bool underlyingCanSeek)
        {
            var underlying = new DelegateStream(
                canReadFunc: () => true,
                canWriteFunc: () => false,
                canSeekFunc: () => underlyingCanSeek,
                readFunc: (_, __, ___) => 123,
                writeFunc: (_, __, ___) =>
                {
                    throw new NotSupportedException();
                },
                seekFunc: (_, __) => 123L

Review comment (suggestion):
nit: we could throw `SkipTestException` to show this test as skipped rather than passing when it can't be run.

```suggestion
                throw new SkipTestException("Not enough memory");
```

Code after:
            catch (OutOfMemoryException)
            {
                return;
            }

            var writableStream = new WriteOnlyStream();
            using (var bs = new BufferedStream(writableStream))
            {
                bs.Write(new ReadOnlySpan<byte>(bytes));
                Assert.Equal(InputSize, writableStream.Position);
            }
        }

        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.Is64BitProcess))]
        [OuterLoop]
        public async Task WriteAsyncFromMemory_InputSizeLargerThanHalfOfMaxInt_ShouldSuccess()
        {
            const int InputSize = int.MaxValue / 2 + 1;
            byte[] bytes;
            try
            {
                bytes = new byte[InputSize];
            }
            catch (OutOfMemoryException)
            {
                throw new SkipTestException("Not enough memory");
            }

            var writableStream = new WriteOnlyStream();
            using (var bs = new BufferedStream(writableStream))
            {
                await bs.WriteAsync(new ReadOnlyMemory<byte>(bytes));
                Assert.Equal(InputSize, writableStream.Position);
            }
        }

        [Theory]
        [InlineData(true)]
        [InlineData(false)]
        public async Task ShouldNotFlushUnderlyingStreamIfReadOnly(bool underlyingCanSeek)
        {
            var underlying = new DelegateStream(
                canReadFunc: () => true,
                canWriteFunc: () => false,
                canSeekFunc: () => underlyingCanSeek,
                readFunc: (_, __, ___) => 123,
                writeFunc: (_, __, ___) =>
                {
                    throw new NotSupportedException();
                },
                seekFunc: (_, __) => 123L