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

Code before:
            {
                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
            );

            var wrapper = new CallTrackingStream(underlying);

            var buffered = new BufferedStream(wrapper);
            buffered.ReadByte();


Review comment (suggestion):
note: the `WriteAsync` overload that accepts an array calls the `WriteAsync` overload that takes `ROM`, so there is no need to test it. No changes required in that regard 👍 

https://github.com/dotnet/runtime/blob/15663b5a44d507e0c120f88b6e2e96f977ceac90/src/libraries/System.Private.CoreLib/src/System/IO/BufferedStream.cs#L997-L1001

Code after:
            {
                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
            );

            var wrapper = new CallTrackingStream(underlying);

            var buffered = new BufferedStream(wrapper);
            buffered.ReadByte();