public async Task WriteAsync_WithPayload() { var(encoder, reader) = GetEncoder(); var frame = FrameProvider.GetFrame(4); await encoder.EncodeAsync(frame); var result = await reader.ReadAsync(); Assert.Equal(FrameProvider.HeaderSize + FrameProvider.FrameSize, result.Buffer.Length); }
public async Task ShouldDecodeOneFrame() { var(decoder, writer) = GetDecoder(); await FrameProvider.WriteFrame(writer, FrameProvider.GetFrame(4)); await foreach (var frame in decoder.DecodeAsync()) { Assert.Equal(4, frame.MessageId); Assert.Equal(FrameProvider.FrameSize, frame.Payload.Memory.Length); break; } }
public async Task ShouldDecode1024Frame() { var(decoder, writer) = GetDecoder(); var enumerator = decoder.DecodeAsync().GetAsyncEnumerator(); for (var i = 0; i < 1024; i++) { await FrameProvider.WriteFrame(writer, FrameProvider.GetFrame(i)); await enumerator.MoveNextAsync(); var frame = enumerator.Current; Assert.Equal(i, frame.MessageId); Assert.Equal(FrameProvider.FrameSize, frame.Payload.Memory.Length); } }
//[InlineData(8192)] public async Task DecodeAsync_ReadFrames(int n) { var(decoder, reader, writer) = GetDecoder(); decoder.Reset(reader); var enumerator = decoder.DecodeAsync().GetAsyncEnumerator(); for (var i = 0; i < n; i++) { await writer.WriteAsync(FrameProvider.GetFrameMemory(4, FrameProvider.FrameSize)); var moveNext = await enumerator.MoveNextAsync(); moveNext.Should().BeTrue(); var(frame, payload) = enumerator.Current; frame.MessageId.Should().Be(4); payload.Length.Should().Be(FrameProvider.FrameSize); } decoder.FramesRead.Should().Be(n); }