Exemplo n.º 1
0
        public async void CopyDataAsync_NullDestination_ThrowsArgumentNullException()
        {
            var source      = CreateFakePipeReader();
            var destination = CreateNullPipeWriter();

            async Task copyAction()
            {
                _ = await PipeReaderCopyDataExtensions.CopyDataAsync(source, destination, 1, CancellationToken.None);
            }

            _ = await Assert.ThrowsAsync <ArgumentNullException>(copyAction);
        }
Exemplo n.º 2
0
        public async void CopyDataAsync_CorrectArguments_CopiesData(byte[] sourceArray, long copyLimit,
                                                                    long expectedCopyCount, byte[] expectedDestinationArray)
        {
            using var sourceStream      = new MemoryStream(sourceArray, false);
            using var destinationStream = new MemoryStream();
            var source      = PipeReader.Create(sourceStream);
            var destination = PipeWriter.Create(destinationStream);

            var copyCount = await PipeReaderCopyDataExtensions.CopyDataAsync(source, destination, copyLimit, cancellationToken : CancellationToken.None);

            var destinationArray = destinationStream.ToArray();

            Assert.Equal(expectedCopyCount, copyCount);
            Assert.Equal(expectedDestinationArray, destinationArray);
        }