Beispiel #1
0
        public async Task DrainBufferAsync_CopiesContentFromMemoryStream()
        {
            // Arrange
            var input = new byte[] { 1, 2, 3, 4, 5 };

            using var bufferingStream = new FileBufferingWriteStream(tempFileDirectoryAccessor: () => TempDirectory);
            bufferingStream.Write(input, 0, input.Length);
            var memoryStream = new MemoryStream();

            // Act
            await bufferingStream.DrainBufferAsync(memoryStream, default);

            // Assert
            Assert.Equal(input, memoryStream.ToArray());
        }
Beispiel #2
0
        public async Task DrainBufferAsync_WithContentInDisk_CopiesContentFromMemoryStream()
        {
            // Arrange
            var input = Enumerable.Repeat((byte)0xca, 30).ToArray();

            using var bufferingStream = new FileBufferingWriteStream(memoryThreshold: 21, tempFileDirectoryAccessor: () => TempDirectory);
            bufferingStream.Write(input, 0, input.Length);
            var memoryStream = new MemoryStream();

            // Act
            await bufferingStream.DrainBufferAsync(memoryStream, default);

            // Assert
            Assert.Equal(input, memoryStream.ToArray());
        }
        public async Task DrainBufferAsync_IncludesContentPossiblyBufferedByFileStream()
        {
            // We want to ensure that the FileStream (which has a 1-byte buffer) flushes prior to the other read stream reading input.
            // Arrange
            var input = new byte[] { 3, };

            using var bufferingStream = new FileBufferingWriteStream(0, tempFileDirectoryAccessor: () => TempDirectory);
            bufferingStream.Write(input, 0, input.Length);
            var memoryStream = new MemoryStream();

            // Act
            await bufferingStream.DrainBufferAsync(memoryStream, default);

            // Assert
            Assert.Equal(input, memoryStream.ToArray());
            Assert.Equal(0, bufferingStream.Length);
        }