public void RentAndPopulateFromStream_ShouldReturnMemoryOwnerWithExpectedLength()
        {
            var stream = new MemoryStream();

            var result = SqsReceiveResponseMemoryPool.RentAndPopulateFromStream(stream, 5);

            result.Memory.Length.Should().Be(5);
        }
        public void RentAndPopulateFromStream_ShouldThrow_WhenContentLengthIsZero()
        {
            var stream = new MemoryStream();

            Action act = () => SqsReceiveResponseMemoryPool.RentAndPopulateFromStream(stream, 0);

            act.Should().Throw <ArgumentException>(because: "we should only both renting memory if there is content to store.");
        }
        public void RentAndPopulateFromStream_ShouldThrow_WhenStreamIsNotReadable()
        {
            var stream = new NonReadableStream();

            Action act = () => SqsReceiveResponseMemoryPool.RentAndPopulateFromStream(stream, 1);

            act.Should().Throw <ArgumentException>(because: "the stream must be readable");
        }
        public async Task RentAndPopulateFromStreamAsync_ShouldReturnMemoryOwnerWithExpectedLength()
        {
            var stream = new MemoryStream(new byte[10]);

            var result = await SqsReceiveResponseMemoryPool.RentAndPopulateFromStreamAsync(stream, 5);

            result.Memory.Length.Should().Be(5);
        }
        public async Task RentAndPopulateFromStreamAsync_ShouldThrow_WhenContentLengthIsZero()
        {
            var stream = new MemoryStream();

            Func <Task> func = async() => await SqsReceiveResponseMemoryPool.RentAndPopulateFromStreamAsync(stream, 0);

            await func.Should().ThrowAsync <ArgumentException>(because: "we should only both renting memory if there is content to store.");
        }
        public async Task RentAndPopulateFromStreamAsync_ShouldThrow_WhenStreamIsNotReadable()
        {
            var stream = new NonReadableStream();

            Func <Task> func = async() => await SqsReceiveResponseMemoryPool.RentAndPopulateFromStreamAsync(stream, 1);

            await func.Should().ThrowAsync <ArgumentException>(because: "the stream must be readable.");
        }
Exemplo n.º 7
0
        public void AwaitRentAndPopulateFromStream()
        {
            _stream.Position = 0;

            using (var responseMemory = SqsReceiveResponseMemoryPool.RentAndPopulateFromStream(_stream, _contentLength))
            {
                var memory = responseMemory.Memory;
            }
        }
Exemplo n.º 8
0
        private static async Task RentAndPopulateFromStreamAsync()
        {
            byte[] bytes = GetResponseBytes();

            await using var ms = new MemoryStream(bytes);

            using (var responseMemory = await SqsReceiveResponseMemoryPool.RentAndPopulateFromStreamAsync(ms, bytes.Length))
            {
                var memory = responseMemory.Memory; // We now have the bytes for the response that we can parse.
            }
        }