コード例 #1
0
        public async Task FlushAsync_CorrectBytesAreSaved(int shadowBufferSize, int totBytes, int writeBlockLength, bool delayedWriter)
        {
            byte[]               inputBuffer = Enumerable.Range(1, totBytes).Select(f => (byte)f).ToArray();
            byte[]               destBuffer  = new byte[totBytes];
            MemoryStream         destStream  = new MemoryStream(destBuffer);
            BufferedStreamWriter s           = new BufferedStreamWriter(destStream, GetConfig(shadowBufferSize, delayedWriter));

            for (int ix = 0; ix < totBytes; ix += writeBlockLength)
            {
                await s.WriteAsync(inputBuffer, ix, Math.Min(totBytes - ix, writeBlockLength));
            }

            await s.FlushAsync();

            Assert.AreEqual(inputBuffer, destBuffer);
        }
コード例 #2
0
        public async Task FlushAsync_StreamFlushes()
        {
            byte[] inputBuffer = Enumerable.Range(1, 10).Select(f => (byte)f).ToArray();
            var    streamMock  = new Mock <Stream>(MockBehavior.Strict);

            streamMock
            .Setup(p => p.WriteAsync(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .Returns((byte[] buffer, int offset, int count, CancellationToken token) => Task.CompletedTask);
            streamMock
            .Setup(p => p.FlushAsync(It.IsAny <CancellationToken>()))
            .Returns((CancellationToken token) => Task.CompletedTask);
            BufferedStreamWriter s = new BufferedStreamWriter(streamMock.Object, GetConfig(4));
            await s.WriteAsync(inputBuffer, 0, inputBuffer.Length, CancellationToken.None);

            await s.FlushAsync(CancellationToken.None);

            streamMock.Verify(f => f.FlushAsync(It.IsAny <CancellationToken>()), Times.Once());
        }