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_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_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."); }
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. } }